Skip to content

Commit

Permalink
Merge branch 'master' into a11ystring-plugin
Browse files Browse the repository at this point in the history
# Conflicts:
#	js/common/ChipperStringUtils.js
  • Loading branch information
zepumph committed Oct 7, 2019
2 parents a5f2c99 + ef059a2 commit 55bac8e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 69 deletions.
6 changes: 4 additions & 2 deletions eslint/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = {
args: 'none'
}
],

// error when let is used but the variable is never reassigned, see https://github.com/phetsims/tasks/issues/973
'prefer-const': [
2,
Expand Down Expand Up @@ -125,19 +126,20 @@ module.exports = {
// disallow use of undefined when initializing variables
'no-undef-init': 2,

//
// phet-specific require statement rules
'require-statement-match': 2,
'phet-io-require-contains-ifphetio': 2,
'string-require-statement-match': 2,

// Require @public/@private for this.something = result;
'property-visibility-annotation': 0,
'no-property-in-require-statement': 2,

// permit only one var declaration per line, see #390
'one-var': [
2,
'never'
],
'string-require-statement-match': 2,

// require radix argument for parseInt
radix: 2,
Expand Down
2 changes: 1 addition & 1 deletion js/SimVersion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2019, University of Colorado Boulder
// Copyright 2019, University of Colorado Boulder

/**
* Handles serializing and deserializing versions for simulations.
Expand Down
12 changes: 0 additions & 12 deletions js/common/ChipperStringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@
return str;
},

/**
* Return the first line that contains the substring 'find'
* @param {string} string - the parent string within which to search
* @param {string} find - the legal regex string to be found
* @returns {array} - the whole line containing the matched substring
*/
firstLineThatContains: function( string, find ) {
const findRE = '.*' + find.replace( /[-/\\^$*+?.()|[\]{}]/g, '\\$&' ) + '.*';
const theReturn = string.match( new RegExp( findRE, 'g' ) );
return theReturn ? theReturn[ 0 ] : null;
},

/**
* Recurse through a string file and format each string value appropriately
* @param {StringMap} stringMap
Expand Down
59 changes: 13 additions & 46 deletions js/grunt/phet-io/copySupplementalPhetioFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const minify = require( '../minify' );
// constants
const DEDICATED_REPO_WRAPPER_PREFIX = 'phet-io-wrapper-';
const WRAPPER_COMMON_FOLDER = 'phet-io-wrappers/common';
const PRODUCTION_SITE = 'phet-io.colorado.edu';
const WRAPPERS_FOLDER = 'wrappers/'; // The wrapper index assumes this constant, please see phet-io-wrappers/index/index.js before changing

// phet-io internal files to be consolidated into 1 file and publicly served as a minified phet-io library.
Expand Down Expand Up @@ -124,60 +123,28 @@ module.exports = async ( repo, version, simulationDisplayName, packageObject ) =
}
} );

/*
* Remove individual common phet-io code imports because they are all in phetio.js
*/
// Remove individual common phet-io code imports because they are all in phetio.js
// NOTE: don't use Array.prototype.forEach here. After bashing my head against a wall I think it is because of
// race conditions editing `contents`.
for ( let i = 0; i < LIB_FILES.length; i++ ) {
const filePath = LIB_FILES[ i ];
const fileName = filePath.slice( filePath.lastIndexOf( '/' ) + 1 ); // plus one to not include the slash

// TODO: use LIB_FILES and/or factor this outs
// This returns the whole line that contains this substring, so it can be removed
const firstQueryStringLine = ChipperStringUtils.firstLineThatContains( contents, 'QueryStringMachine.js">' );

// Don't remove the import if it is coming from the phet-io website, only if it is a relative path in requirejs mode.
if ( firstQueryStringLine && firstQueryStringLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstQueryStringLine, '' ); // included in phetio.js
}
const firstAssertLine = ChipperStringUtils.firstLineThatContains( contents, 'assert.js">' );
if ( firstAssertLine && firstAssertLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstAssertLine, '' ); // included in phetio.js
}
const firstIFrameClientLine = ChipperStringUtils.firstLineThatContains( contents, 'Client.js">' );
if ( firstIFrameClientLine && firstIFrameClientLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstIFrameClientLine, '' ); // included in phetio.js
}

