Gulp JS File Automation

0

My question is as follows, I have a .js file in my code that contains a bunch of variables that only change their value.

Example:

var teste = "http://desenvolvimento.com.br";
var teste = "http://producao.com.br";

After running the gulp I would like to pass some parameters.

Example:

gulp producao
//var teste = "http://desenvolvimento.com.br";
var teste = "http://producao.com.br";

Basically when running the gulp production parameter or gulp development it automatically commented on the variables that have the different production notes.

    
asked by anonymous 04.07.2018 / 20:31

1 answer

0

There is a global that is available within the file .js which is process . This global has a process.argv key that contains the arguments used to start the command. An example would be:

For gulp producao the process.argv will be ['node', 'caminho/para/gulp.js', 'producao'] , if you pass more arguments elese will appear in that array.

So, in the specific case of producao position would be process.argv[2] , and what you want therefore will be:

const teste = process.argv[2] === 'producao' ? 'http://producao.com.br' : 'http://desenvolvimento.com.br';
    
04.07.2018 / 20:42