-
Notifications
You must be signed in to change notification settings - Fork 23
/
set-env-vars.js
executable file
·36 lines (27 loc) · 1.09 KB
/
set-env-vars.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
#!/usr/bin/env node
const fs = require('fs');
let config = fs.readFileSync('config.js.example', 'utf8');
config = config.toString().replace('const config = ', '').replace(';', '');
// Replace ":" with "@colon@" if it's between double-quotes
config = config.replace(/:\s*"([^"]*)"/g, function(match, p1) {
return ': "' + p1.replace(/:/g, '@colon@') + '"';
});
// Replace ":" with "@colon@" if it's between single-quotes
config = config.replace(/:\s*'([^']*)'/g, function(match, p1) {
return ': "' + p1.replace(/:/g, '@colon@') + '"';
});
// Add double-quotes around any tokens before the remaining ":"
config = config.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?\s*:/g, '"$2": ');
// Turn "@colon@" back into ":"
config = config.replace(/@colon@/g, ':');
config = JSON.parse(config);
Object.keys(config).forEach(item => {
if (process.env[item]) {
if (item === 'PRIVACY_POLICY' || item === 'AVG_GAS_PRICE_ENABLED') {
config[item] = process.env[item] === 'true';
} else {
config[item] = process.env[item];
}
}
});
console.log('const config = ' + JSON.stringify(config, null, 2) + ';');