forked from vicegold/web-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
40 lines (31 loc) · 1.03 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
37
38
39
40
'use strict';
// get project configuration
let config = require('./project.json');
// check each config property for references to solve
let walk = (input) => {
for (let key in input) {
// ignore value as it's useless for us
if (input.hasOwnProperty(key) === false || input[key] === null) {
continue;
}
// another object, digg deeper
if (typeof input[key] === 'object') {
input[key] = walk(input[key]);
continue;
}
// not a string, nor a self-reference found
if (typeof input[key] !== 'string' || input[key].indexOf('@this.') < 0) {
continue;
}
// replace reference with the value of the actual config entry
input[key] = input[key].replace(/@this\.([\w\.]+)/, (match, option) =>
option.split('.').reduce(
(previous, current) => previous[current],
config
)
);
}
return input;
}
// export config
module.exports = walk(config || {});