Update default config

This commit is contained in:
ajnart
2022-12-24 17:18:16 +09:00
parent 3fb82a7336
commit e3d7b04059
20 changed files with 815 additions and 169 deletions

View File

@@ -9,10 +9,10 @@ export const getConfig = (name: string): BackendConfigType => {
// 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.
let config = readConfig(name);
if (!config.schemaVersion) {
// TODO: Migrate config to new format
config = migrateConfig(config);
const config = readConfig(name);
if (config.schemaVersion === undefined) {
console.log('Migrating config file...', config);
return migrateConfig(config, name);
}
return config;
};

View File

@@ -1,7 +1,7 @@
import { BackendConfigType } from '../../types/config';
export const getFallbackConfig = (name?: string): BackendConfigType => ({
schemaVersion: '1.0.0',
schemaVersion: 1,
configProperties: {
name: name ?? 'default',
},

View File

@@ -9,13 +9,14 @@ export const getFrontendConfig = (name: string): ConfigType => {
apps: config.apps.map((app) => ({
...app,
integration: {
...app.integration ?? null,
...(app.integration ?? null),
type: app.integration?.type ?? null,
properties: app.integration?.properties.map((property) => ({
...property,
value: property.type === 'private' ? undefined : property.value,
isDefined: property.value != null,
})) ?? [],
properties:
app.integration?.properties.map((property) => ({
...property,
value: property.type === 'private' ? undefined : property.value,
isDefined: property.value != null,
})) ?? [],
},
})),
};

View File

@@ -1,9 +1,10 @@
import fs from 'fs';
import { ConfigType } from '../../types/config';
import { Config } from '../types';
export function migrateConfig(config: Config): ConfigType {
export function migrateConfig(config: Config, name: string): ConfigType {
const newConfig: ConfigType = {
schemaVersion: '1.0.0',
schemaVersion: 1,
configProperties: {
name: config.name ?? 'default',
},
@@ -76,6 +77,9 @@ export function migrateConfig(config: Config): ConfigType {
},
},
}));
// Overrite the file ./data/configs/${name}.json
// with the new config format
fs.writeFileSync(`./data/configs/${name}.json`, JSON.stringify(newConfig, null, 2));
return newConfig;
}