feat(theme-editor): add migration (#2310)

* chore: change 'Default theme of antd' to 'Default'

* feat(theme-editor): add migration

* refactor: change file name
This commit is contained in:
被雨水过滤的空气-Rain 2023-07-30 11:44:00 +08:00 committed by GitHub
parent b22207b180
commit 682f0dfc30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 4 deletions

View File

@ -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': '紧凑暗黑',

View File

@ -3,7 +3,7 @@ import { ThemeItem } from '../types';
/** antd 默认主题 */
export const antd: Omit<ThemeItem, 'id'> = {
config: {
name: 'Default theme of antd',
name: 'Default',
},
optional: true,
isBuiltIn: true,

View File

@ -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() {}
}

View File

@ -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({