From 5b81c4d07cbe42fec5c6b1b6a30b00bf027e353d Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 14 Dec 2022 22:33:15 +0800 Subject: [PATCH] fix: plugin upgrade --- .../src/plugin-manager/PluginManager.ts | 4 ++ packages/presets/nocobase/src/index.ts | 61 +++++++++++++------ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/packages/core/server/src/plugin-manager/PluginManager.ts b/packages/core/server/src/plugin-manager/PluginManager.ts index 5f60b0da66..c2681d3bd2 100644 --- a/packages/core/server/src/plugin-manager/PluginManager.ts +++ b/packages/core/server/src/plugin-manager/PluginManager.ts @@ -89,6 +89,10 @@ export class PluginManager { return this.plugins.get(name); } + has(name: string) { + return this.plugins.has(name); + } + clientWrite(data: any) { const { method, plugins } = data; if (method === 'create') { diff --git a/packages/presets/nocobase/src/index.ts b/packages/presets/nocobase/src/index.ts index b3abcd9998..48c6751589 100644 --- a/packages/presets/nocobase/src/index.ts +++ b/packages/presets/nocobase/src/index.ts @@ -2,32 +2,41 @@ import { Plugin } from '@nocobase/server'; import path from 'path'; export class PresetNocoBase extends Plugin { - async addBuiltInPlugins() { - const builtInPlugins = process.env.PRESET_NOCOBASE_PLUGINS + getBuiltInPlugins() { + return process.env.PRESET_NOCOBASE_PLUGINS ? process.env.PRESET_NOCOBASE_PLUGINS.split(',') : [ - 'error-handler', - 'collection-manager', - 'ui-schema-storage', - 'ui-routes-storage', - 'file-manager', - 'system-settings', - 'verification', - 'users', - 'acl', - 'china-region', - 'workflow', - 'client', - 'export', - 'import', - 'audit-logs', - ]; + 'error-handler', + 'collection-manager', + 'ui-schema-storage', + 'ui-routes-storage', + 'file-manager', + 'system-settings', + 'verification', + 'users', + 'acl', + 'china-region', + 'workflow', + 'client', + 'export', + 'import', + 'audit-logs', + ]; + } + + getLocalPlugins() { + const localPlugins = ['sample-hello', 'oidc', 'saml', 'map']; + return localPlugins; + } + + async addBuiltInPlugins() { + const builtInPlugins = this.getBuiltInPlugins(); await this.app.pm.add(builtInPlugins, { enabled: true, builtIn: true, installed: true, }); - const localPlugins = ['sample-hello', 'oidc', 'saml', 'map']; + const localPlugins = this.getLocalPlugins(); await this.app.pm.add(localPlugins, {}); await this.app.reload(); } @@ -55,6 +64,20 @@ export class PresetNocoBase extends Plugin { console.log(`Initialize all built-in plugins`); await this.addBuiltInPlugins(); } + const builtInPlugins = this.getBuiltInPlugins(); + await this.app.pm.add( + builtInPlugins.filter((plugin) => !this.app.pm.has(plugin)), + { + enabled: true, + builtIn: true, + installed: true, + }, + ); + const localPlugins = this.getLocalPlugins(); + await this.app.pm.add( + localPlugins.filter((plugin) => !this.app.pm.has(plugin)), + {}, + ); }); this.app.on('beforeInstall', async () => { console.log(`Initialize all built-in plugins`);