diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 88fcf4ec..bb6d5f5f 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -28,7 +28,7 @@ }, "dependencies": { "@ms/api": "^0.0.0", - "es6-map": "^0.1.5", - "inversify": "^5.0.1" + "@ms/common": "^0.0.0", + "@ms/container": "^0.0.0" } -} +} \ No newline at end of file diff --git a/packages/plugin/src/decorators.ts b/packages/plugin/src/decorators.ts index fe9561cb..58467b2f 100644 --- a/packages/plugin/src/decorators.ts +++ b/packages/plugin/src/decorators.ts @@ -5,16 +5,15 @@ import { getPluginMetadatas } from './utils' /** * MiaoScript plugin - * @param name namespace name default is '/' - * @param middleware middleware array + * @param metadata PluginMetadata */ -export function plugin(currentMetadata: interfaces.PluginMetadata) { +export function plugin(metadata: interfaces.PluginMetadata) { return function(target: any) { - target.description = currentMetadata; - currentMetadata.target = target; + target.description = metadata; + metadata.target = target; decorate(injectable(), target); - Reflect.defineMetadata(METADATA_KEY.plugin, currentMetadata, target); + Reflect.defineMetadata(METADATA_KEY.plugin, metadata, target); const previousMetadata: interfaces.PluginMetadata[] = getPluginMetadatas(); - Reflect.defineMetadata(METADATA_KEY.plugin, [currentMetadata, ...previousMetadata], Reflect); + Reflect.defineMetadata(METADATA_KEY.plugin, [metadata, ...previousMetadata], Reflect); }; } diff --git a/packages/plugin/src/interfaces.ts b/packages/plugin/src/interfaces.ts index 589c0397..72e1fa13 100644 --- a/packages/plugin/src/interfaces.ts +++ b/packages/plugin/src/interfaces.ts @@ -5,12 +5,7 @@ export namespace interfaces { @injectable() export abstract class Plugin { public description: PluginMetadata; - protected logger: Console; - - @postConstruct() - private init() { - this.logger = global.console; - } + public logger: Console; public load() { } public enable() { } diff --git a/packages/plugin/src/manager.ts b/packages/plugin/src/manager.ts index bcd01634..09092ad5 100644 --- a/packages/plugin/src/manager.ts +++ b/packages/plugin/src/manager.ts @@ -1,4 +1,4 @@ -import { plugin, server } from '@ms/api' +import { plugin, server, MiaoScriptConsole } from '@ms/api' import { injectable, inject, postConstruct, Container } from '@ms/container' import * as fs from '@ms/common/dist/fs' @@ -11,6 +11,8 @@ export class PluginManagerImpl implements plugin.PluginManager { private pluginInstance: any; @inject(server.ServerType) private serverType: string; + @inject(server.Console) + private Console: MiaoScriptConsole; private pluginMap: Map; @@ -47,7 +49,6 @@ export class PluginManagerImpl implements plugin.PluginManager { } private runCatch(pl: any, func: string) { - console.log(JSON.stringify(pl)); try { pl[func].call(pl); } catch (ex) { @@ -131,6 +132,8 @@ export class PluginManagerImpl implements plugin.PluginManager { this.pluginMap.set(metadata.name, container.getNamed(plugin.Plugin, metadata.name)); let pluginInstance = this.pluginMap.get(metadata.name) pluginInstance.description = metadata; + // @ts-ignore + pluginInstance.logger = new this.Console(metadata.name); } } }