diff --git a/package.json b/package.json index f50b8e9..2b2b8aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubick", - "version": "2.1.2", + "version": "2.1.3", "author": "muwoo <2424880409@qq.com>", "private": true, "scripts": { @@ -21,6 +21,7 @@ "dependencies": { "@better-scroll/core": "^2.4.2", "ant-design-vue": "^2.2.8", + "axios": "^1.3.4", "core-js": "^3.6.5", "cross-spawn": "^7.0.3", "extract-file-icon": "^0.3.2", diff --git a/src/core/plugin-handler/index.ts b/src/core/plugin-handler/index.ts index 30ba17c..3719815 100644 --- a/src/core/plugin-handler/index.ts +++ b/src/core/plugin-handler/index.ts @@ -9,6 +9,7 @@ import fixPath from 'fix-path'; import spawn from 'cross-spawn'; import { ipcRenderer } from 'electron'; +import axios from 'axios'; fixPath(); @@ -22,6 +23,8 @@ class AdapterHandler { // 插件源地址 readonly registry: string; + pluginCaches = {}; + /** * Creates an instance of AdapterHandler. * @param {AdapterHandlerOptions} options @@ -52,6 +55,29 @@ class AdapterHandler { this.registry = register || 'https://registry.npm.taobao.org'; } + async upgrade(name: string): Promise { + // 创建一个npm-registry-client实例 + const packageJSON = JSON.parse( + fs.readFileSync(`${this.baseDir}/package.json`, 'utf-8') + ); + const registryUrl = `https://registry.npm.taobao.org/${name}`; + + // 从npm源中获取依赖包的最新版本 + try { + const installedVersion = packageJSON.dependencies[name].replace('^', ''); + let latestVersion = this.pluginCaches[name]; + if (!latestVersion) { + const { data } = await axios.get(registryUrl, { timeout: 2000 }); + latestVersion = data['dist-tags'].latest; + this.pluginCaches[name] = latestVersion; + } + if (latestVersion > installedVersion) { + await this.install([name], { isDev: false }); + } + } catch (e) { + // ... + } + } /** * 获取插件信息 * @param {string} adapter 插件名称 diff --git a/src/renderer/components/search.vue b/src/renderer/components/search.vue index 6316b64..e5d039d 100644 --- a/src/renderer/components/search.vue +++ b/src/renderer/components/search.vue @@ -29,11 +29,12 @@ >