mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
feat(migration): add v4-to-v5 settings migration runner with backup
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { z } from 'zod';
|
||||
import { settingsSchema } from '@/lib/validators';
|
||||
|
||||
export const v4SettingsSchema = z.object({
|
||||
theme: z.enum(['light', 'dark', 'auto']).default('auto'),
|
||||
customCss: z.string().optional().nullable(),
|
||||
recentFiles: z.array(z.string()).default([]),
|
||||
editorFontSize: z.number().min(10).max(28).default(14),
|
||||
keyBindings: z.record(z.string(), z.string()).optional(),
|
||||
snippets: z.array(z.unknown()).default([]),
|
||||
});
|
||||
|
||||
export function migrateV4ToV5(v4: unknown): z.infer<typeof settingsSchema> {
|
||||
const parsed = v4SettingsSchema.parse(v4);
|
||||
const defaults = settingsSchema.parse({});
|
||||
return {
|
||||
...defaults,
|
||||
...parsed,
|
||||
theme: parsed.theme === 'auto' ? 'system' : parsed.theme,
|
||||
customCssPath: parsed.customCss ?? null,
|
||||
recentFiles: parsed.recentFiles,
|
||||
editorFontSize: parsed.editorFontSize,
|
||||
userBindings: parsed.keyBindings ?? defaults.userBindings ?? {},
|
||||
snippets: parsed.snippets,
|
||||
};
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export const settingsSchema = z.object({
|
||||
lineNumbers: z.boolean().default(true),
|
||||
wordWrap: z.boolean().default(true),
|
||||
minimap: z.boolean().default(true),
|
||||
theme: z.enum(['light', 'dark', 'auto']).default('auto'),
|
||||
theme: z.enum(['light', 'dark', 'system']).default('system'),
|
||||
accentColor: z.enum(['brand', 'blue', 'green', 'purple', 'orange']).default('brand'),
|
||||
fontFamily: z.enum(['system', 'jetbrains', 'fira']).default('system'),
|
||||
pdfFormat: z.enum(['letter', 'a4', 'legal']).default('a4'),
|
||||
@@ -21,6 +21,7 @@ export const settingsSchema = z.object({
|
||||
welcomeDismissed: z.boolean().default(false),
|
||||
editorFontSize: z.number().min(10).max(28).default(14),
|
||||
customCssPath: z.string().nullable().default(null),
|
||||
userBindings: z.record(z.string(), z.string()).default({}),
|
||||
});
|
||||
export type Settings = z.infer<typeof settingsSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user