Created
August 19, 2014 14:03
-
-
Save codekipple/cb29b8e5329a685509ee to your computer and use it in GitHub Desktop.
programatically building a grunt tasks options
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) { | |
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