62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { PluginConfiguration, Service } from '../types';
|
|
import { ScopedEventEmitter } from '../util/events';
|
|
|
|
export interface IPlugin {
|
|
manifest: IPluginManifest;
|
|
stream: ScopedEventEmitter;
|
|
config: PluginConfiguration;
|
|
service: Service | null;
|
|
}
|
|
|
|
/**
|
|
* Base class for all plugins
|
|
*/
|
|
export class Plugin implements IPlugin {
|
|
public service: Service | null = null;
|
|
protected on = this.addEventListener;
|
|
|
|
constructor(
|
|
public manifest: IPluginManifest,
|
|
public stream: ScopedEventEmitter,
|
|
public config: PluginConfiguration) {}
|
|
|
|
/**
|
|
* Called when plugin first starts.
|
|
* Please use this instead of the constructor.
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
public initialize(): void {}
|
|
|
|
public get name(): string {
|
|
return this.manifest.name;
|
|
}
|
|
|
|
public get version(): string {
|
|
return this.manifest.version;
|
|
}
|
|
|
|
protected addEventListener(name: string, fn: any): void {
|
|
this.stream.on(this.name, name, fn);
|
|
}
|
|
|
|
protected emit(event: string, data: any): void {
|
|
this.stream.emit.call(this.stream, event, data);
|
|
}
|
|
|
|
protected emitTo(name: string, event: string, data: any): void {
|
|
this.stream.emitTo.call(this.stream, name, event, data);
|
|
}
|
|
}
|
|
|
|
export interface IPluginManifest {
|
|
repository: string;
|
|
fullPath: string;
|
|
main: string;
|
|
name: string;
|
|
tags?: string[];
|
|
version: string;
|
|
description: string;
|
|
dependencies: string[];
|
|
npmDependencies: string[];
|
|
}
|