Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass params to an grunt task from an alias task

Tags:

gruntjs

Is there a way to pass an argument from a alias task like this into on of the calling tasks:

grunt.registerTask('taskA', ['taskB', 'taskC'])

grunt taskA:test

so that task taskB and taskC will be called with the parameter test?

like image 254
Andreas Köberle Avatar asked Apr 26 '13 14:04

Andreas Köberle


1 Answers

You can create a dynamic alias task like this:

grunt.registerTask('taskA', function(target) {
  var tasks = ['taskB', 'taskC'];
  if (target == null) {
    grunt.warn('taskA target must be specified, like taskA:001.');
  }
  grunt.task.run.apply(grunt.task, tasks.map(function(task) {
    return task + ':' + target;
  }));
});

Here is the FAQ with another example in the Grunt docs: http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

like image 140
Kyle Robinson Young Avatar answered Oct 20 '22 17:10

Kyle Robinson Young