2019-09-07 04:23:15 +00:00
|
|
|
import { interfaces } from './interfaces'
|
|
|
|
import { METADATA_KEY } from './constants'
|
|
|
|
|
|
|
|
function getPlugins() {
|
2019-09-19 10:59:32 +00:00
|
|
|
return [...getPluginMetadatas().values()].map((target) => target.target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPlugin(name: string) {
|
|
|
|
return getPluginMetadatas().get(name);
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginMetadatas() {
|
2019-09-19 10:59:32 +00:00
|
|
|
let pluginMetadatas: Map<string, interfaces.PluginMetadata> = Reflect.getMetadata(
|
2019-09-07 04:23:15 +00:00
|
|
|
METADATA_KEY.plugin,
|
|
|
|
Reflect
|
2019-09-19 10:59:32 +00:00
|
|
|
) || new Map<string, interfaces.PluginMetadata>();
|
2019-09-07 04:23:15 +00:00
|
|
|
return pluginMetadatas;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginMetadata(target: any) {
|
|
|
|
let pluginMetadata: interfaces.PluginMetadata = Reflect.getMetadata(
|
|
|
|
METADATA_KEY.plugin,
|
2019-09-19 10:59:32 +00:00
|
|
|
target.constructor
|
2019-09-07 04:23:15 +00:00
|
|
|
) || {};
|
|
|
|
return pluginMetadata;
|
|
|
|
}
|
|
|
|
|
2019-09-19 10:59:32 +00:00
|
|
|
function getPluginCommandMetadata(target: any) {
|
|
|
|
let commandMetadata: Map<string, interfaces.CommandMetadata> = Reflect.getMetadata(
|
|
|
|
METADATA_KEY.cmd,
|
|
|
|
target.constructor
|
|
|
|
) || new Map<string, interfaces.CommandMetadata>();
|
|
|
|
return commandMetadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginTabCompleterMetadata(target: any) {
|
2019-11-04 12:28:52 +00:00
|
|
|
let tabcompleterMetadata: Map<string, interfaces.TabCompleterMetadata> = Reflect.getMetadata(
|
2019-09-19 10:59:32 +00:00
|
|
|
METADATA_KEY.tab,
|
|
|
|
target.constructor
|
|
|
|
) || new Map<string, interfaces.TabCompleterMetadata>();
|
|
|
|
return tabcompleterMetadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginListenerMetadata(target: any) {
|
|
|
|
let listnerMetadata: interfaces.ListenerMetadata[] = Reflect.getMetadata(
|
|
|
|
METADATA_KEY.listener,
|
|
|
|
target.constructor
|
|
|
|
) || [];
|
|
|
|
return listnerMetadata;
|
|
|
|
}
|
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
export {
|
2019-09-19 10:59:32 +00:00
|
|
|
getPlugin,
|
2019-09-07 04:23:15 +00:00
|
|
|
getPlugins,
|
|
|
|
getPluginMetadatas,
|
2019-09-19 10:59:32 +00:00
|
|
|
getPluginMetadata,
|
|
|
|
getPluginCommandMetadata,
|
|
|
|
getPluginTabCompleterMetadata,
|
|
|
|
getPluginListenerMetadata,
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|