feat: add plugin stage log

Signed-off-by: MiaoWoo <admin@yumc.pw>
backup
MiaoWoo 2020-02-01 02:46:55 +08:00
parent f6df0a2c47
commit 8ccfe499df
3 changed files with 24 additions and 14 deletions

View File

@ -6,9 +6,10 @@
"author": "MiaoWoo <admin@yumc.pw>",
"license": "MIT",
"scripts": {
"bs": "npx lerna bootstrap",
"clean": "npx lerna run clean",
"watch": "npx lerna run watch --parallel",
"build": "npx lerna run build --scope='@ms/!(plugins)'",
"watch": "npx lerna run watch --parallel --scope='@ms/!(manager)'",
"build": "npx lerna run build --scope='@ms/!(plugins|manager)'",
"build:plugins": "npx lerna run build --scope=@ms/plugins",
"lp": "npx lerna publish"
},
@ -18,4 +19,4 @@
"devDependencies": {
"lerna": "^3.20.2"
}
}
}

View File

@ -27,7 +27,9 @@
"mongodb": "^3.4.1"
},
"devDependencies": {
"@types/express": "^4.17.2",
"@types/mongodb": "^3.3.14",
"@types/socket.io": "^2.1.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"ts-node-dev": "^1.0.0-pre.44",

View File

@ -1,4 +1,4 @@
import { plugin, server, command, event, MiaoScriptConsole } from '@ms/api'
import { plugin, server, command, event } from '@ms/api'
import { injectable, inject, postConstruct, Container, ContainerInstance } from '@ms/container'
import * as fs from '@ms/common/dist/fs'
@ -21,7 +21,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
private pluginMap: Map<string, interfaces.Plugin>
@postConstruct()
init() {
initialize() {
if (this.pluginInstance !== null) {
// 如果plugin不等于null 则代表是正式环境
console.info(`Initialization MiaoScript Plugin System: ${this.pluginInstance} ...`)
@ -44,15 +44,21 @@ export class PluginManagerImpl implements plugin.PluginManager {
this.buildPlugins()
}
private logStage(plugin: interfaces.Plugin, stage: string) {
console.log(`[${plugin.description.name}] ${stage} ${plugin.description.name} version ${plugin.description.version} by ${plugin.description.author || 'Unknow'}`)
}
load(...args: any[]): void {
this.checkAndGet(args[0]).forEach(pl => {
this.runCatch(pl, 'load')
this.runCatch(pl, `${this.serverType}load`)
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
this.logStage(plugin, "Loading")
this.runCatch(plugin, 'load')
this.runCatch(plugin, `${this.serverType}load`)
})
}
enable(...args: any[]): void {
this.checkAndGet(args[0]).forEach(plugin => {
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
this.logStage(plugin, "Enabling")
this.runCatch(plugin, 'enable')
this.runCatch(plugin, `${this.serverType}enable`)
this.registryCommand(plugin)
@ -61,11 +67,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
disable(...args: any[]): void {
this.checkAndGet(args[0]).forEach(pl => {
this.runCatch(pl, 'disable')
this.runCatch(pl, `${this.serverType}disable`)
this.unregistryCommand(pl)
this.unregistryListener(pl)
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
this.logStage(plugin, "Disabling")
this.runCatch(plugin, 'disable')
this.runCatch(plugin, `${this.serverType}disable`)
this.unregistryCommand(plugin)
this.unregistryListener(plugin)
})
}