Skip to content

Instantly share code, notes, and snippets.

@thomasyip
Last active August 29, 2015 14:14
Show Gist options
  • Save thomasyip/67ceba91dc58c7fe3925 to your computer and use it in GitHub Desktop.
Save thomasyip/67ceba91dc58c7fe3925 to your computer and use it in GitHub Desktop.
Grunt Multi Task: configmerge
module.exports = function(grunt) {
grunt.initConfig({
compass: {
// see configmerge.compass
},
watch: {
// see configmerge.watch
}
configmerge: {
compass: {
'params' : ['folder1', 'folder2', 'folder3'],
'template': {
'files': [{ 'src': '*.scss', 'expand': false}],
'options': {
'sassDir': '<%= dirs.src %>/{%= param %}/sass',
'cssDir': '<%= dirs.src %>/{%= param %}/css'
}
}
},
watch: {
'params' : ['folder1', 'folder2', 'folder3'],
'template': {
files: ['<%= dirs.src %>/{%= param %}/sass/*.scss', '!.*', '!.**/*'],
tasks: ['compass:{%= param %}'],
options: {
livereload: true
}
},
}
},
});
grunt.registerMultiTask('configmerge', "Merge parametrized config", function() {
var params = this.data['params'],
template = this.data['template'],
param, i, replaced, task;
if (typeof template !== 'string') {
template = JSON.stringify(template);
}
grunt.template.addDelimiters('curly', '{%', '%}');
task = grunt.config.get(this.target)
for (i in params) {
param = params[i];
replaced = grunt.template.process(template, {
data: {param: param},
delimiters: 'curly'}
);
task[param] = JSON.parse(replaced);
grunt.config.set(this.target, task);
}
});
grunt.task.run('configmerge');
require('load-grunt-tasks')(grunt);
grunt.registerTask('main', ['compass', 'coffee']);
grunt.registerTask('default', ['watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment