Skip to content

Commit

Permalink
Add phetTimingLog, see #1342
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 17, 2022
1 parent e27c7f4 commit 0577740
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 169 deletions.
114 changes: 63 additions & 51 deletions js/grunt/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,76 +217,88 @@ module.exports = function( grunt ) {
const path = require( 'path' );
const fs = require( 'fs' );
const getPhetLibs = require( './getPhetLibs' );
const phetTimingLog = require( '../../../perennial-alias/js/common/phetTimingLog' );

// Parse minification keys
const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS );
const minifyOptions = {};
minifyKeys.forEach( minifyKey => {
const option = grunt.option( `minify.${minifyKey}` );
if ( option === true || option === false ) {
minifyOptions[ minifyKey ] = option;
await phetTimingLog.startAsync( 'grunt-build', async () => {

// Parse minification keys
const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS );
const minifyOptions = {};
minifyKeys.forEach( minifyKey => {
const option = grunt.option( `minify.${minifyKey}` );
if ( option === true || option === false ) {
minifyOptions[ minifyKey ] = option;
}
} );

// grunt options that apply to multiple build tasks
const instrument = !!grunt.option( 'instrument' );

// Do not uglify or transpile if it is being instrumented, so it will match development code as closely as possible
if ( instrument ) {
minifyOptions.babelTranspile = false;
minifyOptions.uglify = false;
}
} );

// grunt options that apply to multiple build tasks
const instrument = !!grunt.option( 'instrument' );
const repoPackageObject = grunt.file.readJSON( `../${repo}/package.json` );

// Do not uglify or transpile if it is being instrumented, so it will match development code as closely as possible
if ( instrument ) {
minifyOptions.babelTranspile = false;
minifyOptions.uglify = false;
}
// Run the type checker first.
const brands = getBrands( grunt, repo, buildLocal );

const repoPackageObject = grunt.file.readJSON( `../${repo}/package.json` );
await phetTimingLog.startAsync( 'tsc', async () => {

// Run the type checker first.
const brands = getBrands( grunt, repo, buildLocal );
// We must have phet-io code checked out to type check, since simLauncher imports phetioEngine
if ( brands.includes( 'phet-io' ) || brands.includes( 'phet' ) ) {
const results = await tsc( `../${repo}` );
reportTscResults( results, grunt );
}
else {
grunt.log.writeln( 'skipping type checking' );
}
} );

// We must have phet-io code checked out to type check, since simLauncher imports phetioEngine
if ( brands.includes( 'phet-io' ) || brands.includes( 'phet' ) ) {
const results = await tsc( `../${repo}` );
reportTscResults( results, grunt );
}
else {
grunt.log.writeln( 'skipping type checking' );
}
phetTimingLog.start( 'transpile', () => {

// If that succeeds, then convert the code to JS
transpiler.transpileRepos( getPhetLibs( repo ) );
// If that succeeds, then convert the code to JS
transpiler.transpileRepos( getPhetLibs( repo ) );
} );

// standalone
if ( repoPackageObject.phet.buildStandalone ) {
grunt.log.writeln( 'Building standalone repository' );
// standalone
if ( repoPackageObject.phet.buildStandalone ) {
grunt.log.writeln( 'Building standalone repository' );

const parentDir = `../${repo}/build/`;
if ( !fs.existsSync( parentDir ) ) {
fs.mkdirSync( parentDir );
}
const parentDir = `../${repo}/build/`;
if ( !fs.existsSync( parentDir ) ) {
fs.mkdirSync( parentDir );
}

fs.writeFileSync( `${parentDir}/${repo}.min.js`, await buildStandalone( repo, minifyOptions ) );
fs.writeFileSync( `${parentDir}/${repo}.min.js`, await buildStandalone( repo, minifyOptions ) );

if ( repoPackageObject.phet.standaloneTranspiles ) {
for ( const file of repoPackageObject.phet.standaloneTranspiles ) {
fs.writeFileSync( `../${repo}/build/${path.basename( file )}`, minify( grunt.file.read( file ) ) );
if ( repoPackageObject.phet.standaloneTranspiles ) {
for ( const file of repoPackageObject.phet.standaloneTranspiles ) {
fs.writeFileSync( `../${repo}/build/${path.basename( file )}`, minify( grunt.file.read( file ) ) );
}
}
}
}
else {
else {

const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` );
assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` );
grunt.log.writeln( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` );
const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` );
assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` );
grunt.log.writeln( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` );

// Other options
const allHTML = !!grunt.option( 'allHTML' );
const localesOption = grunt.option( 'locales' ) || 'en'; // Default back to English for now
// Other options
const allHTML = !!grunt.option( 'allHTML' );
const localesOption = grunt.option( 'locales' ) || 'en'; // Default back to English for now

for ( const brand of brands ) {
grunt.log.writeln( `Building brand: ${brand}` );
for ( const brand of brands ) {
grunt.log.writeln( `Building brand: ${brand}` );

await buildRunnable( repo, minifyOptions, instrument, allHTML, brand, localesOption, buildLocal );
await phetTimingLog.startAsync( 'build-brand-' + brand, async () => {
await buildRunnable( repo, minifyOptions, instrument, allHTML, brand, localesOption, buildLocal );
} );
}
}
}
} );
} )
);

Expand Down
Loading

0 comments on commit 0577740

Please sign in to comment.