-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (34 loc) · 1003 Bytes
/
index.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
const fs = require("fs");
const env = process.env.NODE_ENV || "unknown";
const homedir = require("os").homedir();
if (env == "unknown") {
console.error("missing process.env");
process.exit();
}
var cfg = {};
var stubs = {
misc: `${homedir}/sfdc/etc/jsconfig/misc.json`,
sfdc: `${homedir}/sfdc/etc/jsconfig/sfdc.json`,
local: `${__dirname}/../../config/default.json`,
store: `${__dirname}/../../config/store.json`,
};
for (const [name, file] of Object.entries(stubs)) {
cfg[name] = {};
if (fs.existsSync(file)) {
if (name == "sfdc") {
var sfdc = require(file);
if (sfdc[env]) {
cfg.sfdc = sfdc[env];
} else {
console.error(`unknown auth ${env}`);
process.exit();
}
} else {
cfg[name] = require(file);
}
}
}
cfg.save = function() {
fs.writeFileSync(stubs["store"], JSON.stringify(cfg.store, null, 3));
};
module.exports = cfg;