UNPKG

grunt-pretasks

Version:
37 lines (32 loc) 1.15 kB
'use strict'; module.exports = function (grunt) { function queuePreTasks(things) { things.forEach(function (thing) { var taskConfig = grunt.config()[thing.task.name]; if (!taskConfig || !taskConfig.options) return; var taskOptions = taskConfig.options; if ('preTasks' in taskOptions) { var preTasks = taskOptions.preTasks; grunt.task.run(preTasks); } }); } // overrides Task.prototype.run so we can queue options.preTasks grunt.util.task.Task.prototype.run = function () { // Parse arguments into an array, returning an array of task+args objects. var things = this.parseArgs(arguments).map(this._taskPlusArgs, this); // Throw an exception if any tasks weren't found. 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; } // Append pre things to queue queuePreTasks(things); // Append things to queue in the correct spot. this._push(things); // Make chainable! return this; } };