diff --git a/packages/i18n/languages/en.yml b/packages/i18n/languages/en.yml index b3e88bb2..4275073e 100644 --- a/packages/i18n/languages/en.yml +++ b/packages/i18n/languages/en.yml @@ -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!" diff --git a/packages/i18n/languages/zh_cn.yml b/packages/i18n/languages/zh_cn.yml index b7f15f91..0ae0ed73 100644 --- a/packages/i18n/languages/zh_cn.yml +++ b/packages/i18n/languages/zh_cn.yml @@ -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, 将不会被载入到服务器!" diff --git a/packages/plugin/src/config.ts b/packages/plugin/src/config.ts index 22ca8d5c..774c2541 100644 --- a/packages/plugin/src/config.ts +++ b/packages/plugin/src/config.ts @@ -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) { diff --git a/packages/plugin/src/interfaces.ts b/packages/plugin/src/interfaces.ts index 1e27b1c3..29b43bec 100644 --- a/packages/plugin/src/interfaces.ts +++ b/packages/plugin/src/interfaces.ts @@ -67,6 +67,10 @@ export namespace interfaces { * 配置文件版本号 */ version?: number + /** + * 默认配置 + */ + default?: any /** * 实体变量名称 */ diff --git a/packages/plugin/src/manager.ts b/packages/plugin/src/manager.ts index 34bce018..6e1091dc 100644 --- a/packages/plugin/src/manager.ts +++ b/packages/plugin/src/manager.ts @@ -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) diff --git a/packages/plugin/src/scanner/file-scanner.ts b/packages/plugin/src/scanner/file-scanner.ts index a712a0ce..c6785c9e 100644 --- a/packages/plugin/src/scanner/file-scanner.ts +++ b/packages/plugin/src/scanner/file-scanner.ts @@ -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) => {