Skip to content

Instantly share code, notes, and snippets.

@indieisaconcept
Created October 27, 2012 13:50
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 indieisaconcept/3964678 to your computer and use it in GitHub Desktop.
Save indieisaconcept/3964678 to your computer and use it in GitHub Desktop.
Load multiple grunt plugins by reading package.json
var loadPackageTasks = function (/* String */ prefix, /* Array */ tasks) {
prefix = prefix || 'grunt-';
tasks = tasks || grunt.file.readJSON('package.json') || [];
var prefixLen = prefix.length;
if (_.isObject(tasks)) {
tasks = tasks.devDependencies || tasks;
tasks = Object.keys(tasks);
}
// filter out tasks which do not meet the import
// criteria based on prefix defined
tasks.filter(function (/* String */ task) {
var match = task.substr(0, prefixLen) === prefix || false;
return match;
}).forEach(function (/* String */ task) {
grunt.loadNpmTasks(task);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment