core/src/plugin/plugin.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-11-21 15:41:08 +00:00
import { logger } from '../core/logger';
2020-11-28 13:34:34 +00:00
import { PluginConfiguration, Service } from '../types';
2020-11-21 15:41:08 +00:00
import { ScopedEventEmitter } from '../util/events';
export interface IPlugin {
manifest: IPluginManifest;
stream: ScopedEventEmitter;
config: PluginConfiguration;
2020-11-28 13:34:34 +00:00
service: Service | null;
2020-11-21 15:41:08 +00:00
}
export class Plugin implements IPlugin {
2020-11-28 13:34:34 +00:00
public service: Service | null = null;
2020-11-21 15:41:08 +00:00
constructor(
public manifest: IPluginManifest,
public stream: ScopedEventEmitter,
public config: PluginConfiguration) {}
public initialize(): void {}
2020-11-28 13:34:34 +00:00
protected get name(): string {
2020-11-21 15:41:08 +00:00
return this.manifest.name;
}
2020-11-28 13:34:34 +00:00
protected get version(): string {
2020-11-21 15:41:08 +00:00
return this.manifest.version;
}
2020-11-28 13:34:34 +00:00
protected addEventListener(name: string, fn: any): void {
2020-11-21 15:41:08 +00:00
this.stream.on(this.name, name, fn);
}
2020-11-28 13:34:34 +00:00
protected emit(event: string, fn: any): void {
2020-11-21 15:41:08 +00:00
this.stream.emit.call(this.stream, event, fn);
}
2020-11-28 13:34:34 +00:00
protected emitTo(name: string, event: string, fn: any): void {
2020-11-21 15:41:08 +00:00
this.stream.emitTo.call(this.stream, name, event, fn);
}
}
export interface IPluginManifest {
repository: string;
fullPath: string;
main: string;
name: string;
version: string;
description: string;
dependencies: string[];
npmDependencies: string[];
}