Skip to content

Commit

Permalink
Including some aqua-related code snippets, see phetsims/aqua#88
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Apr 15, 2020
1 parent 5273cc8 commit 05e9669
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 3 deletions.
28 changes: 28 additions & 0 deletions js/common/asyncFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2020, University of Colorado Boulder

/**
* Returns an array filtered asynchronously
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

/**
* Returns an array filtered asynchronously
*
* @param {Array.<*>} list
* @param {function({*}):*})} f
* @returns {Promise.<Array.<*>>}
*/
const asyncFilter = async ( list, f ) => {
const items = [];
for ( const item of list ) {
if ( await f( item ) ) {
items.push( item );
}
}
return items;
};

module.exports = asyncFilter;
25 changes: 25 additions & 0 deletions js/common/asyncForEach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020, University of Colorado Boulder

/**
* Executes async functions on each element in an array.
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

/**
* Executes async functions on each element in an array.
*
* @param {Array.<*>} list
* @param {function({*})})} f
* @returns {Promise}
*/
const asyncForEach = async ( list, f ) => {
let index = 0;
for ( const item of list ) {
await f( item, index++ );
}
};

module.exports = asyncForEach;
27 changes: 27 additions & 0 deletions js/common/asyncMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020, University of Colorado Boulder

/**
* Returns an array mapped asynchronously
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

/**
* Returns an array mapped asynchronously
*
* @param {Array.<*>} list
* @param {function({*}):*})} f
* @returns {Promise.<Array.<*>>}
*/
const asyncMap = async ( list, f ) => {
const items = [];
let index = 0;
for ( const item of list ) {
items.push( await f( item, index++ ) );
}
return items;
};

module.exports = asyncMap;
24 changes: 24 additions & 0 deletions js/common/cloneMissingRepos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2020, University of Colorado Boulder

/**
* Clones missing repositories
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

const execute = require( './execute' );
const winston = require( 'winston' );

/**
* Clones missing repositories
* @public
*
* @returns {Promise} - Resolves with no value
*/
module.exports = async () => {
winston.info( 'Cloning missing repos' );

return execute( 'bash', [ 'perennial/bin/clone-missing-repos.sh' ], '../' );
};
36 changes: 36 additions & 0 deletions js/common/copyDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2020, University of Colorado Boulder

/**
* Copies a directory (recursively) to another location
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

const ncp = require( 'ncp' );
const winston = require( 'winston' );

/**
* Copies a directory (recursively) to another location
* @public
*
* @param {string} path
* @param {string} location
* @param {Object} [options]
* @returns {Promise}
*/
module.exports = function( pathToCopy, location, options ) {
winston.info( `copying ${pathToCopy} into ${location}` );

return new Promise( ( resolve, reject ) => {
ncp.ncp( pathToCopy, location, options, err => {
if ( err ) {
reject( `copyDirectory error: ${err}` );
}
else {
resolve();
}
} );
} );
};
34 changes: 34 additions & 0 deletions js/common/createDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020, University of Colorado Boulder

/**
* Creates a directory at the given path
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

const fs = require( 'fs' );
const winston = require( 'winston' );

/**
* Creates a directory at the given path
* @public
*
* @param {string} path
* @returns {Promise}
*/
module.exports = function( path ) {
winston.info( `Creating directory ${path}` );

return new Promise( ( resolve, reject ) => {
fs.mkdir( path, err => {
if ( err ) {
reject( `createDirectory: ${err}` );
}
else {
resolve();
}
} );
} );
};
34 changes: 34 additions & 0 deletions js/common/deleteDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020, University of Colorado Boulder

/**
* Deletes a path recursively
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

const rimraf = require( 'rimraf' );
const winston = require( 'winston' );

/**
* Deletes a path recursively
* @public
*
* @param {string} path - The path to delete recursively
* @returns {Promise}
*/
module.exports = function( path ) {
winston.info( `Deleting directory ${path}` );

return new Promise( ( resolve, reject ) => {
rimraf( path, err => {
if ( err ) {
reject( `rimraf: ${err}` );
}
else {
resolve();
}
} );
} );
};
27 changes: 27 additions & 0 deletions js/common/isStale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020, University of Colorado Boulder

/**
* Asynchronously checks whether a repo is not up-to-date with origin/master
*
* @author Jonathan Olson <[email protected]>
*/

'use strict';

const getRemoteBranchSHAs = require( './getRemoteBranchSHAs' );
const gitRevParse = require( './gitRevParse' );

/**
* Asynchronously checks whether a repo is not up-to-date with origin/master
* @public
*
* @param {string} repo - The repository name
* @returns {Promise.<boolean>}
* @rejects {ExecuteError}
*/
module.exports = async function( repo ) {
const currentSHA = await gitRevParse( repo, 'master' );
const remoteSHA = ( await getRemoteBranchSHAs( repo ) ).master;

return currentSHA !== remoteSHA;
};
10 changes: 7 additions & 3 deletions js/listContinuousTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const interactiveDescriptionRepos = getRepoList( 'interactive-descriptions' );
* {Array.<string>} test
* {string} type
* {string} [url]
* {string} [repo]
* {string} [queryParameters]
* {boolean} [es5]
* {string} [brand]
Expand All @@ -40,7 +41,8 @@ const tests = [];
tests.push( {
test: [ repo, 'build', 'phet' ],
type: 'build',
brand: 'phet'
brand: 'phet',
repo: repo
} );
} );

Expand All @@ -49,7 +51,8 @@ phetioRepos.forEach( repo => {
tests.push( {
test: [ repo, 'build', 'phet-io' ],
type: 'build',
brand: 'phet-io'
brand: 'phet-io',
repo: repo
} );
} );

Expand All @@ -58,7 +61,8 @@ repos.forEach( repo => {
if ( fs.existsSync( `../${repo}/Gruntfile.js` ) ) {
tests.push( {
test: [ repo, 'lint' ],
type: 'lint'
type: 'lint',
repo: repo
} );
}
} );
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"lodash": "^4.17.10",
"mimelib": "~0.2.19",
"minimist": "^1.1.1",
"ncp": "^2.0.0",
"qunit": "~2.4.1",
"request": "^2.55.0",
"rimraf": "^2.5.4",
"rsync": "^0.6.1",
"request-promise-native": "^1.0.5",
"thread-sleep": "^2.0.0",
Expand Down

0 comments on commit 05e9669

Please sign in to comment.