mirror of
https://github.com/certd/certd.git
synced 2026-04-14 12:30:54 +08:00
28 lines
486 B
JavaScript
28 lines
486 B
JavaScript
|
|
export class PluginRegistry {
|
|
constructor () {
|
|
this.plugins = {}
|
|
}
|
|
|
|
install (plugin) {
|
|
if (plugin == null) {
|
|
return
|
|
}
|
|
if (this.plugins == null) {
|
|
this.plugins = {}
|
|
}
|
|
const name = plugin.name || (plugin.define && plugin.define.name)
|
|
this.plugins[name] = plugin
|
|
}
|
|
|
|
get (name) {
|
|
if (name) {
|
|
return this.plugins[name]
|
|
}
|
|
|
|
throw new Error(`找不到${name}插件`)
|
|
}
|
|
}
|
|
|
|
export const pluginRegistry = new PluginRegistry()
|