commit
6b429b2ca1
|
@ -24,6 +24,7 @@ var os = require("os");
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var argv = require('./Cli').argv;
|
var argv = require('./Cli').argv;
|
||||||
var npm = require("npm/lib/npm.js");
|
var npm = require("npm/lib/npm.js");
|
||||||
|
var vm = require('vm');
|
||||||
|
|
||||||
/* Root path of the installation */
|
/* Root path of the installation */
|
||||||
exports.root = path.normalize(path.join(npm.dir, ".."));
|
exports.root = path.normalize(path.join(npm.dir, ".."));
|
||||||
|
@ -45,6 +46,7 @@ exports.dbType = "dirty";
|
||||||
* This setting is passed with dbType to ueberDB to set up the database
|
* This setting is passed with dbType to ueberDB to set up the database
|
||||||
*/
|
*/
|
||||||
exports.dbSettings = { "filename" : path.join(exports.root, "dirty.db") };
|
exports.dbSettings = { "filename" : path.join(exports.root, "dirty.db") };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default Text of a new pad
|
* The default Text of a new pad
|
||||||
*/
|
*/
|
||||||
|
@ -102,32 +104,24 @@ exports.abiwordAvailable = function()
|
||||||
|
|
||||||
// Discover where the settings file lives
|
// Discover where the settings file lives
|
||||||
var settingsFilename = argv.settings || "settings.json";
|
var settingsFilename = argv.settings || "settings.json";
|
||||||
if (settingsFilename.charAt(0) != '/') {
|
settingsFilename = path.resolve(path.join(root, settingsFilename));
|
||||||
settingsFilename = path.normalize(path.join(root, settingsFilename));
|
|
||||||
}
|
|
||||||
|
|
||||||
var settingsStr
|
var settingsStr;
|
||||||
try{
|
try{
|
||||||
//read the settings sync
|
//read the settings sync
|
||||||
settingsStr = fs.readFileSync(settingsFilename).toString();
|
settingsStr = fs.readFileSync(settingsFilename).toString();
|
||||||
} catch(e){
|
} catch(e){
|
||||||
console.warn('No settings file found. Using defaults.');
|
console.warn('No settings file found. Continuing using defaults!');
|
||||||
settingsStr = '{}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove all comments
|
|
||||||
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
|
|
||||||
|
|
||||||
//try to parse the settings
|
// try to parse the settings
|
||||||
var settings;
|
var settings;
|
||||||
try
|
try {
|
||||||
{
|
if(settingsStr) {
|
||||||
settings = JSON.parse(settingsStr);
|
settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
|
||||||
}
|
}
|
||||||
catch(e)
|
}catch(e){
|
||||||
{
|
console.error('There was an error processing your settings.json file: '+e.message);
|
||||||
console.error("There is a syntax error in your settings.json file");
|
|
||||||
console.error(e.message);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,8 +142,7 @@ for(var i in settings)
|
||||||
//this setting is unkown, output a warning and throw it away
|
//this setting is unkown, output a warning and throw it away
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.warn("Unkown Setting: '" + i + "'");
|
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
|
||||||
console.warn("This setting doesn't exist or it was removed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue