feat: add compile plugin info
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
aa182fb169
commit
f35c8cd3fb
@ -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.initialize: "Initialization MiaoScript Plugin System: Plugin: {plugin} Loader: {loader}..."
|
||||||
ms.plugin.event.map: "Total {count} {type} Event Mapping Complate..."
|
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.initialize.error: "§6Plugin §b{name} §6initialize error §4{ex}"
|
||||||
ms.plugin.manager.stage: "{stage} {plugin} version {version} by {author}"
|
ms.plugin.manager.stage: "{stage} {plugin} version {version} by {author}"
|
||||||
ms.plugin.manager.stage.exec: "[{plugin}] Exec {name} Stage {stage} When servers is {servers}..."
|
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.load: "Loading"
|
||||||
ms.plugin.manager.stage.enable: "Enabling"
|
ms.plugin.manager.stage.enable: "Enabling"
|
||||||
ms.plugin.manager.stage.disable: "Disabling"
|
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.error: "§6Load Plugin From §b{file} §6failed. §4Error: §c{error}"
|
||||||
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
|
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!"
|
ms.plugin.manager.build.not.extends: "§4Found error plugin §b{source} §4it's not extends interfaces.Plugin, the plugin will be ignore!"
|
||||||
|
@ -32,7 +32,8 @@ ms.api.command.tab.completer.error: "§6玩家 §a{player} §6执行 §b{plugin}
|
|||||||
|
|
||||||
ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加载器: {loader}..."
|
ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加载器: {loader}..."
|
||||||
ms.plugin.event.map: "总计 {count} 个 {type} 事件 映射完成..."
|
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.initialize.error: "§6插件 §b{name} §6初始化错误 §4{ex}"
|
||||||
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
|
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
|
||||||
ms.plugin.manager.stage.exec: "[{plugin}] 执行 {stage} 阶段函数 {name} 匹配类型 {servers}..."
|
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.load: "加载"
|
||||||
ms.plugin.manager.stage.enable: "启用"
|
ms.plugin.manager.stage.enable: "启用"
|
||||||
ms.plugin.manager.stage.disable: "关闭"
|
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.error: "§6从文件 §b{file} §6加载插件失败 §4错误: §c{error}"
|
||||||
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
||||||
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
|
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
|
||||||
|
@ -92,6 +92,16 @@ export class PluginConfigManager {
|
|||||||
} else {
|
} else {
|
||||||
value = configLoader.load(base.read(metadata.file))
|
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)}`)
|
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)
|
this.defienConfigProp(plugin, metadata, value)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -67,6 +67,10 @@ export namespace interfaces {
|
|||||||
* 配置文件版本号
|
* 配置文件版本号
|
||||||
*/
|
*/
|
||||||
version?: number
|
version?: number
|
||||||
|
/**
|
||||||
|
* 默认配置
|
||||||
|
*/
|
||||||
|
default?: any
|
||||||
/**
|
/**
|
||||||
* 实体变量名称
|
* 实体变量名称
|
||||||
*/
|
*/
|
||||||
|
@ -81,9 +81,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
this.initialize()
|
this.initialize()
|
||||||
for (const [, scanner] of this.sacnnerMap) {
|
for (const [, scanner] of this.sacnnerMap) {
|
||||||
try {
|
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 {
|
try {
|
||||||
this.loadPlugin(scanner.load(loadMetadata))
|
this.loadAndRequirePlugin(loadMetadata)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
|
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
|
||||||
console.ex(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
|
* @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 {
|
loadFromFile(file: string, scanner = this.sacnnerMap.get('file')): plugin.Plugin {
|
||||||
if (!file) { throw new Error('plugin file can\'t be undefiend!') }
|
if (!file) { throw new Error('plugin file can\'t be undefiend!') }
|
||||||
if (!scanner) { throw new Error('plugin scanner 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)
|
let plugin = this.buildPlugin(metadata)
|
||||||
this.load(plugin)
|
this.load(plugin)
|
||||||
this.enable(plugin)
|
this.enable(plugin)
|
||||||
|
@ -26,7 +26,6 @@ export class JSFileScanner implements plugin.PluginScanner {
|
|||||||
|
|
||||||
private scanFolder(folder: any): string[] {
|
private scanFolder(folder: any): string[] {
|
||||||
var files = []
|
var files = []
|
||||||
console.i18n('ms.plugin.manager.scan', { folder })
|
|
||||||
this.checkUpdateFolder(folder)
|
this.checkUpdateFolder(folder)
|
||||||
// must check file is exist maybe is a illegal symbolic link file
|
// must check file is exist maybe is a illegal symbolic link file
|
||||||
fs.list(folder).forEach((path: any) => {
|
fs.list(folder).forEach((path: any) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user