-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including some aqua-related code snippets, see phetsims/aqua#88
- Loading branch information
1 parent
5273cc8
commit 05e9669
Showing
10 changed files
with
244 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ], '../' ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters