From 99c40c208296c723f5d1a89d1f6c38564bef5829 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 11 Aug 2022 18:16:57 +0200 Subject: Make fosscord read config from json if CONFIG_PATH is set --- util/src/util/Config.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'util/src') diff --git a/util/src/util/Config.ts b/util/src/util/Config.ts index 97a73858..925cb243 100644 --- a/util/src/util/Config.ts +++ b/util/src/util/Config.ts @@ -3,7 +3,7 @@ import path from "path"; import fs from "fs"; // TODO: yaml instead of json -// const overridePath = path.join(process.cwd(), "config.json"); +const overridePath = process.env.CONFIG_PATH ?? ""; let config: ConfigValue; let pairs: ConfigEntity[]; @@ -18,12 +18,14 @@ export const Config = { config = pairsToConfig(pairs); config = (config || {}).merge(DefaultConfigOptions); - // try { - // const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" })); - // config = overrideConfig.merge(config); - // } catch (error) { - // fs.writeFileSync(overridePath, JSON.stringify(config, null, 4)); - // } + if(process.env.CONFIG_PATH) + try { + const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" })); + config = overrideConfig.merge(config); + } catch (error) { + fs.writeFileSync(overridePath, JSON.stringify(config, null, 4)); + } + return this.set(config); }, @@ -50,7 +52,8 @@ function applyConfig(val: ConfigValue) { pair.value = obj; return pair.save(); } - // fs.writeFileSync(overridePath, JSON.stringify(val, null, 4)); + if(process.env.CONFIG_PATH) + fs.writeFileSync(overridePath, JSON.stringify(val, null, 4)); return apply(val); } -- cgit 1.5.1