You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
#!/usr/bin/env node
|
|
|
|
const Neutrino = require('../src/neutrino');
|
|
const yargs = require('yargs');
|
|
const path = require('path');
|
|
const pkg = require(path.join(process.cwd(), 'package.json'));
|
|
|
|
const pkgPresets = pkg.config && pkg.config.presets ? pkg.config.presets : [];
|
|
const environments = { build: 'production', start: 'development', test: 'test' };
|
|
const args = yargs
|
|
.option('presets', {
|
|
description: 'A list of Neutrino presets used to configure the build',
|
|
array: true,
|
|
default: [],
|
|
global: true
|
|
})
|
|
.command('start', 'Build a project in development mode')
|
|
.command('build', 'Compile the source directory to a bundled build')
|
|
.command('test [files..]', 'Run all suites from the test directory or provided files', {
|
|
coverage: {
|
|
description: 'Collect test coverage information and generate report',
|
|
boolean: true,
|
|
default: false
|
|
},
|
|
watch: {
|
|
description: 'Watch source files for changes and re-run tests',
|
|
boolean: true,
|
|
default: false
|
|
}
|
|
})
|
|
.demandCommand(1, 'You must specify a command for Neutrino to run.\nUSAGE: neutrino <command>')
|
|
.recommendCommands()
|
|
.strict()
|
|
.version()
|
|
.help()
|
|
.argv;
|
|
|
|
function run(command, presets) {
|
|
process.env.NODE_ENV = environments[command];
|
|
const N = new Neutrino(presets);
|
|
|
|
N[command](args)
|
|
.then(() => process.exit(0))
|
|
.catch(err => {
|
|
if (err) {
|
|
console.error(err);
|
|
}
|
|
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
run(args._[0], [...new Set(pkgPresets.concat(args.presets))]);
|
|
|