feat: update typescript version

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2021-12-26 01:21:06 +08:00
parent 72173b4778
commit 5ed61829e1
68 changed files with 234 additions and 161 deletions

View File

@ -19,10 +19,10 @@
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"@types/js-yaml": "^4.0.2",
"@types/js-yaml": "^4.0.5",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^4.3.5"
"typescript": "^4.5.3"
},
"dependencies": {
"@ccms/api": "^0.17.0",

View File

@ -44,15 +44,16 @@ export class PluginCommandManager {
let cmdSubCache = Object.keys(pluginInstance.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
if (cmd.autoMain) {
cmdExecutor = (sender: any, command: string, args: string[]) => {
let subcommand = args[0] || 'help'
let subcommand = args[0]
let cmdKey = 'cmd' + subcommand
if (!pluginInstance[cmdKey]) {
pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand)
pluginInstance['cmdhelp'] && pluginInstance.logger.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`)
return
if (pluginInstance[cmdKey]) {
args.shift()
return pluginInstance[cmdKey].apply(pluginInstance, [sender, ...args])
} else if (pluginInstance['cmdmain']) {
return pluginInstance['cmdmain'].apply(pluginInstance, [sender, ...args])
}
args.shift()
return pluginInstance[cmdKey].apply(pluginInstance, [sender, ...args])
pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand)
pluginInstance['cmdhelp'] && pluginInstance.logger.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`)
}
let originCompleter = cmdCompleter
cmdCompleter = (sender: any, command: string, args: string[]) => {

View File

@ -83,22 +83,24 @@ export class PluginConfigManager {
private loadConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
try {
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
let configLoader = this.getConfigLoader(metadata.format)
let defaultValue = metadata.default ?? plugin[metadata.variable]
let configValue = defaultValue
if (!fs.exists(metadata.file)) {
base.save(metadata.file, configLoader.dump(defaultValue))
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format })
} else {
configValue = configLoader.load(base.read(metadata.file)) || {}
if (defaultValue && this.setDefaultValue(configValue, defaultValue)) {
base.save(metadata.file, configLoader.dump(configValue))
let configValue = defaultValue || {}
if (defaultValue) {
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
let configLoader = this.getConfigLoader(metadata.format)
if (!fs.exists(metadata.file)) {
base.save(metadata.file, configLoader.dump(defaultValue))
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format })
} else {
configValue = configLoader.load(base.read(metadata.file)) || {}
if (defaultValue && this.setDefaultValue(configValue, defaultValue)) {
base.save(metadata.file, configLoader.dump(configValue))
}
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(configValue, undefined, 4).substr(0, 500)}`)
}
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(configValue, undefined, 4).substr(0, 500)}`)
}
this.defienConfigProp(plugin, metadata, configValue)
} catch (error) {
} catch (error: any) {
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error })
console.ex(error)
}
@ -111,8 +113,8 @@ export class PluginConfigManager {
if (!Object.prototype.hasOwnProperty.call(configValue, key)) {
configValue[key] = defaultValue[key]
needSave = true
} else if (Object.prototype.toString.call(configValue[key]) == "[object Object]") {
// 对象需要递归检测
} else if (Object.prototype.toString.call(configValue[key]) == "[object Object]" && !Object.prototype.hasOwnProperty.call(defaultValue[key], '____ignore____')) {
// 对象需要递归检测 如果对象内存在 ____ignore____ 那就忽略设置
needSave ||= this.setDefaultValue(configValue[key], defaultValue[key])
}
}
@ -126,7 +128,7 @@ export class PluginConfigManager {
base.save(metadata.file, result)
console.debug(`[${plugin.description.name}] Save Config ${metadata.variable} to file ${metadata.file} =>\n${result.substr(0, 500)}`)
return true
} catch (error) {
} catch (error: any) {
console.i18n("ms.plugin.manager.config.save.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error })
console.ex(error)
return false

View File

@ -2,12 +2,11 @@ import './scanner/file-scanner'
import './loader/ioc-loader'
import './loader/basic-loader'
export * from './config'
export * from './manager'
export * from './decorators'
export * from './interfaces'
export { PluginConfig } from './config'
export {
plugin as JSPlugin,
cmd as Cmd,

View File

@ -2,6 +2,8 @@ import { server, MiaoScriptConsole, event, plugin } from "@ccms/api"
import { injectable, inject, postConstruct } from "@ccms/container"
import { getPluginMetadata } from "./utils"
const File = Java.type('java.io.File')
export namespace interfaces {
@injectable()
export abstract class Plugin implements plugin.Plugin {
@ -20,6 +22,12 @@ export namespace interfaces {
this.logger = new this.Console(this.description.prefix || this.description.name)
}
public getDataFolder() {
let parent = new File(this.description.source).parent
let dataFolder = new File(parent, this.description.name)
return dataFolder.getAbsolutePath()
}
public load() { }
public enable() { }
public disable() { }

View File

@ -38,7 +38,7 @@ export class IocLoader implements plugin.PluginLoader {
console.i18n('ms.plugin.manager.build.not.extends', { source: metadata.source })
return
}
} catch (ex) {
} catch (ex: any) {
console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex })
console.ex(ex)
}
@ -81,10 +81,10 @@ export class IocLoader implements plugin.PluginLoader {
console.i18n("ms.plugin.manager.stage.exec", { plugin: pluginInstance.description.name, name: stage.executor, stage: stageName, servers: stage.servers })
try {
pluginInstance[stage.executor].apply(pluginInstance)
} catch (error) {
} catch (error: any) {
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pluginInstance.description.name, executor: stage.executor, error })
console.ex(error)
}
}
}
}
}

View File

@ -92,12 +92,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
plugins.forEach(loadMetadata => {
try {
this.loadAndRequirePlugin(loadMetadata)
} catch (error) {
} catch (error: any) {
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
console.ex(error)
}
})
} catch (error) {
} catch (error: any) {
console.error(`plugin scanner ${scanner.type} occurred error ${error}`)
console.ex(error)
}
@ -123,7 +123,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
this.runCatch(plugin, `${this.serverType}${stage}`)
plugin.description.loadMetadata.loader[stage]?.(plugin)
process.emit(`plugin.after.${stage}`, plugin)
} catch (ex) {
} catch (ex: any) {
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: plugin.description.name, executor: stage, error: ex })
if (global.debug) { console.ex(ex) }
}
@ -136,7 +136,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
for (const [, loader] of this.loaderMap) {
if (this.loaderRequirePlugin(loadMetadata, loader)?.loaded) return loadMetadata.metadata
}
} catch (error) {
} catch (error: any) {
console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error })
console.ex(error)
}
@ -156,7 +156,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
metadata.loadMetadata = loadMetadata
}
return loadMetadata
} catch (error) {
} catch (error: any) {
if (global.debug) {
console.console(`§6Loader §b${loader.type} §6load §a${loadMetadata.file} §cerror. §4Err: §c${error}`)
console.ex(error)
@ -228,7 +228,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
private runCatch(pl: any, func: string) {
try {
if (pl[func]) pl[func].call(pl)
} catch (ex) {
} catch (ex: any) {
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pl.description.name, executor: func, error: ex })
console.ex(ex)
}
@ -279,7 +279,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
this.instanceMap.set(metadata.name, pluginInstance)
return pluginInstance
} catch (error) {
} catch (error: any) {
console.console(`§4无法加载插件 §b${metadata.name} §4构建插件失败!`)
console.ex(error)
}