feat: merge decorators meta interface
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
eaa11ac89e
commit
d679915062
@ -28,8 +28,7 @@
|
||||
"minecraft-protocol": "^1.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^6.14.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user