* 添加插件库
(pluginName: string, npmConfig: any = {})
| 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)) { |
no test coverage detected