2022-01-28 15:29:04 +01:00
|
|
|
function load(envName) {
|
2024-10-07 13:20:50 +02:00
|
|
|
const base = require("./base.json");
|
|
|
|
const env = loadConfig(envName);
|
|
|
|
const local = loadConfig("local");
|
|
|
|
|
2022-01-28 15:29:04 +01:00
|
|
|
return {
|
2024-10-07 13:20:50 +02:00
|
|
|
...base,
|
|
|
|
...env,
|
|
|
|
...local,
|
|
|
|
dev: {
|
|
|
|
...base.dev,
|
|
|
|
...env.dev,
|
|
|
|
...local.dev,
|
|
|
|
},
|
|
|
|
flags: {
|
|
|
|
...base.flags,
|
|
|
|
...env.flags,
|
|
|
|
...local.flags,
|
|
|
|
},
|
|
|
|
devFlags: {
|
|
|
|
...base.devFlags,
|
|
|
|
...env.devFlags,
|
|
|
|
...local.devFlags,
|
|
|
|
},
|
2022-01-28 15:29:04 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function log(configObj) {
|
|
|
|
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(`./${configName}.json`);
|
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof Error && e.code === "MODULE_NOT_FOUND") {
|
|
|
|
return {};
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
load,
|
|
|
|
log,
|
|
|
|
};
|