2024-03-08 06:34:50 +01:00
|
|
|
/**
|
|
|
|
|
* @file index.ts
|
|
|
|
|
* @summary ConfigManager system to retrieve and modify system configuration
|
|
|
|
|
* @description Can read from a hand-written file, config.toml, or from a machine-saved file, config.internal.toml
|
|
|
|
|
* Fuses both and provides a way to retrieve individual values
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-16 04:50:07 +02:00
|
|
|
import { loadConfig, watchConfig } from "c12";
|
|
|
|
|
import { type Config, configValidator } from "./config.type";
|
2024-04-07 06:16:54 +02:00
|
|
|
|
2024-05-16 04:37:25 +02:00
|
|
|
const { config } = await watchConfig({
|
2024-04-07 07:30:49 +02:00
|
|
|
configFile: "./config/config.toml",
|
|
|
|
|
overrides:
|
|
|
|
|
(
|
2024-05-16 04:37:25 +02:00
|
|
|
await loadConfig<Config>({
|
2024-04-07 07:30:49 +02:00
|
|
|
configFile: "./config/config.internal.toml",
|
|
|
|
|
})
|
|
|
|
|
).config ?? undefined,
|
2024-04-07 06:16:54 +02:00
|
|
|
});
|
|
|
|
|
|
2024-05-16 04:37:25 +02:00
|
|
|
const parsed = await configValidator.safeParseAsync(config);
|
|
|
|
|
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const exportedConfig = parsed.data;
|
2024-04-07 06:16:54 +02:00
|
|
|
|
|
|
|
|
export { exportedConfig as config };
|
|
|
|
|
export type { Config };
|