From ac371f980576517c521f3cca4ae98d386c0ae99e Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Wed, 11 Sep 2024 20:21:52 -0600 Subject: [PATCH] Better support for command line arguments, see https://github.com/phetsims/chipper/issues/1459 --- js/grunt/Gruntfile.js | 2 +- js/grunt/tasks/build.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js index acd4b238..34ff2400 100644 --- a/js/grunt/Gruntfile.js +++ b/js/grunt/Gruntfile.js @@ -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', diff --git a/js/grunt/tasks/build.js b/js/grunt/tasks/build.js index 6aeda55b..fb56c45c 100644 --- a/js/grunt/tasks/build.js +++ b/js/grunt/tasks/build.js @@ -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 } );