mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:06:06 +00:00
feat: plugin before enable hook (#1648)
This commit is contained in:
parent
28ef3b6952
commit
a09c5001eb
@ -8,8 +8,11 @@ import { mockServer, MockServer } from '@nocobase/test';
|
||||
describe('plugin', () => {
|
||||
let app: MockServer;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
app = mockServer();
|
||||
await app.db.clean({ drop: true });
|
||||
|
||||
await app.db.sync();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@ -108,4 +111,20 @@ describe('plugin', () => {
|
||||
expect(Test).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('enable', function () {
|
||||
it('should call beforeEnable', async () => {
|
||||
const beforeEnable = jest.fn();
|
||||
|
||||
class TestPlugin extends Plugin {
|
||||
async beforeEnable() {
|
||||
beforeEnable();
|
||||
}
|
||||
}
|
||||
|
||||
app.plugin(TestPlugin);
|
||||
await app.pm.enable('TestPlugin');
|
||||
expect(beforeEnable).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -30,6 +30,10 @@ export class PluginManagerRepository extends Repository {
|
||||
}
|
||||
}
|
||||
|
||||
for (const plugin of plugins) {
|
||||
await plugin.beforeEnable();
|
||||
}
|
||||
|
||||
await this.update({
|
||||
filter: {
|
||||
name,
|
||||
|
@ -68,6 +68,8 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
||||
|
||||
async install(options?: InstallOptions) {}
|
||||
|
||||
async beforeEnable() {}
|
||||
|
||||
async afterEnable() {}
|
||||
|
||||
async afterDisable() {}
|
||||
|
@ -114,6 +114,12 @@ class SubAppPlugin extends Plugin {
|
||||
export class MultiAppShareCollectionPlugin extends Plugin {
|
||||
afterAdd() {}
|
||||
|
||||
async beforeEnable() {
|
||||
if (!this.db.inDialect('postgres')) {
|
||||
throw new Error('multi-app-share-collection plugin only support postgres');
|
||||
}
|
||||
}
|
||||
|
||||
async beforeLoad() {
|
||||
if (!this.db.inDialect('postgres')) {
|
||||
throw new Error('multi-app-share-collection plugin only support postgres');
|
||||
|
Loading…
Reference in New Issue
Block a user