feat: add compile plugin info

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-12-17 16:58:37 +08:00
parent 0a8574621d
commit 69ef3b3979
6 changed files with 40 additions and 6 deletions

View File

@ -31,7 +31,8 @@ ms.api.command.tab.completer.error: "§6Player {player} §6exec §b{plugin} §6P
ms.plugin.initialize: "Initialization MiaoScript Plugin System: Plugin: {plugin} Loader: {loader}..."
ms.plugin.event.map: "Total {count} {type} Event Mapping Complate..."
ms.plugin.manager.scan: "Scanning Plugins in {folder} ..."
ms.plugin.manager.scan: "Scanner {scanner} Scanning Plugins in {folder} ..."
ms.plugin.manager.scan.finish: "Scanner {scanner} Found {size} Plugins in {folder} Start Build..."
ms.plugin.manager.initialize.error: "§6Plugin §b{name} §6initialize error §4{ex}"
ms.plugin.manager.stage: "{stage} {plugin} version {version} by {author}"
ms.plugin.manager.stage.exec: "[{plugin}] Exec {name} Stage {stage} When servers is {servers}..."
@ -39,6 +40,7 @@ ms.plugin.manager.stage.exec.error: "§6Plugin §b{plugin} §6exec §d{executor}
ms.plugin.manager.stage.load: "Loading"
ms.plugin.manager.stage.enable: "Enabling"
ms.plugin.manager.stage.disable: "Disabling"
ms.plugin.manager.build: "Plugin {name}({version}) Build Finish source: {file}({scanner}) loader: {loader} Cost: {cost}s."
ms.plugin.manager.build.error: "§6Load Plugin From §b{file} §6failed. §4Error: §c{error}"
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
ms.plugin.manager.build.not.extends: "§4Found error plugin §b{source} §4it's not extends interfaces.Plugin, the plugin will be ignore!"

View File

@ -32,7 +32,8 @@ ms.api.command.tab.completer.error: "§6玩家 §a{player} §6执行 §b{plugin}
ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加载器: {loader}..."
ms.plugin.event.map: "总计 {count} 个 {type} 事件 映射完成..."
ms.plugin.manager.scan: "扫描 {folder} 文件夹中插件..."
ms.plugin.manager.scan: "扫描器 {scanner} 扫描 {folder} 中的插件..."
ms.plugin.manager.scan.finish: "扫描器 {scanner} 在 {folder} 中 发现 {size} 个插件 开始构建..."
ms.plugin.manager.initialize.error: "§6插件 §b{name} §6初始化错误 §4{ex}"
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
ms.plugin.manager.stage.exec: "[{plugin}] 执行 {stage} 阶段函数 {name} 匹配类型 {servers}..."
@ -40,6 +41,7 @@ ms.plugin.manager.stage.exec.error: "§6插件 §b{plugin} §6执行 §d{executo
ms.plugin.manager.stage.load: "加载"
ms.plugin.manager.stage.enable: "启用"
ms.plugin.manager.stage.disable: "关闭"
ms.plugin.manager.build: "插件 {name}({version}) 构建完成 来源: {file}({scanner}) 引导: {loader} 构建耗时: {cost}s."
ms.plugin.manager.build.error: "§6从文件 §b{file} §6加载插件失败 §4错误: §c{error}"
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"

View File

@ -92,6 +92,16 @@ export class PluginConfigManager {
} else {
value = configLoader.load(base.read(metadata.file))
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(value, undefined, 4)}`)
if (metadata.default) {
let needSave = false
for (const key of Object.keys(metadata.default)) {
if (!value[key]) {
value[key] = metadata.default[key]
needSave = true
}
}
needSave && base.save(metadata.file, configLoader.dump(value))
}
}
this.defienConfigProp(plugin, metadata, value)
} catch (error) {

View File

@ -67,6 +67,10 @@ export namespace interfaces {
*
*/
version?: number
/**
*
*/
default?: any
/**
*
*/

View File

@ -81,9 +81,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
this.initialize()
for (const [, scanner] of this.sacnnerMap) {
try {
scanner.scan(folder).forEach(loadMetadata => {
console.i18n('ms.plugin.manager.scan', { scanner: scanner.type, folder })
let plugins = scanner.scan(folder)
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: plugins.length })
plugins.forEach(loadMetadata => {
try {
this.loadPlugin(scanner.load(loadMetadata))
this.loadAndRequirePlugin(loadMetadata)
} catch (error) {
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
console.ex(error)
@ -158,6 +161,20 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
}
private loadAndRequirePlugin(loadMetadata: plugin.PluginLoadMetadata) {
let startTime = Date.now()
let metadata = this.loadPlugin(loadMetadata.scanner.load(loadMetadata))
console.i18n('ms.plugin.manager.build', {
name: loadMetadata.metadata.name,
version: loadMetadata.metadata.version,
file: loadMetadata.file.toString().replace(root, ''),
scanner: loadMetadata.scanner.type,
loader: loadMetadata.loader.type,
cost: (Date.now() - startTime) / 1000
})
return metadata
}
/**
*
* @param file java.io.File
@ -165,7 +182,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
loadFromFile(file: string, scanner = this.sacnnerMap.get('file')): plugin.Plugin {
if (!file) { throw new Error('plugin file can\'t be undefiend!') }
if (!scanner) { throw new Error('plugin scanner can\'t be undefiend!') }
let metadata = this.loadPlugin(scanner.load(scanner.read(file)))
let metadata = this.loadAndRequirePlugin(scanner.read(file))
let plugin = this.buildPlugin(metadata)
this.load(plugin)
this.enable(plugin)

View File

@ -26,7 +26,6 @@ export class JSFileScanner implements plugin.PluginScanner {
private scanFolder(folder: any): string[] {
var files = []
console.i18n('ms.plugin.manager.scan', { folder })
this.checkUpdateFolder(folder)
// must check file is exist maybe is a illegal symbolic link file
fs.list(folder).forEach((path: any) => {