53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { logger } from '../core/logger';
|
|
import { PluginConfiguration, Service } from '../types';
|
|
import { ScopedEventEmitter } from '../util/events';
|
|
|
|
export interface IPlugin {
|
|
manifest: IPluginManifest;
|
|
stream: ScopedEventEmitter;
|
|
config: PluginConfiguration;
|
|
service: Service | null;
|
|
}
|
|
|
|
export class Plugin implements IPlugin {
|
|
public service: Service | null = null;
|
|
|
|
constructor(
|
|
public manifest: IPluginManifest,
|
|
public stream: ScopedEventEmitter,
|
|
public config: PluginConfiguration) {}
|
|
|
|
public initialize(): void {}
|
|
|
|
protected get name(): string {
|
|
return this.manifest.name;
|
|
}
|
|
|
|
protected 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, fn: any): void {
|
|
this.stream.emit.call(this.stream, event, fn);
|
|
}
|
|
|
|
protected emitTo(name: string, event: string, fn: any): void {
|
|
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[];
|
|
}
|