tachybase_todo/packages/server/src/plugin-manager.ts
ChengLei Shao 15950ece05
Application (#175)
* feat: getRepository

* getRepository return type

* export action

* add: acl

* feat: setResourceAction

* feat: action alias

* chore: code struct

* feat: removeResourceAction

* chore: file name

* ignorecase

* remove ACL

* feat: ACL

* feat: role toJSON

* using emit

* chore: test

* feat: plugin-acl

* feat: acl with predicate

* grant universal action test

* grant action test

* update resource action test

* revoke resource action

* usingActionsConfig switch

* plugin-ui-schema-storage

* remove global acl instance

* fix: collection manager with sqlite

* add own action listener

* add acl middleware

* add acl allowConfigure strategy option

* add plugin-acl allowConfigure

* change acl resourceName

* add acl middleware merge params

* bugfix

* append fields on acl action params

* acl middleware parse template

* fix: collection-manager migrate

* add acl association field test

* feat(plugin-acl): grant association field actions

* chore(plugin-acl): type name

* feat(plugin-acl): regrant actions on resource action update

* feat(plugin-acl): regrant action on field destroy

* fix(plugin-acl): test

* fix(plugin-acl): test run

* feat(plugin-acl): set default role

* feat(plugin-users): set user default role

* test(plugin-users): create user with role

* feat(plugin-users): create user with role

* feat(application): application hook

* feat(database): reconnect

* feat(database): application life cycle

* feat(database): sync with option

* feat(database): hook position

* feat(database): hook position

* feat(database): remove load in start

* fix(application): get plugin

* feat(test): loadAndInstall

* feat: improve code

* feat: improve code

* fix: listen options

* fix: bug

* test(database): add test case

Co-authored-by: chenos <chenlinxh@gmail.com>
2022-01-30 11:11:36 +08:00

50 lines
1.1 KiB
TypeScript

import Application from './application';
import { Plugin } from './plugin';
interface PluginManagerOptions {
app: Application;
}
export class PluginManager {
app: Application;
protected plugins = new Map<string, Plugin>();
constructor(options: PluginManagerOptions) {
this.app = options.app;
}
get(name: string) {
return this.plugins.get(name);
}
add<P = Plugin, O = any>(pluginClass: any, options?: O): P {
const instance = new pluginClass(this.app, options);
const name = instance.getName();
if (this.plugins.has(name)) {
throw new Error(`plugin name [${name}] `);
}
this.plugins.set(name, instance);
return instance;
}
async load() {
await this.app.emitAsync('beforeLoadAll');
for (const [name, plugin] of this.plugins) {
await plugin.beforeLoad();
}
for (const [name, plugin] of this.plugins) {
await this.app.emitAsync('beforeLoadPlugin', plugin);
await plugin.load();
await this.app.emitAsync('afterLoadPlugin', plugin);
}
await this.app.emitAsync('afterLoadAll');
}
}