Created
October 27, 2012 13:50
-
-
Save indieisaconcept/3964678 to your computer and use it in GitHub Desktop.
Load multiple grunt plugins by reading package.json
This file contains 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
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