Skip to content

Commit

Permalink
Merge pull request #3831 from cfpb/app_npm_install
Browse files Browse the repository at this point in the history
Add postinstall script for apps under cfgov-refresh
  • Loading branch information
anselmbradford authored Feb 28, 2018
2 parents 34678ba + 7fae968 commit 8634846
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = {
build: [
'config/**/*.js',
'gulpfile.js',
'gulp/**/*.js'
'gulp/**/*.js',
'scripts/npm/**/*.js'
]
},
test: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"wcag": "0.3.0"
},
"scripts": {
"test": "snyk test"
"test": "snyk test",
"postinstall": "node scripts/npm/apps-install"
},
"snyk": true
}
39 changes: 39 additions & 0 deletions scripts/npm/apps-install/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
This script handles installing node dependencies for a project that lives
under cfgov-refresh, but has its own package.json. These projects appear
under the ./cfgov/unprocessed/apps/ path.
*/

const fs = require( 'fs' );
const exec = require( 'child_process' ).exec;

const paths = require( '../../../config/environment' ).paths;

// Aggregate application namespaces that appear in unprocessed/apps.
// eslint-disable-next-line no-sync
let apps = fs.readdirSync( `${ paths.unprocessed }/apps/` );

// Filter out .DS_STORE directory.
apps = apps.filter( dir => dir.charAt( 0 ) !== '.' );

// Run each application's JS through webpack and store the gulp streams.
apps.forEach( app => {
/* Check if node_modules directory exists in a particular app's folder.
If it doesn't log the command to add it and don't process the scripts. */
const appsPath = `${ paths.unprocessed }/apps/${ app }`;
// eslint-disable-next-line no-sync
if ( fs.existsSync( `${ appsPath }/package.json` ) ) {
exec( `npm --prefix ${ appsPath } install ${ appsPath }`,
( error, stdout, stderr ) => {
// eslint-disable-next-line no-console
console.log( 'App\'s npm output: ' + stdout );
// eslint-disable-next-line no-console
console.log( 'App\'s npm errors: ' + stderr );
if ( error !== null ) {
// eslint-disable-next-line no-console
console.log( 'App\'s exec error: ' + error );
}
}
);
}
} );

0 comments on commit 8634846

Please sign in to comment.