Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
feat(validate): Update validate script
Browse files Browse the repository at this point in the history
Validate script now checks for prefered package manager bin – yarn or npm.
  • Loading branch information
adambrgmn committed Dec 19, 2017
1 parent 2199128 commit 72f6d63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/scripts/__tests__/__snapshots__/validate.js.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validate allows you to specify your own npm scripts 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names specialbuild,specialtest,speciallint --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "npm run specialbuild --silent" "npm run specialtest --silent" "npm run speciallint --silent"`;
exports[`validate allows you to specify your own npm scripts 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names specialbuild,specialtest,speciallint --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run specialbuild --silent" "yarn run specialtest --silent" "yarn run speciallint --silent"`;

exports[`validate calls concurrently with all scripts 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,test,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset,bgCyan.bold.reset "npm run build --silent" "npm run lint --silent" "npm run test --silent -- --coverage" "npm run flow --silent"`;
exports[`validate calls concurrently with all scripts 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,test,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset,bgCyan.bold.reset "yarn run build --silent" "yarn run lint --quiet" "yarn run test --silent --coverage" "yarn run flow --silent"`;

exports[`validate does not include "build" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names lint,test,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "npm run lint --silent" "npm run test --silent -- --coverage" "npm run flow --silent"`;
exports[`validate does not include "build" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names lint,test,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run lint --quiet" "yarn run test --silent --coverage" "yarn run flow --silent"`;

exports[`validate does not include "flow" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,test --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "npm run build --silent" "npm run lint --silent" "npm run test --silent -- --coverage"`;
exports[`validate does not include "flow" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,test --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run build --silent" "yarn run lint --quiet" "yarn run test --silent --coverage"`;

exports[`validate does not include "lint" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,test,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "npm run build --silent" "npm run test --silent -- --coverage" "npm run flow --silent"`;
exports[`validate does not include "lint" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,test,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run build --silent" "yarn run test --silent --coverage" "yarn run flow --silent"`;

exports[`validate does not include "test" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "npm run build --silent" "npm run lint --silent" "npm run flow --silent"`;
exports[`validate does not include "test" if it doesn't have that script 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,lint,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset,bgMagenta.bold.reset "yarn run build --silent" "yarn run lint --quiet" "yarn run flow --silent"`;

exports[`validate doesn't use test or lint if it's in precommit 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "npm run build --silent" "npm run flow --silent"`;
exports[`validate doesn't use test or lint if it's in precommit 1`] = `concurrently --kill-others-on-fail --prefix [{name}] --names build,flow --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "yarn run build --silent" "yarn run flow --silent"`;
21 changes: 14 additions & 7 deletions src/scripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,37 @@ const {
resolveBin,
ifScript,
getConcurrentlyArgs,
getPackageManagerBin,
} = require('../utils');

// precommit runs linting and tests on the relevant files
// so those scripts don't need to be run if we're running
// this in the context of a precommit hook.
const precommit = parseEnv('SCRIPTS_PRECOMMIT', false);

const validateScripts = process.argv[2];

const useDefaultScripts = typeof validateScripts !== 'string';

const pm = getPackageManagerBin();
const extraDashDash = pm === 'npm' ? '-- ' : '';

const scripts = useDefaultScripts
? {
build: ifScript('build', 'npm run build --silent'),
lint: precommit ? null : ifScript('lint', 'npm run lint --silent'),
build: ifScript('build', `${getPackageManagerBin()} run build --silent`),
lint: precommit
? null
: ifScript('lint', `${getPackageManagerBin()} run lint --quiet`),
test: precommit
? null
: ifScript('test', 'npm run test --silent -- --coverage'),
flow: ifScript('flow', 'npm run flow --silent'),
: ifScript(
'test',
`${getPackageManagerBin()} run test --silent ${extraDashDash}--coverage`,
),
flow: ifScript('flow', `${getPackageManagerBin()} run flow --silent`),
}
: validateScripts.split(',').reduce(
(scriptsToRun, name) =>
Object.assign({}, scriptsToRun, {
[name]: `npm run ${name} --silent`,
[name]: `${getPackageManagerBin()} run ${name} --silent`,
}),
{},
);
Expand Down

0 comments on commit 72f6d63

Please sign in to comment.