Files
Homarr/src/tools/config/getConfig.ts

21 lines
818 B
TypeScript
Raw Normal View History

2022-12-31 16:07:05 +01:00
import Consola from 'consola';
2023-01-08 15:48:39 +09:00
import { BackendConfigType, ConfigType } from '../../types/config';
2023-01-01 15:59:30 +01:00
import { backendMigrateConfig } from './backendMigrateConfig';
2022-12-11 14:11:25 +01:00
import { configExists } from './configExists';
import { getFallbackConfig } from './getFallbackConfig';
import { readConfig } from './readConfig';
export const getConfig = (name: string): BackendConfigType => {
2023-01-08 15:48:39 +09:00
if (!configExists(name)) return getFallbackConfig() as unknown as ConfigType;
2022-12-22 11:29:51 +09:00
// Else if config exists but contains no "schema_version" property
// then it is an old config file and we should try to migrate it
// to the new format.
2022-12-24 17:18:16 +09:00
const config = readConfig(name);
if (config.schemaVersion === undefined) {
2022-12-31 16:07:05 +01:00
Consola.log('Migrating config file...', config);
2023-01-01 15:59:30 +01:00
return backendMigrateConfig(config, name);
2022-12-22 11:29:51 +09:00
}
2022-12-31 16:07:05 +01:00
2022-12-22 11:29:51 +09:00
return config;
2022-12-11 14:11:25 +01:00
};