fix: plugin upgrade

This commit is contained in:
chenos 2022-12-14 22:33:15 +08:00
parent a593720c81
commit 5b81c4d07c
2 changed files with 46 additions and 19 deletions

View File

@ -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') {

View File

@ -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`);