From 34c598e6d86ae72c3667c889bc221daccbe8c1ea Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Thu, 19 Sep 2019 18:59:00 +0800 Subject: [PATCH] feat: optimize api Signed-off-by: MiaoWoo --- packages/api/src/command.ts | 5 ++++- packages/api/src/console.ts | 1 - packages/api/src/event.ts | 8 ++++---- packages/api/src/interfaces/plugin.ts | 10 ++++++---- packages/api/src/interfaces/task.ts | 9 +++++++++ packages/api/src/typings/plugin.ts | 13 ------------- 6 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 packages/api/src/interfaces/task.ts delete mode 100644 packages/api/src/typings/plugin.ts diff --git a/packages/api/src/command.ts b/packages/api/src/command.ts index 7bde5ed9..202f4376 100644 --- a/packages/api/src/command.ts +++ b/packages/api/src/command.ts @@ -14,11 +14,14 @@ export namespace command { if (exec.tab && typeof exec.tab === "function") { this.onTabComplete(plugin, cmd, exec.tab) } + } + off(plugin: any, name: string) { + } /** * Create Server Command Object */ - abstract create(plugin: object, opts: { name: string }); + abstract create(name: string, opts: { name: string }); abstract onCommand(plugin: object, command: any, opts: { name: string }); abstract onTabComplete(plugin: object, command: any, opts: { name: string }); } diff --git a/packages/api/src/console.ts b/packages/api/src/console.ts index b974c138..769b4005 100644 --- a/packages/api/src/console.ts +++ b/packages/api/src/console.ts @@ -67,7 +67,6 @@ export class MiaoScriptConsole implements Console { if (trace.className.startsWith('<')) { var fileName = trace.fileName if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] } - if (fileName.startsWith('/runtime')) { fileName = fileName.split('/runtime')[1] } cache.push(` §e->§c ${fileName} => §4${trace.methodName}:${trace.lineNumber}`) } else { var className = trace.className; diff --git a/packages/api/src/event.ts b/packages/api/src/event.ts index 4164a142..1020cec3 100644 --- a/packages/api/src/event.ts +++ b/packages/api/src/event.ts @@ -98,15 +98,15 @@ export namespace event { /** * 添加事件监听 - * @param jsp + * @param plugin * @param event * @param exec {function} * @param priority [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR] * @param ignoreCancel */ - listen(jsp, event, exec, priority, ignoreCancel) { - if (!jsp || !jsp.description || !jsp.description.name) throw new TypeError('插件名称为空 请检查传入参数!'); - var name = jsp.description.name; + listen(plugin, event, exec, priority = 'NORMAL', ignoreCancel = false) { + if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('插件名称为空 请检查传入参数!'); + var name = plugin.description.name; var eventCls = this.name2Class(name, event); if (!eventCls) { return; } if (typeof priority === 'boolean') { diff --git a/packages/api/src/interfaces/plugin.ts b/packages/api/src/interfaces/plugin.ts index d1e317e1..ee6e7f04 100644 --- a/packages/api/src/interfaces/plugin.ts +++ b/packages/api/src/interfaces/plugin.ts @@ -1,4 +1,4 @@ -import { Container } from "inversify"; +import { Container } from "@ms/container"; export namespace plugin { /** @@ -18,8 +18,10 @@ export namespace plugin { */ export interface PluginManager { scan(folder: string): void; - load(container: Container): void; - enable(): void; - disable(): void; + build(container: Container): void; + load(...args: any[]): void; + enable(...args: any[]): void; + disable(...args: any[]): void; + reload(...args: any[]): void; } } diff --git a/packages/api/src/interfaces/task.ts b/packages/api/src/interfaces/task.ts new file mode 100644 index 00000000..812f727a --- /dev/null +++ b/packages/api/src/interfaces/task.ts @@ -0,0 +1,9 @@ +export namespace task { + export const Task = Symbol('Task') + export interface Task { + run(func: Function): void; + async(func: Function): void; + later(tick: number): task.Task; + timer(tick: number): task.Task; + } +} diff --git a/packages/api/src/typings/plugin.ts b/packages/api/src/typings/plugin.ts deleted file mode 100644 index 42b1bb5f..00000000 --- a/packages/api/src/typings/plugin.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface CommandInfo { - aliases: string[]; - description: string; -} -export interface PluginInfo { - description: PluginDescription; -} -export interface PluginDescription { - name: string; - version: string; - author: string; - commands: { [key: string]: CommandInfo }; -} \ No newline at end of file