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 f9458e66c1
commit f224b417bb
4 changed files with 5 additions and 12 deletions

View File

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

View File

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

View File

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

View File

@ -34,10 +34,10 @@ function getPluginCommandMetadata(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,
target.constructor
) || new Map<string, interfaces.TabCompleterMetadata>();
) || new Map<string, interfaces.CommandMetadata>();
return tabcompleterMetadata;
}