mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:38:51 +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', () => {
|
describe('plugin', () => {
|
||||||
let app: MockServer;
|
let app: MockServer;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
app = mockServer();
|
app = mockServer();
|
||||||
|
await app.db.clean({ drop: true });
|
||||||
|
|
||||||
|
await app.db.sync();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -108,4 +111,20 @@ describe('plugin', () => {
|
|||||||
expect(Test).toBeDefined();
|
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({
|
await this.update({
|
||||||
filter: {
|
filter: {
|
||||||
name,
|
name,
|
||||||
|
@ -68,6 +68,8 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
|
|
||||||
async install(options?: InstallOptions) {}
|
async install(options?: InstallOptions) {}
|
||||||
|
|
||||||
|
async beforeEnable() {}
|
||||||
|
|
||||||
async afterEnable() {}
|
async afterEnable() {}
|
||||||
|
|
||||||
async afterDisable() {}
|
async afterDisable() {}
|
||||||
|
@ -114,6 +114,12 @@ class SubAppPlugin extends Plugin {
|
|||||||
export class MultiAppShareCollectionPlugin extends Plugin {
|
export class MultiAppShareCollectionPlugin extends Plugin {
|
||||||
afterAdd() {}
|
afterAdd() {}
|
||||||
|
|
||||||
|
async beforeEnable() {
|
||||||
|
if (!this.db.inDialect('postgres')) {
|
||||||
|
throw new Error('multi-app-share-collection plugin only support postgres');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async beforeLoad() {
|
async beforeLoad() {
|
||||||
if (!this.db.inDialect('postgres')) {
|
if (!this.db.inDialect('postgres')) {
|
||||||
throw new Error('multi-app-share-collection plugin only support postgres');
|
throw new Error('multi-app-share-collection plugin only support postgres');
|
||||||
|
Loading…
Reference in New Issue
Block a user