chore: support config path being specified via command line argument (#2201)
All checks were successful
Build / build (push) Successful in 51s
Build Docker image / docker (push) Successful in 38s

Reviewed-on: #2201
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
Sainan 2025-06-18 11:34:12 -07:00 committed by Sainan
parent dabca46e88
commit 0c4065619d
3 changed files with 6 additions and 6 deletions

View File

@ -1,13 +1,13 @@
// First, init config.
import { config, loadConfig } from "@/src/services/configService";
import { config, configPath, loadConfig } from "@/src/services/configService";
import fs from "fs";
try {
loadConfig();
} catch (e) {
if (fs.existsSync("config.json")) {
console.log("Failed to load config.json: " + (e as Error).message);
console.log("Failed to load " + configPath + ": " + (e as Error).message);
} else {
console.log("Failed to load config.json. You can copy config.json.example to create your config.json.");
console.log("Failed to load " + configPath + ". You can copy config.json.example to create your config file.");
}
process.exit(1);
}

View File

@ -72,7 +72,7 @@ export interface IConfig {
};
}
export const configPath = path.join(repoDir, "config.json");
export const configPath = path.join(repoDir, process.argv[2] ?? "config.json");
export const config: IConfig = {
mongodbUrl: "mongodb://127.0.0.1:27017/openWF",

View File

@ -9,7 +9,7 @@ fs.watchFile(configPath, () => {
if (amnesia) {
amnesia = false;
} else {
logger.info("Detected a change to config.json, reloading its contents.");
logger.info("Detected a change to config file, reloading its contents.");
try {
loadConfig();
} catch (e) {
@ -41,7 +41,7 @@ export const validateConfig = (): void => {
}
}
if (modified) {
logger.info(`Updating config.json to fix some issues with it.`);
logger.info(`Updating config file to fix some issues with it.`);
void saveConfig();
}
};