Skip to content

Instantly share code, notes, and snippets.

@neagle
Last active January 12, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neagle/83d21c542f49daa47fdb to your computer and use it in GitHub Desktop.
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.
/**
* 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