MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / register

Method register

packages/core/src/plugin/plugins.ts:109–142  ·  view source on GitHub ↗

* register a plugin * @param pluginConfigCreator - a creator function which returns the plugin config * @param options - the plugin options * @param registerOptions - the plugin register options

(pluginModel: Plugin, registerOptions?: PluginRegisterOptions)

Source from the content-addressed store, hash-verified

107 * @param registerOptions - the plugin register options
108 */
109 async register(pluginModel: Plugin, registerOptions?: PluginRegisterOptions): Promise<void> {
110 const config = pluginModel
111 const { name: pluginName, deps = [], eventPrefix } = config
112 if (!pluginName) {
113 logger.error('pluginConfigCreator.pluginName required', pluginModel)
114 return
115 }
116 const meta: PluginMeta = { dependencies: deps, eventPrefix }
117 const allowOverride = registerOptions?.override === true
118
119 if (this.pluginsMap.has(pluginName)) {
120 if (allowOverride) {
121 const originalPlugin = this.pluginsMap.get(pluginName)
122 logger.log(
123 'plugin override, originalPlugin with name ',
124 pluginName,
125 ' will be destroyed, config:',
126 originalPlugin?.config,
127 )
128 originalPlugin?.destroy()
129 this.pluginsMap.delete(pluginName)
130 } else {
131 throw new Error(`Plugin with name ${pluginName} exists`)
132 }
133 }
134
135 const plugin = new PluginRuntime(pluginName, this, config)
136 if (registerOptions?.autoInit) {
137 await plugin.init()
138 }
139 this.plugins.push(plugin)
140 this.pluginsMap.set(pluginName, plugin)
141 logger.log(`plugin registered with pluginName: ${pluginName}, config: `, config, 'meta:', meta)
142 }
143
144 /**
145 * batch register plugins

Callers 1

registerPluginsMethod · 0.95

Calls 8

initMethod · 0.95
hasMethod · 0.65
getMethod · 0.65
destroyMethod · 0.65
deleteMethod · 0.65
setMethod · 0.65
errorMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected