@interaktiv/dia-scripts
Version:
CLI toolbox with common scripts for most sort of projects at DIA
40 lines (32 loc) • 1.28 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
const exit = require('exit');
const chalk = require('chalk');
const {
parseEnv,
ifScript,
runAll,
getRunAllArgs
} = require('../utils'); // `pre-commit` 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 pre-commit hook.
const preCommit = parseEnv('SCRIPTS_PRE-COMMIT', false);
const validateScripts = process.argv[2];
const useDefaultScripts = typeof validateScripts !== 'string';
const scripts = useDefaultScripts ? {
build: ifScript('build', 'npm run build'),
'check:format': ifScript('format', 'npm run format -- --check'),
lint: preCommit ? null : ifScript('lint', 'npm run lint'),
test: preCommit ? null : ifScript('test', 'npm run test -- --coverage'),
flow: ifScript('flow', 'npm run flow')
} : validateScripts.split(',').reduce((scriptsToRun, name) => (0, _extends2.default)({}, scriptsToRun, {
[name]: ifScript(name, `npm run ${name}`)
}), {});
try {
runAll(getRunAllArgs(scripts));
} catch (error) {
console.log();
console.log(chalk.red(error.message));
exit(error.status);
}