Skip to content

Commit

Permalink
Better support for command line arguments, see #1459
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Sep 12, 2024
1 parent 6b1e5e5 commit ac371f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/grunt/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Minify-specific options:
--minify.stripAssertions=false - During uglification, it will strip assertions.
--minify.stripLogging=false - During uglification, it will not strip logging statements.
`,
wrapExecSync( `node ../chipper/js/grunt/tasks/build.js --repo ${repo}` )
wrapExecSync( `node ../chipper/js/grunt/tasks/build.js --repo ${repo} ${process.argv.slice( 2 ).join( ' ' )}` )
);

grunt.registerTask( 'generate-used-strings-file',
Expand Down
19 changes: 19 additions & 0 deletions js/grunt/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ const assert = require( 'assert' );
const Transpiler = require( '../../common/Transpiler' );
const getBrands = require( './getBrands' );

// Like minimist, process into an object literal which can be consumed by grunt.option.init
function parseArgs( argv ) {
const args = {};
argv.forEach( ( arg, index ) => {
if ( arg.startsWith( '--' ) ) {
const key = arg.slice( 2 );
const value = argv[ index + 1 ] && !argv[ index + 1 ].startsWith( '--' ) ? argv[ index + 1 ] : true;
args[ key ] = value;
}
} );
return args;
}

// Parse argv
const parsedArgs = parseArgs( process.argv.slice( 2 ) );

// Initialize Grunt options with parsed arguments
grunt.option.init( parsedArgs );

const repo = getRequiredArg( '--repo' );

const transpiler = new Transpiler( { silent: true } );
Expand Down

0 comments on commit ac371f9

Please sign in to comment.