Skip to content

Instantly share code, notes, and snippets.

@theaccordance
Last active April 13, 2016 16:39
Show Gist options
  • Save theaccordance/4a4aecad222f4008abf8a1bd7867d049 to your computer and use it in GitHub Desktop.
Save theaccordance/4a4aecad222f4008abf8a1bd7867d049 to your computer and use it in GitHub Desktop.
A modular gruntfile, loading json files containing task configurations from plugins from the file path "grunt/configs"
module.exports = function (grunt) {
function loadConfig(pattern) {
var config = {},
fileName,
fileData;
grunt.file.expand(pattern).forEach(function(filePath) {
fileName = filePath.split('/').pop().split('.')[0];
fileData = grunt.file.readJSON(filepath);
config[fileName] = fileData[fileName];
});
return config;
}
function init() {
var config = {
pkg: grunt.file.readJSON('package.json')
};
require('load-grunt-tasks')(grunt);
if (grunt.file.exists('grunt/tasks')) {
grunt.log.writeln('task directory found, loading tasks...');
grunt.loadTasks('grunt/tasks');
}
grunt.util._.extend(config, loadConfig('grunt/configs/**/*.js'));
grunt.initConfig(config);
}
init();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment