Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
begin adding settings for brush and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcLear committed Apr 29, 2015
1 parent 954384c commit e3f9a67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
3 changes: 3 additions & 0 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"dbSettings" : {
"filename" : "var/dirty.db"
}

/* The default selected tool - 'pencil', 'brush' */
"tool": "brush",

/* An Example of MySQL Configuration
"dbType" : "mysql",
Expand Down
61 changes: 32 additions & 29 deletions src/util/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,45 @@ exports.defaults = {
"dbSettings" : {
"filename" : "var/dirty.db"
},
"ssl": false
"ssl": false,
"tool": "brush",
};



exports.loadSettings = function() {
var settings_file = "settings.json";
var user_settings = {};
try {
user_settings = fs.readFileSync(settings_file).toString();
//minify to remove comments and whitepsace before parsing
user_settings = JSON.parse(JSON.minify(user_settings));
}
catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
}
var settings_file = "settings.json";
var user_settings = {};
try {
user_settings = fs.readFileSync(settings_file).toString();
//minify to remove comments and whitepsace before parsing
user_settings = JSON.parse(JSON.minify(user_settings));
}
catch(e){
console.error('There was an error processing your settings.json file: '+e.message);
process.exit(1);
}

//copy over defaults
for(var k in exports.defaults){exports[k] = exports.defaults[k]}
//go through each key in the user supplied settings and replace the defaults
//if a key is not in the defaults, warn the user and ignore it
for(var k in user_settings) {
if(k in exports.defaults){
//overwrite it
exports[k] = user_settings[k];
}
else
{
console.warn("'Unknown Setting: '" + k + "'. This setting doesn't exist or it was removed");
}
}
//settings specific warnings
if(exports.dbType === "dirty"){
console.warn("DirtyDB is used. This is fine for testing but not recommended for production.");
//copy over defaults
for(var k in exports.defaults){
exports[k] = exports.defaults[k]
}

//go through each key in the user supplied settings and replace the defaults
//if a key is not in the defaults, warn the user and ignore it
for(var k in user_settings) {
if(k in exports.defaults){
//overwrite it
exports[k] = user_settings[k];
}else{
console.warn("'Unknown Setting: '" + k + "'. This setting doesn't exist or it was removed");
}
}

//settings specific warnings
if(exports.dbType === "dirty"){
console.warn("DirtyDB is used. This is fine for testing but not recommended for production.");
}

};

Expand Down

0 comments on commit e3f9a67

Please sign in to comment.