50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
|
import { logger } from '../core/logger';
|
||
|
import { PluginConfiguration } from '../types/plugin-config';
|
||
|
import { ScopedEventEmitter } from '../util/events';
|
||
|
|
||
|
export interface IPlugin {
|
||
|
manifest: IPluginManifest;
|
||
|
stream: ScopedEventEmitter;
|
||
|
config: PluginConfiguration;
|
||
|
}
|
||
|
|
||
|
export class Plugin implements IPlugin {
|
||
|
constructor(
|
||
|
public manifest: IPluginManifest,
|
||
|
public stream: ScopedEventEmitter,
|
||
|
public config: PluginConfiguration) {}
|
||
|
|
||
|
public initialize(): void {}
|
||
|
|
||
|
private get name(): string {
|
||
|
return this.manifest.name;
|
||
|
}
|
||
|
|
||
|
private get version(): string {
|
||
|
return this.manifest.version;
|
||
|
}
|
||
|
|
||
|
private addEventListener(name: string, fn: any): void {
|
||
|
this.stream.on(this.name, name, fn);
|
||
|
}
|
||
|
|
||
|
private emit(event: string, fn: any): void {
|
||
|
this.stream.emit.call(this.stream, event, fn);
|
||
|
}
|
||
|
|
||
|
private 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[];
|
||
|
}
|