Last active
April 13, 2016 16:39
-
-
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"
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
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