From 4b014a86de99629facfaa2dd0ee26e7b51423c93 Mon Sep 17 00:00:00 2001 From: Chris Butler Date: Sun, 16 Aug 2015 14:26:24 -0400 Subject: [PATCH] more robust parsing for iron run #140 #175 --- lib/commands/run.js | 31 ++++++++++++++++++++++++------- lib/iron.js | 7 ++++++- package.json | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/commands/run.js b/lib/commands/run.js index 909f947..e4a9f3a 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -3,6 +3,7 @@ var fs = require('fs'); var spawn = require('child_process').spawn; var source = require('shell-source'); var Future = require('fibers/future'); +var _ = require('underscore'); var syncSource = function (filepath) { var future = new Future; @@ -15,17 +16,27 @@ Command.create({ usage: 'iron run [--use-build] [--env]', description: 'Run your app for a given environment.' }, function (args, opts) { - var appEnv = opts.env || process.env.NODE_ENV || 'development'; - if (!this.findProjectDirectory()) throw new Command.MustBeInProjectError; - var configPath = this.pathFromProject('config', appEnv); - var envPath = path.join(configPath, 'env.sh'); - var settingsPath = path.join(configPath, 'settings.json'); + var appEnv = process.env.NODE_ENV || 'development', + configPath = this.pathFromProject('config', appEnv), + envPath = path.join(configPath, 'env.sh'), + settingsPath; - // source the env file into the process environment + if (opts.env) { + appEnv = opts.env; + configPath = this.pathFromProject('config', appEnv); + } + + // allow settings override + if (opts.settings) { + settingsPath = opts.settings; + } else { + settingsPath = path.join(configPath, 'settings.json'); + } + // source the env file into the process environment if (this.isFile(envPath)) { syncSource(envPath); } @@ -37,5 +48,11 @@ Command.create({ ]); } - return this.invokeMeteorCommand('run', args.concat(process.argv.slice(3))); + // remove run and any platforms + var r = args.concat(_.without(process.argv.slice(2), 'run', args[0])); + + // don't pass --env to meteor + r = _.without(r, appEnv, '--env'); + + return this.invokeMeteorCommand('run', r); }); diff --git a/lib/iron.js b/lib/iron.js index 66a740a..7d09696 100644 --- a/lib/iron.js +++ b/lib/iron.js @@ -60,7 +60,12 @@ Iron = new Command({ console.log(table.toString()); } }, function (args, opts) { - var command = args[0] || 'run'; + var command = 'run'; + if (args[0]) { + command = args[0]; + } else { + args[0] = command; + } if (this.findSubCommand(command)) { return this.runSubCommand(command, args.slice(1), opts); diff --git a/package.json b/package.json index e7a0ee5..1640570 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "dependencies": { "cli-color": "0.2.3", "minimist": "0.0.8", - "underscore": "1.3.3", + "underscore": "1.8.3", "cli-table": "0.3.0", "ejs": "0.8.5", "fibers": "1.0.6",