Skip to content

Commit

Permalink
Added file option for running from IDE, see #595
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jul 27, 2017
1 parent 9aa9fab commit 96a9b32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion js/grunt/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
};
15 changes: 11 additions & 4 deletions js/grunt/sortRequireStatements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) {

Expand Down Expand Up @@ -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 );
}
};

0 comments on commit 96a9b32

Please sign in to comment.