2020-06-17 10:39:24 +00:00
|
|
|
import { plugin } from '@ccms/api'
|
2019-09-07 04:23:15 +00:00
|
|
|
import { interfaces } from './interfaces'
|
|
|
|
import { METADATA_KEY } from './constants'
|
|
|
|
|
2020-06-17 10:39:24 +00:00
|
|
|
const pluginSourceCache = new Map<string, plugin.PluginMetadata>()
|
2020-05-07 10:33:10 +00:00
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
function getPlugins() {
|
2020-06-17 10:39:24 +00:00
|
|
|
return [...getPluginMetadatas().values()].map((target) => target.target)
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPlugin(name: string) {
|
2020-06-17 10:39:24 +00:00
|
|
|
return getPluginMetadatas().get(name)
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 09:12:15 +00:00
|
|
|
function getPluginSources() {
|
2020-06-17 10:39:24 +00:00
|
|
|
let pluginSources: Map<string, plugin.PluginMetadata> = Reflect.getMetadata(
|
2020-09-24 10:36:10 +00:00
|
|
|
METADATA_KEY.source,
|
2020-05-07 09:12:15 +00:00
|
|
|
Reflect
|
2020-06-17 10:39:24 +00:00
|
|
|
) || pluginSourceCache
|
|
|
|
return pluginSources
|
2020-05-07 09:12:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
function getPluginMetadatas() {
|
2020-06-17 10:39:24 +00:00
|
|
|
let pluginMetadatas: Map<string, plugin.PluginMetadata> = Reflect.getMetadata(
|
2019-09-07 04:23:15 +00:00
|
|
|
METADATA_KEY.plugin,
|
|
|
|
Reflect
|
2020-06-17 10:39:24 +00:00
|
|
|
) || new Map<string, plugin.PluginMetadata>()
|
|
|
|
return pluginMetadatas
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginMetadata(target: any) {
|
2020-06-17 10:39:24 +00:00
|
|
|
let pluginMetadata: plugin.PluginMetadata = Reflect.getMetadata(
|
2019-09-07 04:23:15 +00:00
|
|
|
METADATA_KEY.plugin,
|
2019-09-19 10:59:32 +00:00
|
|
|
target.constructor
|
2020-06-17 10:39:24 +00:00
|
|
|
) || {}
|
|
|
|
return pluginMetadata
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 10:59:32 +00:00
|
|
|
function getPluginCommandMetadata(target: any) {
|
2020-09-24 02:33:16 +00:00
|
|
|
let commandMetadata: interfaces.CommandMetadata[] = Reflect.getMetadata(
|
2019-09-19 10:59:32 +00:00
|
|
|
METADATA_KEY.cmd,
|
|
|
|
target.constructor
|
2020-09-24 02:33:16 +00:00
|
|
|
) || []
|
2020-06-17 10:39:24 +00:00
|
|
|
return commandMetadata
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginTabCompleterMetadata(target: any) {
|
2020-04-01 03:08:57 +00:00
|
|
|
let tabcompleterMetadata: Map<string, interfaces.CommandMetadata> = Reflect.getMetadata(
|
2019-09-19 10:59:32 +00:00
|
|
|
METADATA_KEY.tab,
|
|
|
|
target.constructor
|
2020-06-17 10:39:24 +00:00
|
|
|
) || new Map<string, interfaces.CommandMetadata>()
|
|
|
|
return tabcompleterMetadata
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginListenerMetadata(target: any) {
|
|
|
|
let listnerMetadata: interfaces.ListenerMetadata[] = Reflect.getMetadata(
|
|
|
|
METADATA_KEY.listener,
|
|
|
|
target.constructor
|
2020-06-17 10:39:24 +00:00
|
|
|
) || []
|
|
|
|
return listnerMetadata
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 16:12:32 +00:00
|
|
|
function getPluginConfigMetadata(target: any) {
|
|
|
|
let configMetadata: Map<string, interfaces.ConfigMetadata> = Reflect.getMetadata(
|
|
|
|
METADATA_KEY.config,
|
|
|
|
target.constructor
|
2020-06-17 10:39:24 +00:00
|
|
|
) || new Map<string, interfaces.ConfigMetadata>()
|
|
|
|
return configMetadata
|
2020-02-23 16:12:32 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 07:38:00 +00:00
|
|
|
function getPluginStageMetadata(target: any, stage: string) {
|
|
|
|
let stageMetadata: interfaces.ExecMetadata[] = Reflect.getMetadata(
|
|
|
|
METADATA_KEY.stage[stage],
|
|
|
|
target.constructor
|
2020-06-17 10:39:24 +00:00
|
|
|
) || []
|
|
|
|
return stageMetadata
|
2020-04-24 07:38:00 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2020-05-07 09:12:15 +00:00
|
|
|
getPluginSources,
|
2019-09-07 04:23:15 +00:00
|
|
|
getPluginMetadatas,
|
2019-09-19 10:59:32 +00:00
|
|
|
getPluginMetadata,
|
|
|
|
getPluginCommandMetadata,
|
|
|
|
getPluginTabCompleterMetadata,
|
|
|
|
getPluginListenerMetadata,
|
2020-04-24 07:38:00 +00:00
|
|
|
getPluginConfigMetadata,
|
|
|
|
getPluginStageMetadata
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|