Skip to content

Commit

Permalink
Move to tasks/, see #1459
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Sep 12, 2024
1 parent a3d4a94 commit 0d60ca0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 75 deletions.
79 changes: 10 additions & 69 deletions js/grunt/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ if ( !global.processEventOptOut ) {
} );
}

const Transpiler = require( '../common/Transpiler' );
const transpiler = new Transpiler( { silent: true } );

// eslint-disable-next-line require-statement-match
const { spawn } = require( 'child_process' );
const getPhetLibs = require( './getPhetLibs' );
Expand Down Expand Up @@ -195,39 +192,9 @@ Minify-specific options:
wrapExecSync( `node ../chipper/js/grunt/tasks/lint.js --repo ${repo} ${process.argv.slice( 2 ).join( ' ' )}` )
);

grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)', wrapTask( async () => {
const lint = require( './lint' );

// --disable-eslint-cache disables the cache, useful for developing rules
const cache = !grunt.option( 'disable-eslint-cache' );
const fix = grunt.option( 'fix' );
const chipAway = grunt.option( 'chip-away' );
assert && assert( !grunt.option( 'patterns' ), 'patterns not support for lint-all' );

const getPhetLibs = require( './getPhetLibs' );

// Handle the lack of build.json
let buildLocal;
try {
buildLocal = grunt.file.readJSON( `${process.env.HOME}/.phet/build-local.json` );
}
catch( e ) {
buildLocal = {};
}

const brands = getBrands( grunt, repo, buildLocal );

const lintReturnValue = await lint( getPhetLibs( repo, brands ), {
cache: cache,
fix: fix,
chipAway: chipAway
} );

// Output results on errors.
if ( !lintReturnValue.ok ) {
grunt.fail.fatal( 'Lint failed' );
}
} ) );
grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)',
wrapExecSync( `node ../chipper/js/grunt/tasks/lint-all.js --repo ${repo} ${process.argv.slice( 2 ).join( ' ' )}` )
);

grunt.registerTask( 'generate-development-html',
'Generates top-level SIM_en.html file based on the preloads in package.json.',
Expand Down Expand Up @@ -479,6 +446,10 @@ Updates the normal automatically-generated files for this repository. Includes:
const skipTranspile = grunt.option( 'transpile' ) === false;
if ( !skipTranspile ) {
const startTime = Date.now();

const Transpiler = require( '../common/Transpiler' );
const transpiler = new Transpiler( { silent: true } );

transpiler.transpileAll();
const transpileTimeMS = Date.now() - startTime;

Expand Down Expand Up @@ -536,6 +507,9 @@ Updates the normal automatically-generated files for this repository. Includes:
}
else {

const Transpiler = require( '../common/Transpiler' );
const transpiler = new Transpiler( { silent: true } );

transpiler.transpileAll();
proposedAPIs = await generatePhetioMacroAPI( sims, {
showProgressBar: sims.length > 1,
Expand Down Expand Up @@ -633,37 +607,4 @@ Updates the normal automatically-generated files for this repository. Includes:
'pdom-comparison',
'release-branch-list'
].forEach( forwardToPerennialGrunt );
};

// TODO: https://github.com/phetsims/chipper/issues/1459 move to getBrands.js
const getBrands = ( grunt, repo, buildLocal ) => {

// Determine what brands we want to build
assert( !grunt.option( 'brand' ), 'Use --brands={{BRANDS}} instead of brand' );

const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` );
const supportedBrands = localPackageObject.phet.supportedBrands || [];

let brands;
if ( grunt.option( 'brands' ) ) {
if ( grunt.option( 'brands' ) === '*' ) {
brands = supportedBrands;
}
else {
brands = grunt.option( 'brands' ).split( ',' );
}
}
else if ( buildLocal.brands ) {
// Extra check, see https://github.com/phetsims/chipper/issues/640
assert( Array.isArray( buildLocal.brands ), 'If brands exists in build-local.json, it should be an array' );
brands = buildLocal.brands.filter( brand => supportedBrands.includes( brand ) );
}
else {
brands = [ 'adapted-from-phet' ];
}

// Ensure all listed brands are valid
brands.forEach( brand => assert( supportedBrands.includes( brand ), `Unsupported brand: ${brand}` ) );

return brands;
};
12 changes: 6 additions & 6 deletions js/grunt/tasks/generate-used-strings-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const getRequiredArg = require( './getRequiredArg' );
*/
const repo = getRequiredArg( '--repo' );

const getPhetLibs = require( './getPhetLibs' );
const getPhetLibs = require( '../getPhetLibs' );
const fs = require( 'fs' );
const webpackBuild = require( './webpackBuild' );
const ChipperConstants = require( '../common/ChipperConstants' );
const getLocalesFromRepository = require( './getLocalesFromRepository' );
const getStringMap = require( './getStringMap' );
const webpackBuild = require( '../webpackBuild' );
const ChipperConstants = require( '../../common/ChipperConstants' );
const getLocalesFromRepository = require( '../getLocalesFromRepository' );
const getStringMap = require( '../getStringMap' );

const Transpiler = require( '../../common/Transpiler' );
const Transpiler = require( '../../../common/Transpiler' );
const transpiler = new Transpiler( { silent: true } );

transpiler.transpileRepos( getPhetLibs( repo ) );
Expand Down
45 changes: 45 additions & 0 deletions js/grunt/tasks/lint-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024, University of Colorado Boulder

const getRequiredArg = require( './getRequiredArg' );
const getBrands = require( './getBrands' );
const assert = require( 'assert' );

/**
* @author Sam Reid (PhET Interactive Simulations)
*/
const grunt = require( 'grunt' );
const repo = getRequiredArg( '--repo' );

const lint = require( '../lint' );

// --disable-eslint-cache disables the cache, useful for developing rules
const cache = !grunt.option( 'disable-eslint-cache' );
const fix = grunt.option( 'fix' );
const chipAway = grunt.option( 'chip-away' );
assert && assert( !grunt.option( 'patterns' ), 'patterns not support for lint-all' );

const getPhetLibs = require( '../getPhetLibs' );

// Handle the lack of build.json
let buildLocal;
try {
buildLocal = grunt.file.readJSON( `${process.env.HOME}/.phet/build-local.json` );
}
catch( e ) {
buildLocal = {};
}

const brands = getBrands( grunt, repo, buildLocal );

( async () => {
const lintReturnValue = await lint( getPhetLibs( repo, brands ), {
cache: cache,
fix: fix,
chipAway: chipAway
} );

// Output results on errors.
if ( !lintReturnValue.ok ) {
grunt.fail.fatal( 'Lint failed' );
}
} )();

0 comments on commit 0d60ca0

Please sign in to comment.