Skip to content

Commit

Permalink
Fix: Environment variables overwritten by lux CLI (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
adampash authored Aug 15, 2016
1 parent 9868b3d commit 6501ad0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bin/lux
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ function commandNotFound(cmd) {
console.log(` Use ${green('lux --help')} for a full list of commands${EOL}`);
}

function setEnvVar(key, val, def) {
if (val) {
Reflect.set(process.env, key, val);
} else if (!Reflect.has(process.env, key)) {
Reflect.set(process.env, key, def);
}
}

function exec(cmd, ...args) {
let handler;

Expand Down Expand Up @@ -119,11 +127,11 @@ cli
.command('c')
.alias('console')
.description('Load your application into a repl')
.option('-e, --environment [env]', '(Default: development)', 'development')
.option('-e, --environment [env]', '(Default: development)')
.option('-w, --use-weak', 'Use weak mode')
.action(({ environment, useWeak }) => {
process.env.PORT = 4000;
process.env.NODE_ENV = environment;
setEnvVar('PORT', port, 4000);
setEnvVar('NODE_ENV', environment, 'development');
process.env.LUX_CONSOLE = true;

exec('build', !useWeak)
Expand All @@ -136,16 +144,16 @@ cli
.command('s')
.alias('serve')
.description('Serve your application')
.option('-e, --environment [env]', '(Default: development)', 'development')
.option('-e, --environment [env]', '(Default: development)')
.option('-p, --port [port]', '(Default: 4000)', parseInt)
.option('-c, --cluster', 'Run in cluster mode')
.option('-H, --hot', 'Reload when a file change is detected')
.option('-w, --use-weak', 'Use weak mode')
.action(({ hot, port, cluster, environment, useWeak }) => {
const useStrict = !useWeak;

process.env.PORT = port;
process.env.NODE_ENV = environment;
setEnvVar('PORT', port, 4000);
setEnvVar('NODE_ENV', environment, 'development');

exec('build', useStrict)
.then(() => exec('serve', { hot, cluster, useStrict }))
Expand Down

0 comments on commit 6501ad0

Please sign in to comment.