forked from FCoQ/dobby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
36 lines (31 loc) · 1.05 KB
/
config.js
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
var fs = require('fs'),
toml = require('toml'),
console = require('better-console');
// load the configuration file
exports.init = function(cb) {
fs.readFile("config.toml", function(err, config) {
if (err) {
console.error("Error reading configuration file: " + err);
} else {
config = toml.parse(config);
var new_config = {
_config: config,
get: function(field) {
var obj = this._config;
var prop, props = field.split('.');
for (var i = 0, iLen = props.length - 1; i < iLen; i++) {
prop = props[i];
var candidate = obj[prop];
if (candidate !== undefined) {
obj = candidate;
} else {
break;
}
}
return obj[props[i]];
}
};
cb(new_config);
}
})
}