2022-12-22 11:29:51 +09:00
|
|
|
import { BackendConfigType } from '../../types/config';
|
2022-12-11 14:11:25 +01:00
|
|
|
import { configExists } from './configExists';
|
|
|
|
|
import { getFallbackConfig } from './getFallbackConfig';
|
2022-12-22 11:29:51 +09:00
|
|
|
import { migrateConfig } from './migrateConfig';
|
2022-12-11 14:11:25 +01:00
|
|
|
import { readConfig } from './readConfig';
|
|
|
|
|
|
2022-12-11 19:16:31 +01:00
|
|
|
export const getConfig = (name: string): BackendConfigType => {
|
2022-12-11 14:11:25 +01:00
|
|
|
if (!configExists(name)) return getFallbackConfig();
|
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) {
|
|
|
|
|
console.log('Migrating config file...', config);
|
|
|
|
|
return migrateConfig(config, name);
|
2022-12-22 11:29:51 +09:00
|
|
|
}
|
|
|
|
|
return config;
|
2022-12-11 14:11:25 +01:00
|
|
|
};
|