Skip to content

Commit

Permalink
feat: pre-generate package-lock for faster install (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Sep 13, 2018
1 parent b608014 commit dcb0427
Show file tree
Hide file tree
Showing 7 changed files with 11,740 additions and 25 deletions.
33 changes: 31 additions & 2 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const constants = require('./constants');
const naming = require('./naming');
const packageJSON = require('./package-json');
const validators = require('./validators');
const spawnSync = require('child_process').spawnSync;

module.exports = class extends Generator {

Expand Down Expand Up @@ -221,7 +222,8 @@ module.exports = class extends Generator {
'test/_plugin.test.js',
'_index.html',
'_CONTRIBUTING.md',
'_README.md'
'_README.md',
'_package-lock.json'
];

this._promptsToFilter = [];
Expand Down Expand Up @@ -331,7 +333,34 @@ module.exports = class extends Generator {
* we don't want to run that (or depend on it in any way).
*/
install() {
this.npmInstall();
const result = spawnSync('npm', ['--version']);

// no access to npm uh oh, lets let yeoman throw an error
if (result.status !== 0) {
return this.npmInstall();
}

// get the major version for npm
const major = parseFloat(result.stdout.toString().trim().split('.')[0]);

if (!major || major <= 5) {
return this.npmInstall();
}

// this.npmInstall automaticall handles
// skipInstall, but our custom install does not.
// handle it now.
if (this.options.skipInstall) {
this.log('Skipping Install, to install later please run: npm i --package-lock-only && npm ci');
return;
}

// if we are on npm greater than 6
// save time by updating package-lock-only
// and then running npm ci
spawnSync('npm', ['i', '--package-lock-only'], {stdio: 'inherit', cwd: this.destinationRoot()});
spawnSync('npm', ['ci'], {stdio: 'inherit', cwd: this.destinationRoot()});

}

/**
Expand Down
Loading

0 comments on commit dcb0427

Please sign in to comment.