diff options
author | Garren Smith <garren.smith@gmail.com> | 2013-03-18 10:48:12 +0200 |
---|---|---|
committer | Garren Smith <garren.smith@gmail.com> | 2013-03-18 10:50:41 +0200 |
commit | 3a948a836b9460039032f6099dd49d004d2de030 (patch) | |
tree | f8e4a420df2a11418b858439f718170541ec0c65 | |
parent | 2172a0b3f62be19157e30204b6b197fc8e228963 (diff) | |
download | couchdb-1707-feature-override-couchapp-settings.tar.gz |
create grunt helper file, reach couch_config from settings file for use default. COUCHDB-17071707-feature-override-couchapp-settings
-rw-r--r-- | src/fauxton/grunt.js | 51 | ||||
-rw-r--r-- | src/fauxton/settings.json.default | 34 | ||||
-rw-r--r-- | src/fauxton/tasks/helper.js | 20 |
3 files changed, 65 insertions, 40 deletions
diff --git a/src/fauxton/grunt.js b/src/fauxton/grunt.js index 875316b50..e87f4247f 100644 --- a/src/fauxton/grunt.js +++ b/src/fauxton/grunt.js @@ -2,31 +2,26 @@ // configuration file, which you can learn more about here: // https://github.com/cowboy/grunt/blob/master/docs/configuring.md + module.exports = function(grunt) { - var path = require('path'); - var couch_config = { - fauxton: { - db: 'http://localhost:5984/fauxton', - app: './couchapp.js', - options: { - okay_if_missing: true - } - } - }; - - function readSettingsFile () { - if (path.existsSync("settings.json")) { - return grunt.file.readJSON("settings.json") - } else if (path.existsSync("settings.json.default")) { - return grunt.file.readJSON("settings.json.default") - } else { - return {deps: []}; - } - } - - function processAddons(callback){ - readSettingsFile().deps.forEach(callback); - } + var helper = require('./tasks/helper').init(grunt), + path = require('path'); + + var couch_config = function () { + + var default_couch_config = { + fauxton: { + db: 'http://localhost:5984/fauxton', + app: './couchapp.js', + options: { + okay_if_missing: true + } + } + }; + + var settings_couch_config = helper.readSettingsFile().couch_config; + return settings_couch_config || default_couch_config + }(); var cleanable = function(){ // Whitelist files and directories to be cleaned @@ -34,7 +29,7 @@ module.exports = function(grunt) { // You'll always want to clean these two directories var theListToClean = ["dist/", "app/load_addons.js"]; // Now find the external addons you have and add them for cleaning up - processAddons(function(addon){ + helper.processAddons(function(addon){ // Only clean addons that are included from a local dir if (addon.path){ theListToClean.push("app/addons/" + addon.name); @@ -54,7 +49,7 @@ module.exports = function(grunt) { }, img: ["assets/img/**"] }; - processAddons(function(addon){ + helper.processAddons(function(addon){ // Less files from addons var root = addon.path || "app/addons/" + addon.name; var lessPath = root + "/assets/less"; @@ -62,7 +57,7 @@ module.exports = function(grunt) { // .less files exist for this addon theAssets.less.paths.push(lessPath); theAssets.less.files["dist/debug/css/" + addon.name + ".css"] = - lessPath + "/" + addon.name + ".less"; + lessPath + "/" + addon.name + ".less"; } // Images var root = addon.path || "app/addons/" + addon.name; @@ -85,7 +80,7 @@ module.exports = function(grunt) { "base": null } }; - var settings = readSettingsFile(); + var settings = helper.readSettingsFile(); return {template: settings.template || defaultSettings}; }(); diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default index 32cd774b5..b4c0dbcfe 100644 --- a/src/fauxton/settings.json.default +++ b/src/fauxton/settings.json.default @@ -1,17 +1,27 @@ { "deps": [ - { "name": "config" }, - { "name": "logs" }, - { "name": "stats" }, - { "name": "contribute" } + { "name": "config" }, + { "name": "logs" }, + { "name": "stats" }, + { "name": "contribute" } ], - "template": { - "src": "assets/index.underscore", - "dest": "dist/debug/index.html", - "variables": { - "assets_root": "./", - "requirejs": "require.js", - "base": null + "template": { + "src": "assets/index.underscore", + "dest": "dist/debug/index.html", + "variables": { + "assets_root": "./", + "requirejs": "require.js", + "base": null + } + }, + + "couch_config": { + "fauxton": { + "db": "http://localhost:5984/fauxton", + "app": "./couchapp.js", + "options": { + "okay_if_missing": true + } + } } - } } diff --git a/src/fauxton/tasks/helper.js b/src/fauxton/tasks/helper.js new file mode 100644 index 000000000..f0a73718c --- /dev/null +++ b/src/fauxton/tasks/helper.js @@ -0,0 +1,20 @@ +var fs = require('fs'); + +exports.init = function(grunt) { + + return { + readSettingsFile: function () { + if (fs.existsSync("settings.json")) { + return grunt.file.readJSON("settings.json") + } else if (fs.existsSync("settings.json.default")) { + return grunt.file.readJSON("settings.json.default") + } else { + return {deps: []}; + } + }, + + processAddons: function (callback) { + this.readSettingsFile().deps.forEach(callback); + }, + }; +} |