forked from Streampunk/beamengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
53 lines (43 loc) · 1.78 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
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Aerostat Beam Engine - Redis-backed highly-scale-able and cloud-fit media beam engine.
Copyright (C) 2019 Streampunk Media Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
https://www.streampunk.media/ mailto:[email protected]
14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
*/
const fs = require('fs');
const env = process.env.NODE_ENV || 'development';
let base = require(`./config/${env}.js`);
base.loaded = false;
function loadOverride() {
if (base.loaded === true) return base;
if (process.argv.length > 2) {
try {
let argConfig = fs.readFileSync(process.argv[2]);
let override = JSON.parse(argConfig);
Object.keys(base).forEach(x => { // merge at second level
Object.assign(base[x], override[x]);
});
Object.keys(base.rules ? base.rules : {})
.filter(x => base.rules[x] === null)
.forEach(x => { delete base.rules[x]; });
} catch (err) {
console.error(`Failed to open file ${process.argv[2]}: ${err.message}`);
}
}
base.loaded = true;
return base;
}
base.load = loadOverride;
Object.defineProperty(base, 'load', { enumerable: false });
Object.defineProperty(base, 'loaded', { enumerable: false });
module.exports = base;