-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.js
More file actions
47 lines (39 loc) · 1.23 KB
/
settings.js
File metadata and controls
47 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var fs = require('fs');
try {
var settings = JSON.parse(fs.readFileSync('settings.json'));
} catch (err) {
console.log(' Error parsing settings.json: ' + err.message);
console.log('\n');
process.exit(0);
}
var mode;
var init = function(overrides) {
mode = overrides.mode;
delete overrides.mode;
// Load the defaults from the settings
for (var i in settings.default) if (settings.default.hasOwnProperty(i))
exports[i] = settings.default[i];
// Look for the mode in settings, and if it's there load in the data.
if (mode in settings) {
var lsettings = settings[mode];
// Otherwise, try loading the file
} else {
try {
var lsettings = JSON.parse(fs.readFileSync(mode));
} catch (err) {
console.log(' Unable to load settings file ' + mode);
console.log(' Details: ' + err.message);
console.log('');
process.exit(0);
}
}
// Merge the local settings in
for (var i in lsettings) if (lsettings.hasOwnProperty(i))
exports[i] = lsettings[i];
// Copy overrides into settings
for (var i in overrides) if (overrides.hasOwnProperty(i))
if (overrides[i] !== null)
exports[i] = overrides[i];
};
exports.init = init;
exports.getMode = function() { return mode };