@interaktiv/dia-scripts
Version:
CLI toolbox with common scripts for most sort of projects at DIA
36 lines (31 loc) • 1.16 kB
JavaScript
;
const {
parseEnv,
ifTitaniumProject,
ifSfdxProject,
getRunAllArgs,
resolveSelf,
runAll
} = 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);
if (preCommit) throw new Error('Running setup on pre-commit is not allowed');
const setupScriptsArg = process.argv[2];
const args = process.argv.slice(3);
const setupScripts = typeof setupScriptsArg === 'string' ? setupScriptsArg.split(',') : [];
const useDefaultScripts = setupScripts.length === 0;
const diaScripts = resolveSelf();
if (useDefaultScripts) {
const scripts = {
npm: `npm install`,
pmd: ifSfdxProject(`${diaScripts} setup/pmd ${args.join(' ')}`),
titanium: ifTitaniumProject(`${diaScripts} setup/titanium ${args.join(' ')}`),
validate: `${diaScripts} validate`
};
runAll(getRunAllArgs(scripts));
} else {
const script = setupScripts.slice(0, 1);
process.argv = process.argv.filter(a => setupScripts.includes(a) === false);
require(`./${script}`);
}