dufu1991 3 rokov pred
rodič
commit
57060ceef8

+ 6 - 2
packages/vscode-extension/CHANGELOG.md

@@ -1,6 +1,10 @@
-## 0.0.15
+## 0.0.17
 
-- Fixed known issues.(0.0.10 - 0.0.15)
+- Fixed the latest version detection problem.
+
+## 0.0.16
+
+- Fixed known issues.(0.0.10 - 0.0.16)
 
 ## 0.0.9
 

+ 6 - 2
packages/vscode-extension/CHANGELOG_CN.md

@@ -1,6 +1,10 @@
-## 0.0.15
+## 0.0.17
 
-- 修复已知问题。(0.0.10 - 0.0.15)
+- 修复最新版本检测问题。
+
+## 0.0.16
+
+- 修复已知问题。(0.0.10 - 0.0.16)
 
 ## 0.0.9
 

+ 57 - 60
packages/vscode-extension/package.json

@@ -1,62 +1,59 @@
 {
-  "name": "stdf-vscode-extension",
-  "displayName": "STDF for VS Code",
-  "description": "A VS Code extension to facilitate STDF development",
-  "version": "0.0.16",
-  "publisher": "STDF",
-  "icon": "./src/assets/stdf-vscode-extension.png",
-  "main": "./src/extension.js",
-  "engines": {
-    "vscode": "^1.27.0"
-  },
-  "scripts": {
-    "files": "node scripts/files.js",
-    "package": "vsce package",
-    "publish": "vsce publish"
-  },
-  "categories": [
-    "Programming Languages"
-  ],
-  "activationEvents": [
-    "onLanguage:svelte"
-  ],
-  "sponsor": {
-    "url": "https://stdf.design?fund"
-  },
-  "keywords": [
-    "svelte",
-    "stdf",
-    "component",
-    "api",
-    "javascript"
-  ],
-  "contributes": {
-    "commands": [],
-    "configuration": {
-      "type": "object",
-      "title": "STDF",
-      "properties": {
-        "STDF.English": {
-          "type": "boolean",
-          "default": false,
-          "description": "Whether to enable English or not in stdf-vscode-extension"
-        }
-      }
-    }
-  },
-  "devDependencies": {
-    "vscode": "^1.1.37"
-  },
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension"
-  },
-  "bugs": {
-    "url": "https://github.com/dufu1991/stdf/issues?q=is:issue+is:open+vscode"
-  },
-  "homepage": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension/README.md",
-  "LICENSE": "https://github.com/dufu1991/stdf/blob/main/LICENSE",
-  "dependencies": {
-    "latest-version": "^7.0.0"
-  }
+	"name": "stdf-vscode-extension",
+	"displayName": "STDF for VS Code",
+	"description": "A VS Code extension to facilitate STDF development",
+	"version": "0.0.17",
+	"publisher": "STDF",
+	"icon": "./src/assets/stdf-vscode-extension.png",
+	"main": "./src/extension.js",
+	"engines": {
+		"vscode": "^1.27.0"
+	},
+	"scripts": {
+		"files": "node scripts/files.js",
+		"package": "vsce package",
+		"publish": "vsce publish"
+	},
+	"categories": [
+		"Programming Languages"
+	],
+	"activationEvents": [
+		"onLanguage:svelte"
+	],
+	"sponsor": {
+		"url": "https://stdf.design?fund"
+	},
+	"keywords": [
+		"svelte",
+		"stdf",
+		"component",
+		"api",
+		"javascript"
+	],
+	"contributes": {
+		"commands": [],
+		"configuration": {
+			"type": "object",
+			"title": "STDF",
+			"properties": {
+				"STDF.English": {
+					"type": "boolean",
+					"default": false,
+					"description": "Whether to enable English or not in stdf-vscode-extension"
+				}
+			}
+		}
+	},
+	"devDependencies": {
+		"vscode": "^1.1.37"
+	},
+	"repository": {
+		"type": "git",
+		"url": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension"
+	},
+	"bugs": {
+		"url": "https://github.com/dufu1991/stdf/issues?q=is:issue+is:open+vscode"
+	},
+	"homepage": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension/README.md",
+	"LICENSE": "https://github.com/dufu1991/stdf/blob/main/LICENSE"
 }

