Skip to content

Instantly share code, notes, and snippets.

@pajtai
Created December 2, 2013 04:29
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 pajtai/7745107 to your computer and use it in GitHub Desktop.
Save pajtai/7745107 to your computer and use it in GitHub Desktop.
Load all grunt tasks and load grunt config from a directory and set of files
loadGruntConfigAndDependencies('./initConfig/');
function loadGruntConfigAndDependencies (files) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig(loadConfig(files));
}
function loadConfig(files) {
var path = require('path'),
object = {};
grunt.file.recurse(files, function callback(abspath, rootdir, subdir, filename) {
var name = path.basename(filename, path.extname(filename)),
required = require(path.resolve('.', abspath));
if (_.isFunction(required)) {
required = required(grunt);
}
object[name] = required;
});
return object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment