From 60880d8b57a385c9be4816f587a031f5f619a2e3 Mon Sep 17 00:00:00 2001 From: Jarid Margolin Date: Wed, 15 Mar 2017 21:18:02 -0400 Subject: [PATCH] Make run method in bin/neutrino self contained. --- packages/neutrino/bin/neutrino | 22 +++++++++------------- packages/neutrino/package.json | 1 + 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/neutrino/bin/neutrino b/packages/neutrino/bin/neutrino index f2649a4..eeadbde 100755 --- a/packages/neutrino/bin/neutrino +++ b/packages/neutrino/bin/neutrino @@ -10,17 +10,9 @@ const { pathOr, pipe, partialRight } = require('ramda'); const { join } = require('path'); const stringify = require('javascript-stringify'); const sort = require('deep-sort-object'); +const optional = require('optional'); const inspect = pipe(sort, partialRight(stringify, [null, 2]), console.log, process.exit); -const cwd = process.cwd(); -let pkg = {}; - -try { - pkg = require(join(cwd, 'package.json')); -} catch (ex) {} - -const pkgPresets = pathOr([], ['neutrino', 'presets'], pkg); -const environments = { build: 'production', start: 'development', test: 'test' }; const args = yargs .option('inspect', { description: 'Output a string representation of the configuration used by Neutrino and exit', @@ -55,13 +47,17 @@ const args = yargs .help() .argv; -function run(command, presets) { - process.env.NODE_ENV = environments[command]; - +function run(command, args) { + const environments = { build: 'production', start: 'development', test: 'test' }; + const pkg = optional(join(process.cwd(), 'package.json')) || {}; + const pkgPresets = pathOr([], ['neutrino', 'presets'], pkg); + const presets = [...new Set(pkgPresets.concat(args.presets))]; const options = pathOr({}, ['neutrino', 'options'], pkg); const config = pathOr({}, ['neutrino', 'config'], pkg); const api = new Neutrino(Object.assign(options, { config })); + process.env.NODE_ENV = environments[command]; + // Grab all presets and merge them into a single webpack-chain config instance api.import(presets); @@ -83,4 +79,4 @@ function run(command, presets) { }); } -run(args._[0], [...new Set(pkgPresets.concat(args.presets))]); +run(args._[0], args); diff --git a/packages/neutrino/package.json b/packages/neutrino/package.json index 9a65625..6f49f0e 100644 --- a/packages/neutrino/package.json +++ b/packages/neutrino/package.json @@ -25,6 +25,7 @@ "deep-sort-object": "^1.0.1", "deepmerge": "^1.3.2", "javascript-stringify": "^1.6.0", + "optional": "^0.1.3", "ora": "^1.1.0", "ramda": "^0.23.0", "webpack": "^2.2.1",