J
J
JimmyLee2015-01-03 16:20:39
JavaScript
JimmyLee, 2015-01-03 16:20:39

Which gulp plugin can accept variable values ​​from the console?

For example, we write in the console like this:
win/linux/[email protected]$ gulp taskname a=100 b=hello
And in the gulpfile.js task, we were able to fill the corresponding variables with these values. Thank you!
Thanks for the replies, the solution is:
gulpfile.js:
gulp.task('arg', function ()
{
var args = require('yargs').argv;
if(args.a) {
console.log('a = %d ', args.a);
}
else {
console.log('variable "a" not found');
}
})
console:
gulp arg -a=111
[17:35:00] Using gulpfile D:\gulp\gulpfile .js
[17:35:00] Starting 'arg'...
a = 111
[17:35:00] Finished 'arg' after 111 ms
-------------------------------------------------- ---------------------------------
It was also noticed that when using the gulp-load plugin -plugins
nothing works:
var gulp = require('gulp'), glp = require('gulp-load-plugins'), $ = glp();
gulp.task('arg', function ()
{
var args = $.yargs.argv;
if(args.a)
{
console.log('a = %d', args.a);
}
else
{
console.log ('variable "a" not found');
}
});
> gulp arg -a=111
[17:38:48] Using gulpfile D:\gulp\gulpfile.js
[17:38:48] Starting 'arg'...
[17:38:48] 'arg' errored after 788µs
[17:38:48] TypeError: Cannot read property 'argv' of undefined

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sanex3339, 2015-01-03
@sanex3339

https://www.npmjs.com/package/yargs

S
Sergey Nalomenko, 2015-01-03
@nalomenko

With Yargs . A similar question was once discussed on StackOverflow

J
JimmiLee, 2015-01-03
@JimmiLee

Thank you, I didn’t even think that there would be a solution so quickly))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question