// Bundle in readFile and loadWrapperTemplate so they can be used uniformly by index (in root location) and wrappers (nested locations)
const firstReadFileLine = ChipperStringUtils.firstLineThatContains( contents, 'readFile.js">' );
if ( firstReadFileLine && firstReadFileLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstReadFileLine, '' ); // included in phetio.js
}
const firstLoadWrapperTemplateLine = ChipperStringUtils.firstLineThatContains( contents, 'loadWrapperTemplate.js">' );
if ( firstLoadWrapperTemplateLine && firstLoadWrapperTemplateLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstLoadWrapperTemplateLine, '' ); // included in phetio.js
}
const firstWrapperTypeLine = ChipperStringUtils.firstLineThatContains( contents, 'WrapperTypes.js">' );
if ( firstWrapperTypeLine && firstWrapperTypeLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstWrapperTypeLine, '' ); // included in phetio.js
}
const firstPhetioIDUtilsLine = ChipperStringUtils.firstLineThatContains( contents, 'PhetioIDUtils.js' );
if ( firstPhetioIDUtilsLine && firstPhetioIDUtilsLine.indexOf( PRODUCTION_SITE ) === -1 ) {
contents = ChipperStringUtils.replaceAll( contents, firstPhetioIDUtilsLine, '' ); // included in phetio.js
// a newline at the end of this regex breaks it. Likely because the "$" matches the newline. I tried `\n` and `\\n`
const regExp = new RegExp( `^.*/js/${fileName}".*$`, 'gm' );
contents = contents.replace( regExp, '' );
}

// Support wrappers that use code from phet-io-wrappers
contents = ChipperStringUtils.replaceAll( contents, '/phet-io-wrappers/', '/' );

// Don't use ChipperStringUtils because we want to capture the relative path and transfer it to the new script.
// This is to support providing the relative path through the build instead of just hard coding it.
contents = contents.replace( /<!--\{\{([./]*)phet-io.js}}-->/g,
`<script src = "$1${pathToLib}" ></script>`
);

// This must be after the above phet-io.js import and Client.js stripping. This case is to support wrappers
// that use the data-client-name attribute to dictate their own Type name.
contents = ChipperStringUtils.replaceAll( contents,
'../common/js/Client.js',
`${pathToLib}`
contents = contents.replace(
/<!--(<script src="[./]*\{\{PATH_TO_LIB_FILE}}".*><\/script>)-->/g, // '.*' is to support `data-client-name` in wrappers like "multi"
'$1' // just uncomment, dont fill it in yet
);
contents = ChipperStringUtils.replaceAll( contents, '{{PATH_TO_LIB_FILE}}', pathToLib );

contents = ChipperStringUtils.replaceAll( contents,
'<!--{{GOOGLE_ANALYTICS.js}}-->',
Expand Down
4 changes: 2 additions & 2 deletions js/grunt/phet-io/generatePhetioAPIFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ module.exports = async ( repo, localTestingURL ) => {
receivedTypes = true;
await resolved();
}
else {
console.log( msg.text() );
else if ( msg.type() === 'error' ) {
console.error( msg.text() );
}
} );

Expand Down
5 changes: 3 additions & 2 deletions js/initialize-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
* enables cache busting in requirejs mode.
*/
cacheBust: {
type: 'flag'
type: 'boolean',
defaultValue: true
},

/**
Expand Down Expand Up @@ -557,7 +558,7 @@
vibration: {
type: 'string',
defaultValue: null,
validValues: [ null, 'objects', 'interaction', 'state' ]
validValues: [ null, 'objects', 'manipulation', 'interaction-changes', 'result' ]
},

/**
Expand Down
2 changes: 1 addition & 1 deletion templates/sim-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ require.config( {
{{CONFIG_LINES}}
},

// optional cache bust to make browser refresh load all included scripts, can be enabled with ?cacheBust
// Cache busting is applied by default, but can be disabled via ?cacheBust=false, see initialize-globals.js
urlArgs: phet.chipper.getCacheBustArgs()
} );
6 changes: 3 additions & 3 deletions templates/sim-development.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
const brandMatch = location.search.match( /brand=([^&]+)/ );
const brand = brandMatch ? decodeURIComponent( brandMatch[ 1 ] ) : 'adapted-from-phet';

// matches "cacheBust" at the start of the string, as well as directly after "?" or "&"
const cacheBust = /(^|\?|&)cacheBust/.test( location.search );
const queryAppend = cacheBust ? `?bust=${Date.now()}` : '';
// Cache busting is applied by default, but can be disabled via ?cacheBust=false, see initialize-globals.js
const isCacheBustDisabled = /(^|\?|&)cacheBust=false/.test( location.search );
const queryAppend = isCacheBustDisabled ? '' : `?bust=${Date.now()}`;

// Preloads, with more included for phet-io brand
let preloads = {{PRELOADS}};
Expand Down

0 comments on commit 55bac8e

Please sign in to comment.