Andreas Köberle
Andreas Köberle

Reputation: 110922

Pass params to an grunt task from an alias task

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?

Upvotes: 10

Views: 4669

Answers (1)

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

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

Upvotes: 20

Related Questions