Skip to content

Commit

Permalink
Merge pull request #6 from incandescent/mbt-task-cfg
Browse files Browse the repository at this point in the history
User-defined config
  • Loading branch information
mkuklis committed Jun 20, 2012
2 parents f60f94a + e769ddc commit 51690dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions tasks/init/project/root/grunt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var fs = require('fs');
var extend = require('node.extend');
var path = require('path');

module.exports = function (grunt) {

// load js paths
var cfgPath = "tasks/cfg";
var jsFiles = require('./app/js/files.js').map(function (file) {
if (file == "js/config/envs/dev.js") {
file = "js/config/envs/prod.js";
Expand All @@ -10,7 +15,7 @@ module.exports = function (grunt) {

jsFiles.unshift('phonegap/iphone/www/cordova-1.7.0.js');

grunt.initConfig({
var cfg = {
js: {
files: jsFiles
},
Expand Down Expand Up @@ -121,7 +126,18 @@ module.exports = function (grunt) {
release: {
"app/assets/app.js": '<config:js.files>'
}
});
};

// deep-merge user configs
if (path.existsSync(cfgPath)) {
grunt.utils._.each(fs.readdirSync(cfgPath), function(cfg_file) {
if (cfg_file.match(/.*\.json$/)) {
extend(true, cfg, JSON.parse(fs.readFileSync(cfgPath + '/' + cfg_file)));
}
});
}

grunt.initConfig(cfg);

// Load local tasks
grunt.loadTasks("tasks");
Expand Down
3 changes: 2 additions & 1 deletion tasks/init/project/root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"grunt": "0.3.9",
"grunt-jasmine-task": "latest",
"html-minifier": "latest",
"clean-css": "0.3.2"
"clean-css": "0.3.2",
"node.extend": "latest"
},
"keywords": [],
"engines": {
Expand Down
1 change: 1 addition & 0 deletions tasks/init/project/root/tasks/cfg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Force git to check in this dir

0 comments on commit 51690dd

Please sign in to comment.