Skip to content

Instantly share code, notes, and snippets.

@codekipple
Created August 19, 2014 14:03
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 codekipple/cb29b8e5329a685509ee to your computer and use it in GitHub Desktop.
Save codekipple/cb29b8e5329a685509ee to your computer and use it in GitHub Desktop.
programatically building a grunt tasks options
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
var config = {
options: {
includePaths: [
'<%=wpThemeDir%>/<%= wpParentThemeDir %>/sass/partials/'
]
},
dist: {
files: []
}
};
var configs = [];
configs['all'] = JSON.parse(JSON.stringify(config));
for (var key in pkg.themes) {
var taskName = key;
var theme = pkg.themes[key];
// clone config object
configs[taskName] = JSON.parse(JSON.stringify(config));
configs[taskName].dist.files.push({
expand: true,
flatten: true,
ext: '.css',
src: '<%=wpThemeDir%>/' + theme + '/sass/*.scss',
dest: '<%=wpThemeDir%>/' + theme + '/css/'
});
// Add to the all task
configs['all'].dist.files.push(configs[taskName].dist.files);
};
grunt.registerTask('wired_sass', function(theme) {
if (arguments.length === 0) {
grunt.config('sass', configs['all']);
} else {
grunt.config('sass', configs[theme]);
}
grunt.task.run('sass');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment