diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js index e96ea582b..e867a0a6a 100644 --- a/js/grunt/Gruntfile.js +++ b/js/grunt/Gruntfile.js @@ -406,7 +406,8 @@ module.exports = function( grunt ) { grunt.registerTask( 'sort-require-statements', 'Sort the require statements for all *.js files in the js/ directory. ' + 'This assumes the code is formatted with IDEA code style and that ' + 'require statements take one line each (not split across lines). The ' + - 'files are overwritten.', function() { + 'files are overwritten.\n' + + '--file (optional) absolute path of a single file to sort¬', function() { sortRequireStatements( grunt, buildConfig ); } ); }; \ No newline at end of file diff --git a/js/grunt/sortRequireStatements.js b/js/grunt/sortRequireStatements.js index 9fd4c09e8..b77cad12e 100644 --- a/js/grunt/sortRequireStatements.js +++ b/js/grunt/sortRequireStatements.js @@ -20,9 +20,7 @@ module.exports = function( grunt ) { var sourceRoot = process.cwd() + '/js'; - // Count the number of start and end dates we need - grunt.file.recurse( sourceRoot, function( abspath ) { - + var sortRequireStatementsForFile = function( abspath ) { // only address js files if ( abspath.indexOf( '.js' ) ) { @@ -67,5 +65,14 @@ module.exports = function( grunt ) { grunt.file.write( abspath, result.join( '\n' ) ); console.log( 'sorted ' + count + ' require statements in ' + abspath ); } - } ); + }; + + // option to sort a single file + var file = grunt.option( 'file' ); + if ( file ) { + sortRequireStatementsForFile( file ); + } + else { + grunt.file.recurse( sourceRoot, sortRequireStatementsForFile ); + } }; \ No newline at end of file