Skip to content
Browse files

create grunt helper file, reach couch_config from settings file for u…

…se default. COUCHDB-1707
  • Loading branch information...
1 parent 2172a0b commit 3a948a836b9460039032f6099dd49d004d2de030 @garrensmith garrensmith committed Mar 18, 2013
Showing with 65 additions and 40 deletions.
  1. +23 −28 src/fauxton/grunt.js
  2. +22 −12 src/fauxton/settings.json.default
  3. +20 −0 src/fauxton/tasks/helper.js
View
51 src/fauxton/grunt.js
@@ -2,39 +2,34 @@
// 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
// 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,15 +49,15 @@ 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";
if(path.existsSync(lessPath)){
// .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};
}();
View
34 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
+ }
+ }
}
- }
}
View
20 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);
+ },
+ };
+}

0 comments on commit 3a948a8

Please sign in to comment.
Something went wrong with that request. Please try again.