-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-config.js
40 lines (36 loc) · 1.17 KB
/
build-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';
const fs = require('fs');
const path = require('path');
const CONFIG_PATH = path.join('src', 'assets', 'config.json');
const THEME_NAME = process.env.THEME || 'base';
function updateConfig() {
let config = {};
if (fs.existsSync(CONFIG_PATH)) {
config = require('./' + CONFIG_PATH);
}
let result = {};
for (let k in config) {
let v = config[k];
result[k] = v.replace(/\$[A-Z_]+|\$\{.+?\}/g, found => {
found = found.substring(1);
if (found[0] === '{') {
found = found.substring(1, found.length - 1);
}
let foundval = '';
let splitPos = found.indexOf('-');
if (~splitPos) {
foundval = found.substring(splitPos + 1);
found = found.substring(0, splitPos);
}
if (found == 'THEME') {
foundval = THEME_NAME;
} else if (found in process.env && process.env[found] !== '') {
foundval = process.env[found];
}
return foundval;
});
}
fs.writeFileSync(CONFIG_PATH, JSON.stringify(result));
return result;
}
updateConfig();