2021-04-21 20:29:33 +02:00
|
|
|
function load(envName) {
|
|
|
|
return {
|
2021-08-25 20:15:31 +02:00
|
|
|
...require("./config/base.json"),
|
|
|
|
...loadConfig(envName),
|
|
|
|
...loadConfig("local"),
|
2021-10-22 14:50:08 +02:00
|
|
|
dev: {
|
|
|
|
...require("./config/base.json").dev,
|
|
|
|
...loadConfig(envName).dev,
|
|
|
|
...loadConfig("local").dev,
|
|
|
|
},
|
2021-04-21 20:29:33 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function log(configObj) {
|
2021-08-25 20:15:31 +02:00
|
|
|
const repeatNum = 50;
|
|
|
|
console.log(`${"=".repeat(repeatNum)}\nenvConfig`);
|
|
|
|
console.log(JSON.stringify(configObj, null, 2));
|
|
|
|
console.log(`${"=".repeat(repeatNum)}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadConfig(configName) {
|
|
|
|
try {
|
|
|
|
return require(`./config/${configName}.json`);
|
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof Error && e.code === "MODULE_NOT_FOUND") {
|
|
|
|
return {};
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-04-21 20:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
load,
|
|
|
|
log,
|
|
|
|
};
|