2022-12-31 23:31:41 +01:00
|
|
|
import fs from 'fs';
|
2023-07-21 18:08:40 +09:00
|
|
|
|
2023-01-21 23:11:34 +01:00
|
|
|
import { BackendConfigType } from '../../types/config';
|
2022-12-31 23:31:41 +01:00
|
|
|
import { Config } from '../types';
|
|
|
|
|
import { migrateConfig } from './migrateConfig';
|
|
|
|
|
|
2023-01-21 23:11:34 +01:00
|
|
|
export function backendMigrateConfig(config: Config, name: string): BackendConfigType {
|
2022-12-31 23:31:41 +01:00
|
|
|
const migratedConfig = migrateConfig(config);
|
|
|
|
|
|
2023-01-08 13:09:54 +09:00
|
|
|
// Make a backup of the old file ./data/configs/${name}.json
|
|
|
|
|
// New name is ./data/configs/${name}.bak
|
|
|
|
|
fs.copyFileSync(`./data/configs/${name}.json`, `./data/configs/${name}.json.bak`);
|
|
|
|
|
|
2022-12-31 23:31:41 +01:00
|
|
|
// Overrite the file ./data/configs/${name}.json
|
|
|
|
|
// with the new config format
|
|
|
|
|
fs.writeFileSync(`./data/configs/${name}.json`, JSON.stringify(migratedConfig, null, 2));
|
|
|
|
|
|
|
|
|
|
return migratedConfig;
|
|
|
|
|
}
|