tecc 66168bcca3
feat(rewrite): Static data and key loading
static-data: Static data is now loaded. For now only the logos are loaded, but more may be added in the future. The logos are loaded in a similar fashion to how locale-specific logos are.
keys: Keys can now be loaded. They aren't
2024-04-17 04:57:07 +02:00

48 lines
1.4 KiB
TypeScript

import { getConfig, validateConfig } from "#self/config";
import log from "#self/log";
import { exit } from "node:process";
import { getActiveLocaleDescriptions, loadAllLocales, loadLocaleDescriptions } from "#self/locales";
import { loadStaticData } from "#self/util/static";
export async function prepareConfig() {
try {
log.level = "error"; // Silences logs
const validationError = validateConfig(getConfig());
if (validationError != undefined) {
log.error(`Configuration is invalid: ${validationError}`);
exit(1);
}
} catch (e) {
log.error(`Could not validate configuration: ${e}`);
exit(1);
}
}
export async function prepareLocales() {
try {
const localeDescriptions = await loadLocaleDescriptions();
const active = getActiveLocaleDescriptions();
await loadAllLocales();
log.info(
`${localeDescriptions.length} locale(s) are registered, of which ${active.length} are active`
);
} catch (e) {
log.error(`Could not load locales: ${e}`);
exit(1);
}
}
export async function prepareStaticData() {
try {
await loadStaticData();
log.info("Loaded static data");
} catch (e) {
log.error(`Could not load static data: ${e}`);
exit(1);
}
}
export async function prepareTestEnvironment() {
await prepareConfig();
await prepareLocales();
await prepareStaticData();
}