+ 0 - 8
packages/vscode-extension/scripts/files.js

@@ -48,13 +48,6 @@ const replaceMenuList = () => {
 	console.log('🎉 menuList replace success!');
 };
 
-// 复制 ../../packages/stdf/package.json 文件到 src/doc 目录下
-// Copy ../../packages/stdf/package.json file to src/doc directory
-const copyPackageJson = () => {
-	fs.copyFileSync('../../packages/stdf/package.json', './src/doc/package.json');
-	console.log('🎉 package.json copy success!');
-};
-
 // 复制 ../../LICENSE 文件到 ./ 目录下
 // Copy ../../LICENSE file to ./ directory
 const copyLicense = () => {
@@ -66,5 +59,4 @@ createDoc();
 copyDoc();
 copyMenuList();
 replaceMenuList();
-copyPackageJson();
 copyLicense();

+ 23 - 9
packages/vscode-extension/src/extension.js

@@ -1,17 +1,13 @@
 const vscode = require('vscode');
 const path = require('path');
-
-// 读取 ./doc/package.json 文件
-// Read the ./doc/package.json file
-const stdfPackage = require('./doc/package.json');
-const latestVersion = stdfPackage.version;
+const { exec } = require('child_process');
 
 // 组件列表
 // components list
 const componentListOrgin = require('./menuList');
 const componentList = ArrChildFun(componentListOrgin);
 
-function activate() {
+async function activate() {
 	// 如果没有设置,返回undefined
 	// If not set, return undefined
 	const result = vscode.workspace.getConfiguration().get('STDF');
@@ -36,6 +32,10 @@ function activate() {
 		currentVersion = currentVersion.slice(1);
 	}
 
+	// stdf 组件库的最新版本号
+	// The latest version number of the stdf component library
+	const latestVersion = await getLatestVersion('stdf');
+
 	// 当前文件是 .svelte 文件时且 isImportStdf 为 true 时,才注册悬浮提示
 	// When the current file is a .svelte file and isImportStdf is true, register the hover prompt
 	if (vscode.window.activeTextEditor.document.languageId === 'svelte' && isImportStdf) {
@@ -52,9 +52,9 @@ function activate() {
 				if (componentList.includes(word)) {
 					// 组合当前 STDF 版本和最新版本
 					// Combine the current STDF version and the latest version
-					const versionContent = `${isZh ? '当前版本' : 'Current version'}:${currentVersion}   ${
-						isZh ? '最新版本' : 'Latest version'
-					}:${latestVersion}`;
+					const versionContent = `STDF ${isZh ? '当前' : 'Current'}:${currentVersion}   ${
+						isZh ? '最新' : 'Latest'
+					}:${latestVersion}   [${isZh ? '查看更新日志' : 'See changelog'}](https://stdf.design/#/guide?nav=changelog)`;
 
 					// 获取对应组件的 api.md 文件的路径
 					// Get the path of the api.md file of the corresponding component
@@ -107,6 +107,20 @@ function ArrChildFun(arr) {
 	return newArr2;
 }
 
+// 获取指定 npm 包的最新版本号
+// Get the latest version number of the specified npm package
+async function getLatestVersion(packageName) {
+	return new Promise((resolve, reject) => {
+		exec(`npm show ${packageName} version`, (error, stdout, stderr) => {
+			if (error || stderr) {
+				reject(error || stderr);
+			} else {
+				resolve(stdout.trim());
+			}
+		});
+	});
+}
+
 function deactivate() {}
 
 module.exports = {