#!/usr/bin/env node // TODO: Remove this once babel-loader updates // https://github.com/babel/babel-loader/pull/391 process.noDeprecation = true; const yargs = require('yargs'); const { pathOr } = require('ramda'); const build = require('./build'); const inspect = require('./inspect'); const start = require('./start'); const test = require('./test'); const { getNodeEnv, getPackageJson } = require('../src/utils'); const args = yargs .option('inspect', { description: 'Output a string representation of the configuration used by Neutrino and exit', boolean: true, default: false, global: true }) .option('use', { description: 'A list of Neutrino middleware used to configure the build', array: true, default: [], global: true }) .option('env', { description: 'The value for the environment variable, NODE_ENV', string: true, 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 ') .recommendCommands() .strict() .version() .help() .argv; // foldMiddleware :: Object -> Array const foldMiddleware = (args) => { const pkg = getPackageJson(); const pkgMiddleware = pathOr([], ['neutrino', 'use'], pkg); return [...new Set(pkgMiddleware.concat(args.use))]; }; // normalizeOptions :: Object -> Object const normalizeOptions = (args) => { const pkg = getPackageJson(); const options = pathOr({}, ['neutrino', 'options'], pkg); const env = args.inspect ? getNodeEnv(args._[0], args.env) : args.env; return Object.assign(options, { config: pathOr({}, ['neutrino', 'config'], pkg), args: Object.assign(args, { env }) }); }; process.on('unhandledRejection', (err) => { console.error(err); process.exit(1); }); const cmd = args.inspect ? 'inspect' : args._[0]; const middleware = foldMiddleware(args); const options = normalizeOptions(args); ({ build, inspect, start, test })[cmd](middleware, options);