grunt
grunt copied to clipboard
allow the specification of a callback in Task#run
An attempt at https://github.com/gruntjs/grunt/issues/1184, really it just pulls out a callback from the run function and uses it for done(). The issue is old and I didn't see an official response so I thought I would take a stab at it.
+1 this.
I rarely need to use the callback function, but on certain complex projects it's necessary. Anyone wanting to use this without overwriting the source can use this prototype:
grunt.util.task.Task.prototype.run = function () {
if (typeof(arguments[arguments.length - 1]) === 'function') {
this._options.done = arguments[arguments.length - 1];
delete arguments[arguments.length - 1];
}
var things = this.parseArgs(arguments).map(this._taskPlusArgs, this);
var fails = things.filter(function(thing) { return !thing.task; });
if (fails.length > 0) {
this._throwIfRunning(new Error('Task "' + fails[0].nameArgs + '" not found.'));
return this;
}
this._push(things);
return this;
}