13

This is currently possible:

ember build --environment=production

... and I would like to do something like this instead:

ember build --environment=production --baseurl=foo

but config/environment.js only gets passed in the value of environment.

Is it possible to get the value of the other options passed in at the command line too?

bguiz
  • 27,371
  • 47
  • 154
  • 243

4 Answers4

9

You could set environment variables the old fashioned way (export WHATEVER=wee) from terminal or as part of a build script, then reference them in your Brocfile.js via node with process.env.WHATEVER. After that, it would be a matter of having broccoli do whatever it is you needed to do with them. You could pre-process files and replace strings, for example.

... just a suggestion. Not sure if that's what you're looking for or not.

Ben Lesh
  • 107,825
  • 47
  • 247
  • 232
  • 1
    @ Ben Lesh thanks for the answer. That was indeed how I solved the problem (before asking the question even). +1 and check to you! ... I just wanted to know if ember-cli allowed additional parameters/ arguments. – bguiz Jul 07 '14 at 11:53
  • is it possible to run something like **ember server --environment=test** – SuperUberDuper Jan 07 '15 at 09:49
  • You can also access any environment variable directly in your environment.js with process.env.VARNAME – Mike Darmetko Jan 12 '17 at 22:55
7

It appears that this is not allowed:

Looking in node_modules/ember-cli/lib/commands/build.js, we see:

availableOptions: [
  { name: 'environment', type: String, default: 'development' },
  { name: 'output-path', type: path, default: 'dist/' }
],

... and in node_modules/ember-cli/lib/models/command.js

this.availableOptions.forEach(function(option) {
  knownOpts[option.name] = option.type;
});

... which together mean that any options that are not defined, for each subcommand of ember, get discarded.

bguiz
  • 27,371
  • 47
  • 154
  • 243
1

You can do foo=bar ember build (however doing ember build foo=bar doesn't work)

And the argument is available via process.env.foo.

Hillboy
  • 472
  • 6
  • 19
1

To extend upon @ben's answer.

The raw command line arguments are available inside ember-cli-build.js and other files from the

process.argv.[]

So a command like this

ember build staging

you can access via:

process.argv.includes('staging')

see node's documentation for whats available.

https://nodejs.org/docs/latest/api/process.html

Chris Rice
  • 728
  • 2
  • 9
  • 32