From 96a28c174daf979250f6e9db805bc61e7b28caa7 Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Wed, 11 Sep 2024 22:56:54 -0600 Subject: [PATCH] Move to tasks/, see https://github.com/phetsims/chipper/issues/1459 --- js/grunt/Gruntfile.js | 71 ++++++------------- js/grunt/tasks/commits-since.js | 17 +++++ .../tasks/generate-development-strings.js | 15 ++++ js/grunt/tasks/published-README.js | 13 ++++ js/grunt/tasks/report-media.js | 14 ++++ js/grunt/tasks/report-third-party.js | 10 +++ js/grunt/tasks/sort-imports.js | 20 ++++++ js/grunt/tasks/unpublished-README.js | 13 ++++ 8 files changed, 125 insertions(+), 48 deletions(-) create mode 100644 js/grunt/tasks/commits-since.js create mode 100644 js/grunt/tasks/generate-development-strings.js create mode 100644 js/grunt/tasks/published-README.js create mode 100644 js/grunt/tasks/report-media.js create mode 100644 js/grunt/tasks/report-third-party.js create mode 100644 js/grunt/tasks/sort-imports.js create mode 100644 js/grunt/tasks/unpublished-README.js diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js index 7f42c420..e4aa8293 100644 --- a/js/grunt/Gruntfile.js +++ b/js/grunt/Gruntfile.js @@ -212,7 +212,7 @@ Minify-specific options: 'Generates top-level SIM-a11y-view.html file used for visualizing accessible content. Usually you should ' + 'set the "phet.simFeatures.supportsInteractiveDescription":true flag in the sim package.json and run `grunt update` ' + 'instead of manually generating this.', - wrapExecSync( `node ../chipper/js/grunt/tasks/generateA11yViewHTML.js --repo ${repo}` ) + wrapExecSync( `node ../chipper/js/grunt/tasks/generate-a11y-view.js --repo ${repo}` ) ); grunt.registerTask( 'update', ` @@ -231,77 +231,49 @@ Updates the normal automatically-generated files for this repository. Includes: 'To support locales=* in unbuilt mode, generate a conglomerate JSON file for each repo with translations in babel. Run on all repos via:\n' + '* for-each.sh perennial-alias/data/active-repos npm install\n' + '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings', - wrapTask( async () => { - const generateDevelopmentStrings = require( '../scripts/generateDevelopmentStrings' ); - const fs = require( 'fs' ); - - if ( fs.existsSync( `../${repo}/${repo}-strings_en.json` ) ) { - generateDevelopmentStrings( repo ); - } - } ) + wrapExecSync( `node ../chipper/js/grunt/tasks/generate-development-strings.js --repo ${repo}` ) ); grunt.registerTask( 'published-README', 'Generates README.md file for a published simulation.', - wrapTask( async () => { - const generateREADME = require( './generateREADME' ); // used by multiple tasks - await generateREADME( repo, true /* published */ ); - } ) ); + wrapExecSync( `node ../chipper/js/grunt/tasks/published-README.js --repo ${repo}` ) + ); grunt.registerTask( 'unpublished-README', 'Generates README.md file for an unpublished simulation.', - wrapTask( async () => { - const generateREADME = require( './generateREADME' ); // used by multiple tasks - await generateREADME( repo, false /* published */ ); - } ) ); - - grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', wrapTask( async () => { - const sortImports = require( './sortImports' ); - - const file = grunt.option( 'file' ); + wrapExecSync( `node ../chipper/js/grunt/tasks/unpublished-README.js --repo ${repo}` ) + ); - if ( file ) { - sortImports( file ); - } - else { - grunt.file.recurse( `../${repo}/js`, absfile => sortImports( absfile ) ); - } - } ) ); + // TODO: https://github.com/phetsims/chipper/issues/1459 probably does not need to be here in grunt + grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', + wrapExecSync( `node ../chipper/js/grunt/tasks/sort-imports.js --repo ${repo} ${process.argv.slice( 2 ).join( ' ' )}` ) + ); + // TODO: https://github.com/phetsims/chipper/issues/1459 probably does not need to be here in grunt grunt.registerTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.', - wrapTask( async () => { - const dateString = grunt.option( 'date' ); - assert( dateString, 'missing required option: --date={{DATE}}' ); - - const commitsSince = require( './commitsSince' ); - - await commitsSince( repo, dateString ); - } ) ); + wrapExecSync( `node ../chipper/js/grunt/tasks/commits-since.js --repo ${repo} ${process.argv.slice( 2 ).join( ' ' )}` ) // TODO: Just need date, or take everything? See https://github.com/phetsims/chipper/issues/1459 + ); // See reportMedia.js + // TODO: https://github.com/phetsims/chipper/issues/1459 probably does not need to be here in grunt grunt.registerTask( 'report-media', '(project-wide) Report on license.json files throughout all working copies. ' + 'Reports any media (such as images or sound) files that have any of the following problems:\n' + '(1) incompatible-license (resource license not approved)\n' + '(2) not-annotated (license.json missing or entry missing from license.json)\n' + '(3) missing-file (entry in the license.json but not on the file system)', - wrapTask( async () => { - const reportMedia = require( './reportMedia' ); - - await reportMedia( repo ); - } ) ); + wrapExecSync( `node ../chipper/js/grunt/tasks/report-media.js --repo ${repo}` ) + ); // see reportThirdParty.js + // TODO: https://github.com/phetsims/chipper/issues/1459 probably does not need to be here in grunt grunt.registerTask( 'report-third-party', 'Creates a report of third-party resources (code, images, sound, etc) used in the published PhET simulations by ' + 'reading the license information in published HTML files on the PhET website. This task must be run from main. ' + 'After running this task, you must push sherpa/third-party-licenses.md.', - wrapTask( async () => { - const reportThirdParty = require( './reportThirdParty' ); - - await reportThirdParty(); - } ) ); + wrapExecSync( `node ../chipper/js/grunt/tasks/report-third-party.js --repo ${repo}` ) + ); grunt.registerTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo', wrapTask( async () => { const modulify = require( './modulify' ); @@ -385,7 +357,9 @@ Updates the normal automatically-generated files for this repository. Includes: // Notify about long transpile times, in case more people need to skip if ( transpileTimeMS >= 5000 ) { - grunt.log.writeln( `generate-phet-io-api transpilation took ${transpileTimeMS} ms` ); + grunt.log.writeln( + `generate-phet-io-api transpilation took ${transpileTimeMS} ms` + ); } } else { @@ -460,6 +434,7 @@ Updates the normal automatically-generated files for this repository. Includes: } ) ); + // TODO: https://github.com/phetsims/chipper/issues/1459 probably does not need to be here in grunt grunt.registerTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo', diff --git a/js/grunt/tasks/commits-since.js b/js/grunt/tasks/commits-since.js new file mode 100644 index 00000000..5ed2ff2f --- /dev/null +++ b/js/grunt/tasks/commits-since.js @@ -0,0 +1,17 @@ +// Copyright 2024, University of Colorado Boulder + +const getRequiredArg = require( './getRequiredArg' ); + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +const grunt = require( 'grunt' ); +const repo = getRequiredArg( '--repo' ); + +const dateString = grunt.option( 'date' ); +assert( dateString, 'missing required option: --date={{DATE}}' ); + +const commitsSince = require( '../commitsSince' ); +const assert = require( 'assert' ); + +await commitsSince( repo, dateString ); \ No newline at end of file diff --git a/js/grunt/tasks/generate-development-strings.js b/js/grunt/tasks/generate-development-strings.js new file mode 100644 index 00000000..ef68cefa --- /dev/null +++ b/js/grunt/tasks/generate-development-strings.js @@ -0,0 +1,15 @@ +// Copyright 2024, University of Colorado Boulder + +const getRequiredArg = require( './getRequiredArg' ); + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +const repo = getRequiredArg( '--repo' ); + +const generateDevelopmentStrings = require( '../../scripts/generateDevelopmentStrings' ); +const fs = require( 'fs' ); + +if ( fs.existsSync( `../${repo}/${repo}-strings_en.json` ) ) { + generateDevelopmentStrings( repo ); +} \ No newline at end of file diff --git a/js/grunt/tasks/published-README.js b/js/grunt/tasks/published-README.js new file mode 100644 index 00000000..4bbd092e --- /dev/null +++ b/js/grunt/tasks/published-README.js @@ -0,0 +1,13 @@ +// Copyright 2024, University of Colorado Boulder + +const getRequiredArg = require( './getRequiredArg' ); + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +const repo = getRequiredArg( '--repo' ); + +const generateREADME = require( './generateREADME' ); // used by multiple tasks +( async () => { + await generateREADME( repo, true /* published */ ); +} )(); \ No newline at end of file diff --git a/js/grunt/tasks/report-media.js b/js/grunt/tasks/report-media.js new file mode 100644 index 00000000..44e40d9e --- /dev/null +++ b/js/grunt/tasks/report-media.js @@ -0,0 +1,14 @@ +// Copyright 2024, University of Colorado Boulder + +const getRequiredArg = require( './getRequiredArg' ); + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +const repo = getRequiredArg( '--repo' ); + +const reportMedia = require( './reportMedia' ); + +( () => { + await reportMedia( repo ); +} )(); \ No newline at end of file diff --git a/js/grunt/tasks/report-third-party.js b/js/grunt/tasks/report-third-party.js new file mode 100644 index 00000000..3c18d95f --- /dev/null +++ b/js/grunt/tasks/report-third-party.js @@ -0,0 +1,10 @@ +// Copyright 2024, University of Colorado Boulder + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +( () => { + const reportThirdParty = require( '../reportThirdParty' ); + + await reportThirdParty(); +} )(); \ No newline at end of file diff --git a/js/grunt/tasks/sort-imports.js b/js/grunt/tasks/sort-imports.js new file mode 100644 index 00000000..1d69b180 --- /dev/null +++ b/js/grunt/tasks/sort-imports.js @@ -0,0 +1,20 @@ +// Copyright 2024, University of Colorado Boulder + +const getRequiredArg = require( './getRequiredArg' ); + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +const grunt = require( 'grunt' ); +const repo = getRequiredArg( '--repo' ); + +const sortImports = require( './sortImports' ); + +const file = grunt.option( 'file' ); + +if ( file ) { + sortImports( file ); +} +else { + grunt.file.recurse( `../${repo}/js`, absfile => sortImports( absfile ) ); +} \ No newline at end of file diff --git a/js/grunt/tasks/unpublished-README.js b/js/grunt/tasks/unpublished-README.js new file mode 100644 index 00000000..6844a0c4 --- /dev/null +++ b/js/grunt/tasks/unpublished-README.js @@ -0,0 +1,13 @@ +// Copyright 2024, University of Colorado Boulder + +const getRequiredArg = require( './getRequiredArg' ); + +/** + * @author Sam Reid (PhET Interactive Simulations) + */ +const repo = getRequiredArg( '--repo' ); + +const generateREADME = require( './generateREADME' ); // used by multiple tasks +( async () => { + await generateREADME( repo, false /* published */ ); +} )(); \ No newline at end of file