From 50e62e246fef7975866c244e08ead7c681d50349 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 9 Dec 2025 21:55:02 +0100 Subject: [add]: prompt+banner+refactor --- lib/config.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lib/config.js (limited to 'lib/config.js') diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..9d2ed39 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,62 @@ +const path = require("path") +const fs = require("fs-extra") + +const configPath = path.join(__dirname, "../config/config.json") +const apiPath = path.join(__dirname, "../config/api.json") +const cachePath = path.join(__dirname, "../cache/mod_versions.json") + +const LoadConfig = () => +{ + return require(configPath) +} + +const LoadApi = () => +{ + try + { + return require(apiPath) + } + catch + { + return {} + } +} + +const LoadCache = async () => +{ + try + { + if (await fs.pathExists(cachePath)) + return JSON.parse(await fs.readFile(cachePath, "utf8")) + } + catch (err) + { + console.error("[Cache] Failed to load:", err) + } + return {} +} + +const SaveCache = async cache => +{ + try + { + await fs.ensureDir(path.dirname(cachePath)) + await fs.writeFile(cachePath, JSON.stringify(cache, null, 2)) + } + catch (err) + { + console.error("[Cache] Failed to save:", err) + } +} + +module.exports = +{ + configPath, + apiPath, + cachePath, + LoadConfig, + LoadApi, + LoadCache, + SaveCache +} + -- cgit v1.3