diff --git a/src/modules/plugin.ts b/src/modules/plugin.ts index 44a5819..ce13a8d 100644 --- a/src/modules/plugin.ts +++ b/src/modules/plugin.ts @@ -60,6 +60,10 @@ class PluginAPI extends EventEmitter2 { return this._config; } + get pluginConfig(): Config { + throw new Error("not implemented and should not be called"); + } + private _logger: Logger; get logger(): Logger { @@ -163,6 +167,35 @@ export class PluginAPIManager { }; } + if (prop === "pluginConfig") { + return new Proxy(config, { + get(target: Config, prop: string): any { + if (prop === "set") { + return (key: string, value: any): void => { + target.set(`plugin.${plugin.name}.${key}`, value); + }; + } + + if (prop === "get") { + return (key: string, fallback = null): any => { + return target.get( + `plugin.${plugin.name}.${key}`, + fallback + ); + }; + } + + if (prop === "has") { + return (key: string): any => { + return target.has(`plugin.${plugin.name}.${key}`); + }; + } + + throw new Error(`Invalid method accessed ${prop}`); + }, + }); + } + return (target as any)[prop]; }, })