-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
32 lines (28 loc) · 874 Bytes
/
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
var fs = require('fs');
var Q = require('q');
var resolve = function resolve(value) {
var recur = function(node, resolvedNode) {
for (var prop in node) {
if (node.hasOwnProperty(prop)) {
resolvedNode[prop] = resolve(node[prop]);
}
}
return resolvedNode;
}
if (typeof(value) == 'string' && value.length && value[0] === '$') {
return process.env[value.substr(1)];
} else if (typeof(value) == 'object') {
return recur(value, Array.isArray(value) ? [] : {});
} else {
return value;
}
}
module.exports.load = function(path) {
if (!path) {
return Q.reject('Please specify a config file, e.g. `hypermeter my-config.json`');
}
return Q.nfcall(fs.realpath, path)
.then(function(realpath) {
return resolve(require(realpath));
});
}