feat: add plugin stage log

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-01 02:46:55 +08:00
parent c7f66d8252
commit 99dee28fd4
3 changed files with 24 additions and 14 deletions

View File

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

View File

@ -27,7 +27,9 @@
"mongodb": "^3.4.1" "mongodb": "^3.4.1"
}, },
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.2",
"@types/mongodb": "^3.3.14", "@types/mongodb": "^3.3.14",
"@types/socket.io": "^2.1.4",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0", "rimraf": "^3.0.0",
"ts-node-dev": "^1.0.0-pre.44", "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 { injectable, inject, postConstruct, Container, ContainerInstance } from '@ms/container'
import * as fs from '@ms/common/dist/fs' import * as fs from '@ms/common/dist/fs'
@ -21,7 +21,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
private pluginMap: Map<string, interfaces.Plugin> private pluginMap: Map<string, interfaces.Plugin>
@postConstruct() @postConstruct()
init() { initialize() {
if (this.pluginInstance !== null) { if (this.pluginInstance !== null) {
// 如果plugin不等于null 则代表是正式环境 // 如果plugin不等于null 则代表是正式环境
console.info(`Initialization MiaoScript Plugin System: ${this.pluginInstance} ...`) console.info(`Initialization MiaoScript Plugin System: ${this.pluginInstance} ...`)
@ -44,15 +44,21 @@ export class PluginManagerImpl implements plugin.PluginManager {
this.buildPlugins() 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 { load(...args: any[]): void {
this.checkAndGet(args[0]).forEach(pl => { this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
this.runCatch(pl, 'load') this.logStage(plugin, "Loading")
this.runCatch(pl, `${this.serverType}load`) this.runCatch(plugin, 'load')
this.runCatch(plugin, `${this.serverType}load`)
}) })
} }
enable(...args: any[]): void { 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, 'enable')
this.runCatch(plugin, `${this.serverType}enable`) this.runCatch(plugin, `${this.serverType}enable`)
this.registryCommand(plugin) this.registryCommand(plugin)
@ -61,11 +67,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
} }
disable(...args: any[]): void { disable(...args: any[]): void {
this.checkAndGet(args[0]).forEach(pl => { this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
this.runCatch(pl, 'disable') this.logStage(plugin, "Disabling")
this.runCatch(pl, `${this.serverType}disable`) this.runCatch(plugin, 'disable')
this.unregistryCommand(pl) this.runCatch(plugin, `${this.serverType}disable`)
this.unregistryListener(pl) this.unregistryCommand(plugin)
this.unregistryListener(plugin)
}) })
} }