Skip to content

Commit

Permalink
chore(*) add process.env.ENV support to gulp tasks
Browse files Browse the repository at this point in the history
On any gulp task:
* if no --env flag passed, environment variable ENV is taken
* if none of them is set, 'dev' is set by default
* if you pass by --env flag, it will be reflected in process.env.ENV
  • Loading branch information
topheman committed Aug 23, 2015
1 parent 7e55ca4 commit 8147d55
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions gulp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export const OPEN = util.env.open === 'false' ? false : true;
//launch your task with `--disable-watch` for example
export const DISABLE_WATCH = util.env['disable-watch'];

var environment = (util.env.env || 'dev').toLowerCase();
if (environment === true) {
environment = 'dev';
}
else if (['dev', 'prod', 'test'].indexOf(environment) === -1) {
// if no --env flag, environment variable ENV is taken,
// if none of them is set, 'dev' is set by default
// if you pass by --env flag, it will be reflected in process.env.ENV
var environment = ((util.env.env === true ? 'dev' : util.env.env) || process.env.ENV || 'dev').toLowerCase();
if (['dev', 'prod', 'test'].indexOf(environment) === -1) {
throw new Error('--env flag only accepts dev/prod/test')
}
if(!process.env.ENV){
LOG(COLORS.yellow('[INFOS] Setting process.env.ENV=' + environment));
process.env.ENV = environment;
}
LOG(COLORS.yellow('### Running in ' + environment + ' ###'));

export const ENV = environment;

0 comments on commit 8147d55

Please sign in to comment.