From 682f0dfc30e5bed1087c8af914a0cdcc222e70a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Sun, 30 Jul 2023 11:44:00 +0800 Subject: [PATCH] feat(theme-editor): add migration (#2310) * chore: change 'Default theme of antd' to 'Default' * feat(theme-editor): add migration * refactor: change file name --- packages/plugins/theme-editor/src/locale/zh-CN.ts | 2 -- .../theme-editor/src/server/builtinThemes.ts | 2 +- .../migrations/202307250847-theme-editor.ts | 15 +++++++++++++++ .../plugins/theme-editor/src/server/plugin.ts | 11 ++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 packages/plugins/theme-editor/src/server/migrations/202307250847-theme-editor.ts diff --git a/packages/plugins/theme-editor/src/locale/zh-CN.ts b/packages/plugins/theme-editor/src/locale/zh-CN.ts index 51fb1f33e..d6cf5b477 100644 --- a/packages/plugins/theme-editor/src/locale/zh-CN.ts +++ b/packages/plugins/theme-editor/src/locale/zh-CN.ts @@ -16,8 +16,6 @@ const locale = { 'Edit based on current theme': '基于当前主题进行编辑', 'Create a brand new theme': '创建一个全新的主题', - // 内置主题的名字 - 'Default theme of antd': 'antd 默认主题', Dark: '暗黑', Compact: '紧凑', 'Compact dark': '紧凑暗黑', diff --git a/packages/plugins/theme-editor/src/server/builtinThemes.ts b/packages/plugins/theme-editor/src/server/builtinThemes.ts index 2deb6e79d..fa153db60 100644 --- a/packages/plugins/theme-editor/src/server/builtinThemes.ts +++ b/packages/plugins/theme-editor/src/server/builtinThemes.ts @@ -3,7 +3,7 @@ import { ThemeItem } from '../types'; /** antd 默认主题 */ export const antd: Omit = { config: { - name: 'Default theme of antd', + name: 'Default', }, optional: true, isBuiltIn: true, diff --git a/packages/plugins/theme-editor/src/server/migrations/202307250847-theme-editor.ts b/packages/plugins/theme-editor/src/server/migrations/202307250847-theme-editor.ts new file mode 100644 index 000000000..88c6cf3bf --- /dev/null +++ b/packages/plugins/theme-editor/src/server/migrations/202307250847-theme-editor.ts @@ -0,0 +1,15 @@ +import { Migration } from '@nocobase/server'; +import { antd, compact, compactDark, dark } from '../builtinThemes'; + +export default class ThemeEditorMigration extends Migration { + async up() { + const theme = this.db.getCollection('themeConfig'); + if (theme) { + await theme.repository.create({ + values: [antd, dark, compact, compactDark], + }); + } + } + + async down() {} +} diff --git a/packages/plugins/theme-editor/src/server/plugin.ts b/packages/plugins/theme-editor/src/server/plugin.ts index d5945a3c9..37bfc6e3c 100644 --- a/packages/plugins/theme-editor/src/server/plugin.ts +++ b/packages/plugins/theme-editor/src/server/plugin.ts @@ -1,5 +1,6 @@ import { Collection } from '@nocobase/database'; import { InstallOptions, Plugin } from '@nocobase/server'; +import { resolve } from 'path'; import { antd, compact, compactDark, dark } from './builtinThemes'; export class ThemeEditorPlugin extends Plugin { @@ -7,7 +8,15 @@ export class ThemeEditorPlugin extends Plugin { afterAdd() {} - beforeLoad() {} + beforeLoad() { + this.db.addMigrations({ + namespace: 'theme-editor', + directory: resolve(__dirname, './migrations'), + context: { + plugin: this, + }, + }); + } async load() { this.theme = this.db.collection({