Allow watch task to be renamed. Closes GH-16.

This commit is contained in:
Kyle Robinson Young 2012-11-19 12:45:45 -08:00
parent d9880aa6bc
commit 4d76707d27

View File

@ -26,15 +26,16 @@ module.exports = function(grunt) {
}; };
grunt.registerTask('watch', 'Run predefined tasks whenever watched files change.', function(target) { grunt.registerTask('watch', 'Run predefined tasks whenever watched files change.', function(target) {
this.requiresConfig('watch'); var name = this.name || 'watch';
this.requiresConfig(name);
// Build an array of files/tasks objects // Build an array of files/tasks objects
var watch = grunt.config('watch'); var watch = grunt.config(name);
var targets = target ? [target] : Object.keys(watch).filter(function(key) { var targets = target ? [target] : Object.keys(watch).filter(function(key) {
return typeof watch[key] !== 'string' && !Array.isArray(watch[key]); return typeof watch[key] !== 'string' && !Array.isArray(watch[key]);
}); });
targets = targets.map(function(target) { targets = targets.map(function(target) {
// Fail if any required config properties have been omitted // Fail if any required config properties have been omitted
target = ['watch', target]; target = [name, target];
this.requiresConfig(target.concat('files'), target.concat('tasks')); this.requiresConfig(target.concat('files'), target.concat('tasks'));
return grunt.config(target); return grunt.config(target);
}, this); }, this);