2022-05-19 00:40:55 +08:00
|
|
|
import { Plugin } from '@nocobase/server';
|
|
|
|
|
2022-10-27 13:00:16 +08:00
|
|
|
export class PresetNocoBase extends Plugin {
|
|
|
|
async addBuiltInPlugins() {
|
|
|
|
const plugins = [
|
|
|
|
'error-handler',
|
|
|
|
'collection-manager',
|
|
|
|
'ui-schema-storage',
|
|
|
|
'ui-routes-storage',
|
|
|
|
'file-manager',
|
|
|
|
'system-settings',
|
|
|
|
'verification',
|
|
|
|
'users',
|
|
|
|
'acl',
|
|
|
|
'china-region',
|
|
|
|
'workflow',
|
|
|
|
'client',
|
|
|
|
'export',
|
|
|
|
'audit-logs',
|
|
|
|
];
|
|
|
|
await this.app.pm.add(plugins, {
|
|
|
|
enabled: true,
|
|
|
|
builtIn: true,
|
|
|
|
installed: true,
|
|
|
|
});
|
2022-10-29 14:07:51 +08:00
|
|
|
const samples = [
|
|
|
|
'sample-command',
|
|
|
|
'sample-custom-block',
|
|
|
|
'sample-custom-page',
|
|
|
|
'sample-custom-signup-page',
|
|
|
|
'sample-hello',
|
|
|
|
'sample-ratelimit',
|
|
|
|
'sample-shop-actions',
|
|
|
|
'sample-shop-events',
|
|
|
|
'sample-shop-i18n',
|
|
|
|
'sample-shop-modeling',
|
|
|
|
];
|
|
|
|
await this.app.pm.add(samples, {});
|
2022-10-27 13:00:16 +08:00
|
|
|
await this.app.reload();
|
2022-05-19 00:40:55 +08:00
|
|
|
}
|
2022-08-20 18:06:12 +08:00
|
|
|
|
2022-10-27 13:00:16 +08:00
|
|
|
afterAdd() {
|
2022-10-28 15:09:14 +08:00
|
|
|
this.app.on('beforeLoad', async (app, options) => {
|
|
|
|
if (options?.method !== 'upgrade') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
|
|
|
|
if (result) {
|
|
|
|
const r = await this.db.collectionExistsInDb('applicationPlugins');
|
|
|
|
if (r) {
|
|
|
|
await this.db.getRepository('applicationPlugins').destroy({ truncate: true });
|
|
|
|
await this.app.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-10-27 13:00:16 +08:00
|
|
|
this.app.on('beforeUpgrade', async () => {
|
|
|
|
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
|
|
|
|
if (result) {
|
|
|
|
await this.addBuiltInPlugins();
|
2022-09-18 14:10:01 +08:00
|
|
|
}
|
|
|
|
});
|
2022-10-27 13:00:16 +08:00
|
|
|
this.app.on('beforeInstall', async () => {
|
|
|
|
await this.addBuiltInPlugins();
|
|
|
|
});
|
2022-08-20 18:06:12 +08:00
|
|
|
}
|
2022-10-27 13:00:16 +08:00
|
|
|
beforeLoad() {}
|
2022-05-19 00:40:55 +08:00
|
|
|
}
|
|
|
|
|
2022-08-20 18:06:12 +08:00
|
|
|
export default PresetNocoBase;
|