ca95edf295
* feat: compact theme * fix: theme * fix: styling * fix: margin * feat: improve * fix: remove console.log * test: enable plugin test * refactor: multi app * test: lazy load sync plugin * test: lazy load test * fix: beforeGetApplication Event * feat: loadFromDatabase options in traverseSubApps * fix: test * fix: multi app manager test * chore: test * test: should upgrade sub apps when main app upgrade * feat: plugin require check * chore: yarn.lock * fix: sql typo * feat: share collections * fix: record name * test: belongs to many repository * fix: belongs to many with targetKey alias * fix: extend collection error * fix: transaction error * feat: collection graph * fix: update options in collection * chore: collections graph * chore: export uitls * feat: connected nodes method in collections graph * feat: exclude params in connected nodes * chore: sub app collection list params * fix: collections graph * feat: syncToApps migration * fix: translation --------- Co-authored-by: chenos <chenlinxh@gmail.com>
90 lines
1.5 KiB
TypeScript
90 lines
1.5 KiB
TypeScript
import { Application } from './application';
|
|
import { InstallOptions } from './plugin-manager';
|
|
|
|
export interface PluginInterface {
|
|
beforeLoad?: () => void;
|
|
|
|
load();
|
|
|
|
getName(): string;
|
|
}
|
|
|
|
export interface PluginOptions {
|
|
activate?: boolean;
|
|
displayName?: string;
|
|
description?: string;
|
|
version?: string;
|
|
enabled?: boolean;
|
|
install?: (this: Plugin) => void;
|
|
load?: (this: Plugin) => void;
|
|
plugin?: typeof Plugin;
|
|
|
|
[key: string]: any;
|
|
}
|
|
|
|
export type PluginType = typeof Plugin;
|
|
|
|
export abstract class Plugin<O = any> implements PluginInterface {
|
|
options: any;
|
|
app: Application;
|
|
|
|
constructor(app: Application, options?: any) {
|
|
this.setOptions(options);
|
|
|
|
this.app = app;
|
|
this.setOptions(options);
|
|
this.afterAdd();
|
|
}
|
|
|
|
get name() {
|
|
return this.options.name as string;
|
|
}
|
|
|
|
get db() {
|
|
return this.app.db;
|
|
}
|
|
|
|
get enabled() {
|
|
return this.options.enabled;
|
|
}
|
|
|
|
set enabled(value) {
|
|
this.options.enabled = value;
|
|
}
|
|
|
|
setOptions(options: any) {
|
|
this.options = options || {};
|
|
}
|
|
|
|
getName() {
|
|
return (this.options as any).name;
|
|
}
|
|
|
|
afterAdd() {}
|
|
|
|
beforeLoad() {}
|
|
|
|
async load() {}
|
|
|
|
async install(options?: InstallOptions) {}
|
|
|
|
async afterEnable() {}
|
|
|
|
async afterDisable() {}
|
|
|
|
async remove() {}
|
|
|
|
async importCollections(collectionsPath: string) {
|
|
await this.db.import({
|
|
directory: collectionsPath,
|
|
from: this.getName(),
|
|
});
|
|
}
|
|
|
|
requiredPlugins() {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export default Plugin;
|