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); return this.plugins.get(name);
} }
has(name: string) {
return this.plugins.has(name);
}
clientWrite(data: any) { clientWrite(data: any) {
const { method, plugins } = data; const { method, plugins } = data;
if (method === 'create') { if (method === 'create') {

View File

@ -2,8 +2,8 @@ import { Plugin } from '@nocobase/server';
import path from 'path'; import path from 'path';
export class PresetNocoBase extends Plugin { export class PresetNocoBase extends Plugin {
async addBuiltInPlugins() { getBuiltInPlugins() {
const builtInPlugins = process.env.PRESET_NOCOBASE_PLUGINS return process.env.PRESET_NOCOBASE_PLUGINS
? process.env.PRESET_NOCOBASE_PLUGINS.split(',') ? process.env.PRESET_NOCOBASE_PLUGINS.split(',')
: [ : [
'error-handler', 'error-handler',
@ -22,12 +22,21 @@ export class PresetNocoBase extends Plugin {
'import', 'import',
'audit-logs', 'audit-logs',
]; ];
}
getLocalPlugins() {
const localPlugins = ['sample-hello', 'oidc', 'saml', 'map'];
return localPlugins;
}
async addBuiltInPlugins() {
const builtInPlugins = this.getBuiltInPlugins();
await this.app.pm.add(builtInPlugins, { await this.app.pm.add(builtInPlugins, {
enabled: true, enabled: true,
builtIn: true, builtIn: true,
installed: true, installed: true,
}); });
const localPlugins = ['sample-hello', 'oidc', 'saml', 'map']; const localPlugins = this.getLocalPlugins();
await this.app.pm.add(localPlugins, {}); await this.app.pm.add(localPlugins, {});
await this.app.reload(); await this.app.reload();
} }
@ -55,6 +64,20 @@ export class PresetNocoBase extends Plugin {
console.log(`Initialize all built-in plugins`); console.log(`Initialize all built-in plugins`);
await this.addBuiltInPlugins(); 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 () => { this.app.on('beforeInstall', async () => {
console.log(`Initialize all built-in plugins`); console.log(`Initialize all built-in plugins`);