2

I am using gulp and gulp-shell packages for a php Laravel application, I just need to know if this is possible to pass argument from cmd to gulpfile.js ? this is my file:

 gulp.task('default',  shell.task([  
   'echo user',    
  ]));

Question: Is it possible to pass an argument from command-line when running gulp and then inside the gulpfile print it out instead of user?

Siavosh
  • 2,136
  • 4
  • 20
  • 44
  • 1
    Take a look at this question: http://stackoverflow.com/questions/23023650/is-it-possible-to-pass-a-flag-to-gulp-to-have-it-run-tasks-in-different-ways. You seem to be able to do that with [yargs](https://www.npmjs.com/package/yargs). This was posted as a comment because your question seems to be a duplicate. – Luís Cruz Feb 28 '15 at 19:58

1 Answers1

0

var command_line_args = require('yargs').argv

Not sure if this is of any use to you or others but I did this manually by passing the arguments explicitly through a custom function. It's not super elegant but it gets the job done.

var appendWithCommandLineArguments = function(cmd, arguments) {
    var to_append = _.chain(command_line_args)
        .pick(arguments)
        .reduce(function(string, val, prop){
            return string+"--"+prop+"="+val+" ";
        }, " ")
        .value();

    return cmd + to_append
}

gulp.task('taskmailer', shell.task([
    appendWithCommandLineArguments('node automate/build/mail/taskMailer.js', ["email", "template"])
]))
loujaybee
  • 96
  • 2
  • 6