Created
November 14, 2014 16:58
This small piece of NodeJS code allows you to split in files the Grunt task file. I wrote this because mine was too big, much better to have small files.
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
--------------------------------------------------------------- | |
Splitr.js | |
--------------------------------------------------------------- | |
var json = { | |
watch: { | |
js: { | |
files: ['<%= yeoman.app %>/scripts/{,*/}*.js', '<%= yeoman.common %>/js/{,*/}*.js'], | |
tasks: ['concat'] | |
}, | |
compass: { | |
.... | |
}, | |
..... | |
}, ....... | |
}; | |
var fs = require('fs'); | |
for (var i in json) | |
{ | |
var buffer = JSON.stringify(json[i], null, 4); | |
buffer = buffer.replace(/\"([^(\")"]+)\":/g,"$1:"); | |
buffer = 'module.exports = ' + buffer + ';'; | |
fs.writeFileSync('./grunt/' + i + '.js', buffer); | |
} | |
--------------------------------------------------------------- | |
Gruntfile.js (need to import blod in your package.json file) | |
--------------------------------------------------------------- | |
'use strict'; | |
module.exports = function (grunt) | |
{ | |
require('load-grunt-tasks')(grunt); | |
var gruntConfig = { | |
pkg: grunt.file.readJSON('package.json') | |
}; | |
grunt.util._.extend(gruntConfig, loadConfig('./grunt/')); | |
grunt.initConfig(gruntConfig); | |
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) { | |
... | |
}); | |
}; | |
function loadConfig(path) { | |
var glob = require('glob'); | |
var object = {}; | |
var key; | |
glob.sync('*', {cwd: path}).forEach(function(option) { | |
key = option.replace(/\.js$/,''); | |
object[key] = require(path + option); | |
}); | |
return object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment