Last active
January 12, 2016 15:19
-
-
Save neagle/83d21c542f49daa47fdb to your computer and use it in GitHub Desktop.
A simple custom Grunt task to build a group of targets for a task based on a prefix. This allows for easy grouping, based on namespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Build a group of targets based on a prefix | |
* | |
* Ex: grunt build:less:debug | |
* | |
* This would run all less targets that begin with "debug_": | |
* debug_web | |
* debug_sidebar | |
* debug_self_help | |
* debug_self_help_theme | |
* ... | |
*/ | |
module.exports = function (grunt) { | |
grunt.registerTask( | |
'build', | |
'Build a set of targets for a given task based on a prefix.', | |
function (task, prefix) { | |
// Make sure the prefix ends with a delimiter to prevent accidental matches | |
// of larger words. We don't want "dist" to match "distribution_" | |
prefix += '_'; | |
var targets = Object.keys(grunt.config(task)); | |
var buildTargets = targets.filter(function (target) { | |
return target.substring(0, prefix.length) === prefix; | |
}); | |
grunt.task.run(buildTargets.map(function (target) { | |
return task + ':' + target; | |
})); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment