feat: merge decorators meta interface

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-04-01 11:08:57 +08:00
parent eaa11ac89e
commit d679915062
4 changed files with 5 additions and 12 deletions

View File

@ -28,7 +28,6 @@
"minecraft-protocol": "^1.11.0" "minecraft-protocol": "^1.11.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^6.14.2",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"typescript": "^3.8.3" "typescript": "^3.8.3"
} }

View File

@ -37,13 +37,13 @@ export function cmd(metadata: interfaces.CommandMetadata = {}) {
* MiaoScript TabComplete * MiaoScript TabComplete
* @param metadata TabCompleterMetadata * @param metadata TabCompleterMetadata
*/ */
export function tab(metadata: interfaces.TabCompleterMetadata = {}) { export function tab(metadata: interfaces.CommandMetadata = {}) {
return function(target: any, key: string, value: any) { return function(target: any, key: string, value: any) {
metadata.name = metadata.name || (key.startsWith('tab') ? key.split('tab', 2)[1] : key); metadata.name = metadata.name || (key.startsWith('tab') ? key.split('tab', 2)[1] : key);
if (!metadata.name) { return; } if (!metadata.name) { return; }
metadata.executor = key; metadata.executor = key;
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key) metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
const previousMetadata: Map<string, interfaces.TabCompleterMetadata> = getPluginTabCompleterMetadata(target) const previousMetadata: Map<string, interfaces.CommandMetadata> = getPluginTabCompleterMetadata(target)
previousMetadata.set(metadata.name, metadata) previousMetadata.set(metadata.name, metadata)
Reflect.defineMetadata(METADATA_KEY.tab, previousMetadata, target.constructor); Reflect.defineMetadata(METADATA_KEY.tab, previousMetadata, target.constructor);
}; };

View File

@ -67,12 +67,6 @@ export namespace interfaces {
*/ */
paramtypes?: string[]; paramtypes?: string[];
} }
export interface TabCompleterMetadata extends ExecMetadata {
/**
*
*/
paramtypes?: string[];
}
export interface ListenerMetadata extends ExecMetadata { export interface ListenerMetadata extends ExecMetadata {
} }
export interface ConfigMetadata extends BaseMetadata { export interface ConfigMetadata extends BaseMetadata {

View File

@ -34,10 +34,10 @@ function getPluginCommandMetadata(target: any) {
} }
function getPluginTabCompleterMetadata(target: any) { function getPluginTabCompleterMetadata(target: any) {
let tabcompleterMetadata: Map<string, interfaces.TabCompleterMetadata> = Reflect.getMetadata( let tabcompleterMetadata: Map<string, interfaces.CommandMetadata> = Reflect.getMetadata(
METADATA_KEY.tab, METADATA_KEY.tab,
target.constructor target.constructor
) || new Map<string, interfaces.TabCompleterMetadata>(); ) || new Map<string, interfaces.CommandMetadata>();
return tabcompleterMetadata; return tabcompleterMetadata;
} }