2022-06-17 02:25:59 +00:00
|
|
|
import { Application } from './application';
|
2022-02-28 13:49:50 +00:00
|
|
|
import { InstallOptions } from './plugin-manager';
|
2021-09-22 16:16:04 +00:00
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
export interface PluginInterface {
|
|
|
|
beforeLoad?: () => void;
|
2023-01-08 04:45:02 +00:00
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
load();
|
2023-01-08 04:45:02 +00:00
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
getName(): string;
|
2021-09-22 16:16:04 +00:00
|
|
|
}
|
2021-09-14 03:09:26 +00:00
|
|
|
|
|
|
|
export interface PluginOptions {
|
|
|
|
activate?: boolean;
|
|
|
|
displayName?: string;
|
|
|
|
description?: string;
|
|
|
|
version?: string;
|
2022-09-18 06:10:01 +00:00
|
|
|
enabled?: boolean;
|
2021-09-14 03:09:26 +00:00
|
|
|
install?: (this: Plugin) => void;
|
|
|
|
load?: (this: Plugin) => void;
|
2021-09-22 16:16:04 +00:00
|
|
|
plugin?: typeof Plugin;
|
2023-01-08 04:45:02 +00:00
|
|
|
|
2021-09-22 16:16:04 +00:00
|
|
|
[key: string]: any;
|
2021-09-14 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
export type PluginType = typeof Plugin;
|
2021-09-14 03:09:26 +00:00
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
export abstract class Plugin<O = any> implements PluginInterface {
|
2022-10-27 05:00:16 +00:00
|
|
|
options: any;
|
2021-09-14 03:09:26 +00:00
|
|
|
app: Application;
|
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
constructor(app: Application, options?: any) {
|
2023-01-08 04:45:02 +00:00
|
|
|
this.setOptions(options);
|
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
this.app = app;
|
|
|
|
this.setOptions(options);
|
2022-10-27 05:00:16 +00:00
|
|
|
this.afterAdd();
|
2021-09-14 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 23:35:48 +00:00
|
|
|
get name() {
|
|
|
|
return this.options.name as string;
|
|
|
|
}
|
|
|
|
|
2022-12-31 02:54:20 +00:00
|
|
|
get db() {
|
|
|
|
return this.app.db;
|
|
|
|
}
|
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
get enabled() {
|
|
|
|
return this.options.enabled;
|
2021-09-14 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
set enabled(value) {
|
|
|
|
this.options.enabled = value;
|
2022-09-18 06:10:01 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
setOptions(options: any) {
|
|
|
|
this.options = options || {};
|
2022-09-18 06:10:01 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
getName() {
|
|
|
|
return (this.options as any).name;
|
|
|
|
}
|
2021-09-14 03:09:26 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
afterAdd() {}
|
2022-09-18 06:10:01 +00:00
|
|
|
|
2022-01-30 03:11:36 +00:00
|
|
|
beforeLoad() {}
|
2021-09-14 03:09:26 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
async load() {}
|
2022-02-28 13:49:50 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
async install(options?: InstallOptions) {}
|
2022-02-06 17:14:00 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
async afterEnable() {}
|
2022-09-18 06:10:01 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
async afterDisable() {}
|
2022-03-28 14:01:10 +00:00
|
|
|
|
2022-10-27 05:00:16 +00:00
|
|
|
async remove() {}
|
2023-01-08 04:45:02 +00:00
|
|
|
|
|
|
|
async importCollections(collectionsPath: string) {
|
|
|
|
await this.db.import({
|
|
|
|
directory: collectionsPath,
|
|
|
|
from: this.getName(),
|
|
|
|
});
|
|
|
|
}
|
2023-03-19 15:40:42 +00:00
|
|
|
|
|
|
|
requiredPlugins() {
|
|
|
|
return [];
|
|
|
|
}
|
2021-09-14 03:09:26 +00:00
|
|
|
}
|
2022-06-17 02:25:59 +00:00
|
|
|
|
|
|
|
export default Plugin;
|