MCPcopy
hub / github.com/youzan/zan-proxy / add

Method add

src/core/services/plugin.ts:138–169  ·  view source on GitHub ↗

* 添加插件库

(pluginName: string, npmConfig: any = {})

Source from the content-addressed store, hash-verified

136 * 添加插件库
137 */
138 public add(pluginName: string, npmConfig: any = {}) {
139 if (this.has(pluginName)) {
140 throw new HttpError(409, '该插件已存在');
141 }
142 return new Promise((resolve, reject) => {
143 const install = () => {
144 npm.commands.install([pluginName, this.pluginInstallDir], async (err: any) => {
145 if (err) {
146 if (err.code === 'E404') {
147 return reject(Error(`插件不存在 ${err.uri}`));
148 }
149 return reject(err);
150 }
151 const plugins = [
152 ...this.getPlugins(),
153 {
154 name: pluginName,
155 version: await this.getPluginVersion(pluginName),
156 registry: npmConfig.registry || npm.config.get('registry'),
157 },
158 ];
159 this.setPlugins(plugins);
160 return resolve(plugins);
161 });
162 };
163 npmConfig = Object.assign({}, npmConfig, {
164 loglevel: 'silent',
165 prefix: this.pluginInstallDir,
166 });
167 this.loadNpmConfig(npmConfig, install);
168 });
169 }
170
171 public update(pluginName: string) {
172 if (!this.has(pluginName)) {

Callers 11

installPluginMethod · 0.45
TFunction · 0.45
NFunction · 0.45
theme.jsFile · 0.45
CFunction · 0.45
SFunction · 0.45
gitbook.jsFile · 0.45
tFunction · 0.45
lunr.min.jsFile · 0.45
tFunction · 0.45
lunr.min.jsFile · 0.45

Calls 2

hasMethod · 0.95
loadNpmConfigMethod · 0.95

Tested by

no test coverage detected