Grunt task setting options?

1

I want to set up a task where I can set 2 parameters and not have to set them in the console every time I call it.

This is what I run on the console:

grunt serve:proxy --proxyServer=8.8.8.8 --proxyPort=9999

And these are the tasks that I have tried to declare but none of them works:

grunt.registerTask('serve:dev', 'serve:proxy:proxyServer=8.8.8.8:proxyPort=9999');

grunt.registerTask('serve:dev_', '', function(obj){

    console.log ( grunt.config ('proxyServer')); //undefine
    console.log ( grunt.option ('proxyServer')); //undefine

    grunt.option('proxyServer', '8.8.8.8');
    grunt.option('proxyPort', 9999);

    console.log ( grunt.config ('proxyServer')); //undefine
    console.log ( grunt.option ('proxyServer')); //8.8.8.8

    grunt.task.run('serve:proxy');
});

In the log you can see that it always keeps the default configuration:

Proxy created for: /my_path to localhost:3000
Proxy created for: /my_path to localhost:3000
Proxy created for: /my_path to localhost:3000
Proxy created for: /my_path to localhost:3000
    
asked by Zawarudo 21.07.2017 в 10:14
source

1 answer

0

Finally I found a solution, I was storing the parameters in the wrong place, the correct thing is:

  grunt.registerTask('serve:proxy:dev', 'proxy to dev', function (){

//   grunt serve:proxy --proxyServer=8.8.8.8 --proxyPort=9999
    grunt.config.set('config.proxyServer', '8.8.8.8');
    grunt.config.set('config.proxyPort', '9999');
    grunt.task.run('serve:proxy');


  });

The parameters (proxyServer and proxyPort) were used with a grunt template (<% = config.proxyServer% > and <% = config.proxyPort% >).

Even if you set the parameters at the config level:     grunt.config ('proxyServer', '8.8.8.8');     grunt.config ('proxyPort', 9999);

Then they are used at the config.config level:

grunt.config.
             proxyServer: 8.8.8.8 <-- este no es 
             proxyPort: 9999      <-- este tampoco
             config.
                    proxyServer: 8.8.8.8 <-- ESTE SI 
                    proxyPort: 9999      <-- ESTE TAMBIEN

More information: link PS: I made a console.log (grunt.config) to see configuration object

    
answered by 28.07.2017 / 12:14
source