From 72f6d6372e3deea59933eb691fbc044aa31dd57c Mon Sep 17 00:00:00 2001 From: Adam Bergman Date: Tue, 19 Dec 2017 12:03:02 +0100 Subject: [PATCH] feat(validate): Update validate script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validate script now checks for prefered package manager bin – yarn or npm. --- .../__tests__/__snapshots__/validate.js.snap | 14 ++++++------- src/scripts/validate.js | 21 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/scripts/__tests__/__snapshots__/validate.js.snap b/src/scripts/__tests__/__snapshots__/validate.js.snap index f1a5163..1ad1a32 100644 --- a/src/scripts/__tests__/__snapshots__/validate.js.snap +++ b/src/scripts/__tests__/__snapshots__/validate.js.snap @@ -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"`; diff --git a/src/scripts/validate.js b/src/scripts/validate.js index aa7f6dd..64e1bc6 100644 --- a/src/scripts/validate.js +++ b/src/scripts/validate.js @@ -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`, }), {}, );