run jsBeautifier on single file
nsisodiya opened this issue · comments
I want that whenever my js file got changes I want to run beautifier on that file. I do not want to run on all js file.
I am using "watch" livereload for this purpose. what should I do ??
grunt.registerTask('singleJSBeautifier', "Add git revision number", function(filePath) {
//Code for running jsBeautifier on single file.????
});
In watch task you can specify jsbeautifier task to run, so on any file change it will run jsbeautifier for all file. Jsbeautifier will only format files which needs formatting which is similar to formatting modified file.
I do not see any need of specifying single file as jsbeautifier get completed in very small time.
Here is a sample code
watch: {
options: {
livereload: 35730
},
js: {
files: ['**/*.js'],
tasks: ['jsbeautifier']
}
}
Looks like I misread what you already post and gave you the same solution what you are already doing. Let me know if you are still looking for this feature. I may implement this as I get some timeframe available. A PR would be nice though. ;)
it will be nice if you implement it..
@nsisodiya why not just look up the docs for js-beautify? It's quite simple to beautify a single file.
I think this will fulfill your need, https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed
Anyway, I have added option to grunt-jsbeatifier itself, here https://github.com/vkadam/grunt-jsbeautifier#run-single-file (v 0.2.12)
So you can use either way for beautifying updated files only.
Closing issue now.