From 4c0a77ed237e8cee4545eed37f4895e5b24e1898 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 20 Jun 2020 16:38:14 +0800 Subject: [PATCH] feat: add amqp & web interface Signed-off-by: MiaoWoo --- packages/api/src/console.ts | 116 ++++++------ packages/api/src/interfaces/amqp.ts | 7 + packages/api/src/interfaces/index.ts | 4 +- packages/api/src/interfaces/plugin.ts | 127 ++++++++++--- packages/api/src/interfaces/server/index.ts | 4 +- packages/api/src/interfaces/web.ts | 3 + packages/core/src/index.ts | 8 +- packages/nashorn/build.sh | 12 -- packages/nashorn/src/build.ts | 197 -------------------- packages/nashorn/src/index.ts | 107 ++++++----- packages/plugin/src/interfaces.ts | 4 + 11 files changed, 236 insertions(+), 353 deletions(-) create mode 100644 packages/api/src/interfaces/amqp.ts create mode 100644 packages/api/src/interfaces/web.ts delete mode 100755 packages/nashorn/build.sh delete mode 100644 packages/nashorn/src/build.ts diff --git a/packages/api/src/console.ts b/packages/api/src/console.ts index 2af5c37e..2ce46088 100644 --- a/packages/api/src/console.ts +++ b/packages/api/src/console.ts @@ -2,10 +2,10 @@ import i18m from '@ccms/i18n' import { SourceMapBuilder } from 'source-map-builder' import * as base64 from 'base64-js' -const Arrays = Java.type('java.util.Arrays'); -const Level = Java.type('java.util.logging.Level'); -const Paths = Java.type('java.nio.file.Paths'); -const ignoreLogPrefix = ['java.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.', 'io.netty.', 'org.spongepowered.']; +const Arrays = Java.type('java.util.Arrays') +const Level = Java.type('java.util.logging.Level') +const Paths = Java.type('java.nio.file.Paths') +const ignoreLogPrefix = ['java.', 'javax.', 'sun.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.', 'io.netty.', 'org.spongepowered.', 'org.apache', 'org.springframework'] enum LogLevel { ALL, @@ -19,19 +19,19 @@ enum LogLevel { } export class MiaoScriptConsole implements Console { - Console: NodeJS.ConsoleConstructor; + Console: NodeJS.ConsoleConstructor - private static sourceMaps: { [key: string]: SourceMapBuilder } = {}; - private static sourceFileMaps: { [key: string]: string } = {}; - private _name: string = ''; - private _level: LogLevel = LogLevel.INFO; + private static sourceMaps: { [key: string]: SourceMapBuilder } = {} + private static sourceFileMaps: { [key: string]: string } = {} + private _name: string = '' + private _level: LogLevel = LogLevel.INFO - protected logger: any; - protected prefix: string = '§6[§bMiaoScript§6]§r '; + protected logger: any + protected prefix: string = '§6[§bMiaoScript§6]§r ' constructor(name?: string) { - this.name = name; - this.logger = global.logger; + this.name = name + this.logger = global.logger if (global.debug) { this._level = LogLevel.DEBUG } @@ -41,36 +41,36 @@ export class MiaoScriptConsole implements Console { } get name() { - return this._name; + return this._name } set name(name: string) { if (name) { - this._name = `[${name}] `; + this._name = `[${name}] ` // noinspection JSUnusedGlobalSymbols - this.prefix = `§6[§cMS§6][§b${name}§6]§r `; + this.prefix = `§6[§cMS§6][§b${name}§6]§r ` } } log(...args: any[]): void { - this.logger.info(this.name + args.join(' ')); + this.logger.info(this.name + args.join(' ')) } info(...args: any[]) { - this.logger.info(this.name + args.join(' ')); + this.logger.info(this.name + args.join(' ')) } warn(...args: any[]) { - this.logger.warning(this.name + args.join(' ')); + this.logger.warning(this.name + args.join(' ')) } error(...args: any[]) { - this.logger.log(Level.SEVERE, this.name + args.join(' ')); + this.logger.log(Level.SEVERE, this.name + args.join(' ')) } debug(...args: any[]) { if (global.debug) { - this.logger.info(this.name + '[DEBUG] ' + args.join(' ')); + this.logger.info(this.name + '[DEBUG] ' + args.join(' ')) } } trace(...args: any[]): void { if (this._level <= LogLevel.TRACE) { - this.logger.info(this.name + '[TRACE] ' + args.join(' ')); + this.logger.info(this.name + '[TRACE] ' + args.join(' ')) } } sender(...args) { @@ -95,29 +95,29 @@ export class MiaoScriptConsole implements Console { if (fileName.endsWith('js')) { if (MiaoScriptConsole.sourceMaps[fileName] === undefined) { MiaoScriptConsole.sourceMaps[fileName] = null - let sourceLine = base.read(fileName).split('\n'); + let sourceLine = base.read(fileName).split('\n') let lastLine = sourceLine[sourceLine.length - 1] if (lastLine.startsWith('//# sourceMappingURL=')) { - let sourceContent = null; - let sourceMappingURL = lastLine.split('sourceMappingURL=', 2)[1]; - if (sourceMappingURL.startsWith('data:application/json;base64,')) { + let sourceContent = null + let sourceMappingURL = lastLine.split('sourceMappingURL=', 2)[1] + if (sourceMappingURL.startsWith('data:application/jsonbase64,')) { sourceContent = String.fromCharCode(...Array.from(base64.toByteArray(sourceMappingURL.split(',', 2)[1]))) } else if (sourceMappingURL.startsWith('http')) { // TODO } else { - let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile(); + let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile() if (file.exists()) { sourceContent = base.read(file) } } if (sourceContent) { MiaoScriptConsole.sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent)) - MiaoScriptConsole.sourceFileMaps[fileName] = Paths.get(fileName, '..', MiaoScriptConsole.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath(); + MiaoScriptConsole.sourceFileMaps[fileName] = Paths.get(fileName, '..', MiaoScriptConsole.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath() } } } if (MiaoScriptConsole.sourceMaps[fileName]) { - let sourceMapping = MiaoScriptConsole.sourceMaps[fileName].getSource(lineNumber, 25, true, true); + let sourceMapping = MiaoScriptConsole.sourceMaps[fileName].getSource(lineNumber, 25, true, true) fileName = MiaoScriptConsole.sourceFileMaps[fileName] - if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine; } + if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine } } } } catch (error) { @@ -129,8 +129,8 @@ export class MiaoScriptConsole implements Console { } } stack(ex: Error, color: boolean = true): string[] { - let stack = ex.getStackTrace(); - let cache = [(color ? '§c' : '') + ex]; + let stack = ex.getStackTrace() + let cache = [(color ? '§c' : '') + ex] //@ts-ignore if (stack.class) { stack = Arrays.asList(stack) @@ -146,8 +146,8 @@ export class MiaoScriptConsole implements Console { cache.push(` -> ${fileName}:${lineNumber} => ${trace.methodName}`) } } else { - let className = trace.className; - var fileName = trace.fileName as string; + let className = trace.className + var fileName = trace.fileName as string if (className.startsWith('jdk.nashorn.internal.scripts')) { className = className.substr(className.lastIndexOf('$') + 1) var { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber) @@ -155,74 +155,74 @@ export class MiaoScriptConsole implements Console { } else { for (let prefix in ignoreLogPrefix) { if (className.startsWith(ignoreLogPrefix[prefix])) { - return; + return } } } if (color) { - cache.push(` §e->§c ${className}.${trace.methodName}(§4${fileName}:${lineNumber}§c)`); + cache.push(` §e->§c ${className}.${trace.methodName}(§4${fileName}:${lineNumber}§c)`) } else { - cache.push(` -> ${className}.${trace.methodName}(${fileName}:${lineNumber})`); + cache.push(` -> ${className}.${trace.methodName}(${fileName}:${lineNumber})`) } } - }); - return cache; + }) + return cache } assert(value: any, message?: string, ...optionalParams: any[]): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } clear(): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } count(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } countReset(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } dir(obj: any, options?: NodeJS.InspectOptions): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } dirxml(...data: any[]): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } group(...label: any[]): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } groupCollapsed(...label: any[]): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } groupEnd(): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } table(tabularData: any, properties?: string[]): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } time(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } timeEnd(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } timeLog(label?: string, ...data: any[]): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } markTimeline(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } profile(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } profileEnd(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } timeStamp(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } timeline(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } timelineEnd(label?: string): void { - throw new Error("Method not implemented."); + throw new Error("Method not implemented.") } } diff --git a/packages/api/src/interfaces/amqp.ts b/packages/api/src/interfaces/amqp.ts new file mode 100644 index 00000000..0d305015 --- /dev/null +++ b/packages/api/src/interfaces/amqp.ts @@ -0,0 +1,7 @@ +export namespace amqp { + export const Manager = Symbol('AmqpManager') + export namespace rabbit { + export const Admin = Symbol('RabbitAdmin') + export const Template = Symbol('RabbitTemplate') + } +} \ No newline at end of file diff --git a/packages/api/src/interfaces/index.ts b/packages/api/src/interfaces/index.ts index 437c0999..24fb9409 100644 --- a/packages/api/src/interfaces/index.ts +++ b/packages/api/src/interfaces/index.ts @@ -1,3 +1,5 @@ +export * from './web' +export * from './amqp' export * from './plugin' export * from './server' -export * from './database' \ No newline at end of file +export * from './database' diff --git a/packages/api/src/interfaces/plugin.ts b/packages/api/src/interfaces/plugin.ts index bd5bebfe..60780fa9 100644 --- a/packages/api/src/interfaces/plugin.ts +++ b/packages/api/src/interfaces/plugin.ts @@ -2,74 +2,147 @@ export namespace plugin { /** * MiaoScript Plugin */ - export const Plugin = Symbol("Plugin"); + export const Plugin = Symbol("Plugin") /** * MiaoScript Plugin Folder */ - export const PluginFolder = Symbol("PluginFolder"); + export const PluginFolder = Symbol("PluginFolder") /** * Runtime Plugin Instance */ - export const PluginInstance = Symbol("PluginInstance"); + export const PluginInstance = Symbol("PluginInstance") /** * MiaoScript Plugin Manager Symbol */ - export const PluginManager = Symbol("PluginManager"); + export const PluginManager = Symbol("PluginManager") /** * MiaoScript Plugin Manager Interface */ export interface PluginManager { - scan(folder: string): void; - build(): void; - loadFromFile(file: string): Plugin; - load(...args: any[]): void; - enable(...args: any[]): void; - disable(...args: any[]): void; - reload(...args: any[]): void; - getPlugin(name: string): plugin.Plugin; - getPlugins(): Map; + scan(folder: string): void + build(): void + loadFromFile(file: string, scanner?: plugin.PluginScanner): Plugin + load(...args: any[]): void + enable(...args: any[]): void + disable(...args: any[]): void + reload(...args: any[]): void + getPlugin(name: string): plugin.Plugin + getPlugins(): Map + } + export const PluginScanner = Symbol("PluginScanner") + /** + * 插件扫描器 + */ + export interface PluginScanner { + /** + * 扫描器类型 + */ + type: string + /** + * 扫描插件 返回插件加载列表 + * @param target 扫描目标 + */ + scan(target: any): string[] + /** + * 加载扫描到的目标 + * @param target 加载目标 + */ + load(target: any): any + } + export const PluginLoader = Symbol("PluginLoader") + /** + * 插件加载器 + */ + export interface PluginLoader { + /** + * 加载器类型 + */ + type: string + /** + * 加载插件 获取元数据 + * @param target 加载目标 + * @param result 扫描器加载的结果 + */ + require(target: any, result: any): PluginMetadata + /** + * 构建插件 + * @param metadata 插件元信息 + */ + build(metadata: any): Plugin + /** + * Load 阶段 + * @param plugin 插件 + */ + load(plugin: Plugin): void + /** + * Enable 阶段 + * @param plugin 插件 + */ + enable(plugin: Plugin): void + /** + * Disable 阶段 + * @param plugin 插件 + */ + disable(plugin: Plugin): void + /** + * Reload 阶段 + * @param plugin 插件 + */ + reload(plugin: Plugin): void } export interface Plugin { - description: PluginMetadata; - logger: Console; - load(): void; - enable(): void; - disable(): void; + description: PluginMetadata + logger: Console + load(): void + enable(): void + disable(): void } - interface BaseMetadata { + export interface BaseMetadata { /** * 名称 为空则为对象名称 */ - name?: string; + name?: string /** * 支持的服务器列表 为空则代表所有 */ - servers?: string[]; + servers?: string[] } export interface PluginMetadata extends BaseMetadata { /** * 插件名称 */ - name: string; + name: string /** * 前缀 */ - prefix?: string; + prefix?: string /** * 插件版本 */ - version: string; + version: string /** * 插件版本 */ - author: string | string[]; + author: string | string[] /** * 插件源文件 必须指定为 __filename */ - source: string; + source: string + /** + * 插件类型 默认为 ioc 执行 MiaoScript 加载逻辑 + */ + type?: string + /** + * 插件扫描器 + */ + scanner?: PluginScanner + /** + * 插件加载器 + */ + loader?: PluginLoader /** * 插件本体 */ - target?: any; + target?: any } } diff --git a/packages/api/src/interfaces/server/index.ts b/packages/api/src/interfaces/server/index.ts index 1c52d4c4..dbbefc7d 100644 --- a/packages/api/src/interfaces/server/index.ts +++ b/packages/api/src/interfaces/server/index.ts @@ -38,7 +38,7 @@ export namespace server { getNettyPipeline(): any getRootLogger(): any sendJson(sender: string | any, json: object | string): void - tabComplete?(sender: string | any, input: string, index?: number) + tabComplete?(sender: string | any, input: string, index?: number): string[] } @injectable() export abstract class ReflectServer implements server.Server { @@ -88,7 +88,7 @@ export namespace server { sendJson(sender: any, json: string | object): void { throw new Error("Method not implemented.") } - tabComplete?(sender: any, input: string, index?: number) { + tabComplete?(sender: any, input: string, index?: number): string[] { throw new Error("Method not implemented.") } protected reflect() { diff --git a/packages/api/src/interfaces/web.ts b/packages/api/src/interfaces/web.ts new file mode 100644 index 00000000..1fd97247 --- /dev/null +++ b/packages/api/src/interfaces/web.ts @@ -0,0 +1,3 @@ +export namespace web { + export const Server = Symbol('Server') +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 6a3fc1a6..a5495b37 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -26,17 +26,16 @@ class MiaoScriptCore { } loadServerConsole() { - global.setGlobal('eventCenter', new EventEmitter(), { writable: false, configurable: false }); //@ts-ignore global.setGlobal('console', new this.Console(), { writable: false, configurable: false }) } loadTaskFunction() { global.setGlobal('setTimeout', (func: Function, tick: number, ...args: any[]) => { - this.taskManager.create(func).later(tick).submit(...args) + return this.taskManager.create(func).later(tick).submit(...args) }, { writable: false, configurable: false }) global.setGlobal('setInterval', (func: Function, tick: number, ...args: any[]) => { - this.taskManager.create(func).timer(tick).submit(...args) + return this.taskManager.create(func).timer(tick).submit(...args) }, { writable: false, configurable: false }) } @@ -54,9 +53,8 @@ class MiaoScriptCore { console.i18n("ms.core.engine.disable") this.pluginManager.disable(this.pluginManager.getPlugins()) this.taskManager.disable() + process.emit('exit', 0) process.exit(0) - //@ts-ignore - require.disable() } } diff --git a/packages/nashorn/build.sh b/packages/nashorn/build.sh deleted file mode 100755 index a4028ea8..00000000 --- a/packages/nashorn/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -# sponge bukkit jdk bungee nukkit -TYPE=nukkit -TARGET=../types/dist/typings -npx tsc src/build.ts --outDir dist -cd dist -rm -rf temp -mkdir -p temp -node build.js ${TYPE} -cd ../ -rm -rf ${TARGET}/${TYPE} -mkdir -p ${TARGET}/${TYPE} -cp dist/temp/* ${TARGET}/${TYPE}/ -R diff --git a/packages/nashorn/src/build.ts b/packages/nashorn/src/build.ts deleted file mode 100644 index 1ff4ac06..00000000 --- a/packages/nashorn/src/build.ts +++ /dev/null @@ -1,197 +0,0 @@ -import * as fs from "fs" - -function convertJson2TypeDefiend(infile: string, outDir: string) { - const file = infile.substr(0, infile.length - 5) - const json = fs.readFileSync(`${inDir}/${file}.json`).toString() - const obj = JSON.parse(json) - const qnas: string[] = obj.qualifiedName.split(".") - let closeBuk = 0 - let temp = `declare namespace ${mappingNamespace(qnas[0])} {\n` - closeBuk++ - const nms = qnas.slice(1, qnas.length - 1) - for (const nm of nms) { - temp += `${' '.repeat(closeBuk)}namespace ${mappingNamespace(nm)} {\n` - closeBuk++ - } - let classModifier = formatClassModifier(obj.modifiers) - temp += `${' '.repeat(closeBuk)}// @ts-ignore\n` - temp += `${' '.repeat(closeBuk)}${classModifier}${qnas[qnas.length - 1]}` - let isInterface = classModifier.includes('interface') - let safeInterface = [] - for (const ifs of obj.interfaces) { - // if (!ifs.qualifiedName.startsWith('java')) { - safeInterface.push(ifs) - // } - } - if (isInterface) { - if (safeInterface.length > 0) { - temp += ' extends ' - for (const ifs of safeInterface) { - temp += ifs.qualifiedName - temp += ', ' - } - temp = temp.substr(0, temp.length - 2) - } - } else { - temp += `${(obj.superclass) ? (' extends ' + (obj.superclass.qualifiedName == "" ? "object" : obj.superclass.qualifiedName)) : ''}` - if (safeInterface.length > 0) { - temp += ' implements ' - for (const ifs of safeInterface) { - temp += ifs.qualifiedName - temp += ', ' - } - temp = temp.substr(0, temp.length - 2) - } - } - temp += ' {\n' - closeBuk++ - for (const constructor of obj.constructors) { - temp += `${formatDoc(constructor.docString, closeBuk)}${' '.repeat(closeBuk)}// @ts-ignore\n${' '.repeat(closeBuk)}constructor(${formatParameters(constructor.parameters)})\n` - } - - let members = {} - - let methods = '' - for (const method of obj.methods) { - let methodModifier = isInterface ? '' : replaceModifiers(method.modifiers, classModifier.includes('abstract')) - if (members[method.name] && methodModifier.includes('abstract')) { - continue - } - members[method.name] = methodModifier - methods += `${formatDoc(method.docString, closeBuk)}${' '.repeat(closeBuk)}// @ts-ignore\n${' '.repeat(closeBuk)}${methodModifier ? (methodModifier + ' ') : ''}${method.name}(${formatParameters(method.parameters)}): ${mappingType(method.returnType, false)};\n` - } - - let fields = '' - for (const field of obj.fields) { - if (members[field.name]) { - continue - } - fields += `${' '.repeat(closeBuk)}// @ts-ignore\n${' '.repeat(closeBuk)}${isInterface ? '' : replaceModifiers(field.modifiers)} ${field.name}: ${mappingType(field.type)};\n` - } - - temp += fields + methods - - for (let index = 0; index < closeBuk; index++) { - temp += `${' '.repeat(closeBuk - index - 1)}}\n` - } - - fs.writeFileSync(`${outDir}/${file}.${suffix}`, temp) - return `${file}.${suffix}` -} - -function formatClassModifier(modifiers: string) { - let tempm = modifiers.replace('public', '').replace('static', '').replace('final', '').trim() - if (!modifiers.includes('interface')) { - tempm += tempm.length == 0 ? 'class' : ' class' - } - return tempm.length > 0 ? (tempm + ' ') : '' -} - -function formatDoc(doc: string, closeBuk: number) { - let middleDoc = '' - for (const line of doc.split('\n')) { - if (line.trim().length != 0) { - middleDoc += `${' '.repeat(closeBuk)} * ${line.trim()}\n` - } - } - return middleDoc.length > 0 ? `${' '.repeat(closeBuk)}/**\n${middleDoc}${' '.repeat(closeBuk)} */\n` : '' -} - -function replaceModifiers(modifiers: string, absClass = false): string { - // modifiers = modifiers.replace(' final', ' readonly') - modifiers = modifiers.split(" final")[0] - modifiers = modifiers.split(" native")[0] - modifiers = modifiers.split(" volatile")[0] - modifiers = modifiers.split(" transient")[0] - modifiers = modifiers.split(" synchronized")[0] - if (!absClass) { - modifiers = modifiers.split(" abstract")[0] - } - return modifiers -} - -function formatParameters(params: any[]) { - if (!params.length) return '' - let tempParam = '' - for (let i = 0; i < params.length - 1; i++) { - const p = params[i]; - tempParam += `${mappingName(p.name)}: ${mappingType(p.type)}, ` - } - let lastParam = params[params.length - 1] - let lastMapType = mappingType(lastParam.type) - if (lastMapType.endsWith("[]")) { - tempParam += `...${mappingName(lastParam.name)}: ${lastMapType}` - } else { - tempParam += `${mappingName(lastParam.name)}: ${lastMapType}` - } - return tempParam -} - -const nameMap = {} -nameMap['function'] = 'func' -nameMap['in'] = 'input' -nameMap['var'] = 'variable' -nameMap['enum'] = 'enumerate' -nameMap['export'] = 'exporter' -nameMap['is'] = 'jis' -nameMap['with'] = 'jwith' - -function mappingNamespace(name: string) { - return typeof nameMap[name] == "string" ? name + '$' : name || '' -} - -function mappingName(name: string) { - return typeof nameMap[name] == "string" ? nameMap[name] : name || '' -} - -const typeMap = [] -typeMap['int'] = 'number /*int*/' -typeMap['java.lang.Integer'] = "number" -typeMap['byte'] = 'number /*byte*/' -typeMap['java.lang.Byte'] = "number" -typeMap['double'] = 'number /*double*/' -typeMap['java.lang.Double'] = "number" -typeMap['short'] = 'number /*short*/' -typeMap['java.lang.Short'] = "number" -typeMap['float'] = 'number /*float*/' -typeMap['java.lang.Float'] = "number" -typeMap['long'] = 'number /*long*/' -typeMap['java.lang.Long'] = "number" -typeMap[''] = 'any' -typeMap['char'] = 'string' -typeMap['java.lang.String'] = "string" -typeMap['java.lang.Object'] = "any" -typeMap['java.util.List'] = "Array" -typeMap['java.util.Set'] = "Array" -typeMap['java.util.Collection'] = "Array" -typeMap['java.lang.Throwable'] = "Error" -// typeMap['java.util.Date'] = 'any /*java.util.Date*/' -// typeMap['java.util.List'] = 'any[] /*java.util.List*/' -// typeMap['java.util.Set'] = 'any[] /*java.util.Set*/' -// typeMap['java.util.Collection'] = 'any[] /*java.util.Collection*/' -// typeMap['java.util.Map'] = 'Map /*java.util.Map*/' - -type JavaType = { - qualifiedName: string, - name: string, - type: string -} - -function mappingType(type: JavaType, isParam: boolean = true): string { - if (!type || !type.type) { return 'any' } - let outType = typeMap[type.qualifiedName] || type.qualifiedName || 'any' - let tsType = type.type.replace(type.qualifiedName, outType).replace('function', 'function$') - return isParam && type.type !== tsType && type.type.includes('.') ? `${type.type} | ${tsType}` : tsType -} - -var args = process.argv.splice(2) - -const suffix = 'd.ts' -const inDir = `../docs/${args[0]}` -const outDir = "./temp" -const files = fs.readdirSync(inDir) -let index = '' -for (const file of files) { - index += `/// \n` -} -fs.writeFileSync(`${outDir}/index.${suffix}`, index) diff --git a/packages/nashorn/src/index.ts b/packages/nashorn/src/index.ts index 4485c984..8026381c 100644 --- a/packages/nashorn/src/index.ts +++ b/packages/nashorn/src/index.ts @@ -1,80 +1,85 @@ declare global { - const __FILE__: string; - const __LINE__: number; - const __DIR__: string; - let Packages: any; + const __FILE__: string + const __LINE__: number + const __DIR__: string + const Packages: any - function print(...message: any[]): void; - function load(script: string | object); - function loadWithNewGlobal(script: string | object); - function exit(code?: number); - function quit(code?: number); - function JavaImporter(...className: string[]); + function print(...message: any[]): void + function load(script: string | object) + function loadWithNewGlobal(script: string | object) + function exit(code?: number) + function quit(code?: number) + function JavaImporter(...className: string[]) namespace Java { - function type(clazz: string): any; - function from(javaObj: any): any[]; - function to(array: any[]): any; - function extend(...parentTypes: any[]); - function synchronized(func: () => void, lock: any); + function type(clazz: string): T + function from(javaObj: T[]): T[] + function to(array: T[], type?: T): T[] + function extend(...parentTypes: any[]): any + function synchronized(func: () => void, lock: any): Function + function asJSONCompatible(obj: T): T //@ts-ignore // function super(type: any); } interface Error { - readonly lineNumber?: number; - readonly columnNumber?: number; - readonly fileName?: string; - dumpStack?: Function; - printStackTrace?: Function; - getStackTrace?: () => any[]; + readonly class?: any + readonly lineNumber?: number + readonly columnNumber?: number + readonly fileName?: string + dumpStack?: Function + printStackTrace?: Function + getStackTrace?: () => any[] } interface String { - trimLeft(): string; - trimRight(): string; + trimLeft(): string + trimRight(): string } interface Object { - setPrototypeOf(obj: object, prototype: object): void; - bindProperties(to: object, from: object): void; + setPrototypeOf(obj: object, prototype: object): void + bindProperties(to: object, from: object): void } namespace NodeJS { interface Global { - scope: string; - logger: any; - debug: boolean; - level: string; - eventCenter: EventEmitter; - NashornEngineStartTime: number; - setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType) => void; - noop: () => void; - console: Console; + scope: string + logger: any + debug: boolean + level: string + NashornEngineStartTime: number + setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType) => void + noop: () => void + console: Console + } + interface Process { + on(event: string, listener: any): this + emit(event: string, ...message: any): this } } - var root: string; - var base: Core; - var ScriptEngineContextHolder: any; - function engineLoad(str: string): any; + const root: string + const base: Core + const ScriptEngineContextHolder: any + function engineLoad(str: string | { script: string, name: string }): any interface Core { - getClass(name: String): any; - getProxyClass(): any; - getInstance(): any; - read(path: string): string; - save(path: string, content: string): void; - delete(path: string): void; + getClass(name: String): any + getProxyClass(): any + getInstance(): any + read(path: string): string + save(path: string, content: string): void + delete(path: string): void } interface Console { - ex(err: Error): void; - stack(err: Error, color?: boolean): string[]; - sender(...args: any): void; - console(...args: any): void; - i18n(name: string, ...params: any[]): void; + ex(err: Error): void + stack(err: Error, color?: boolean): string[] + sender(...args: any): void + console(...args: any): void + i18n(name: string, ...params: any[]): void } interface ProxyConstructor { - newProxy(target: T, handler: ProxyHandler): T; + newProxy(target: T, handler: ProxyHandler): T } } -export { }; +export { } diff --git a/packages/plugin/src/interfaces.ts b/packages/plugin/src/interfaces.ts index 7e0e5a6b..192418a6 100644 --- a/packages/plugin/src/interfaces.ts +++ b/packages/plugin/src/interfaces.ts @@ -31,6 +31,10 @@ export namespace interfaces { executor?: string } export interface CommandMetadata extends ExecMetadata { + /** + * 命令描述 + */ + description?: string /** * 参数列表 */