Skip to content

Commit

Permalink
create grunt helper file, reach couch_config from settings file for u…
Browse files Browse the repository at this point in the history
…se default. COUCHDB-1707
  • Loading branch information
garrensmith committed Mar 18, 2013
1 parent 2172a0b commit 3a948a8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 40 deletions.
51 changes: 23 additions & 28 deletions src/fauxton/grunt.js
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -85,7 +80,7 @@ module.exports = function(grunt) {
"base": null
}
};
var settings = readSettingsFile();
var settings = helper.readSettingsFile();
return {template: settings.template || defaultSettings};
}();

Expand Down
34 changes: 22 additions & 12 deletions 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
}
}
}
}
}
20 changes: 20 additions & 0 deletions 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.