Browse Source

[vscode]publish v0.0.28

dufu1991 1 year ago
parent
commit
4813a331dd

+ 34 - 0
.github/workflows/publish-vscode-next.yml

@@ -0,0 +1,34 @@
+# 当分支 next 有 push 事件并且此次 push 包含了 packages/vscode-extension/package.json 文件时,执行以下任务
+
+name: PUBLISH VSCODE NEXT
+
+on:
+    push:
+        branches:
+            - next
+        paths:
+            - 'packages/vscode-extension/package.json'
+
+jobs:
+    publish:
+        runs-on: ubuntu-latest
+
+        steps:
+            - name: Checkout
+              uses: actions/checkout@v4
+
+            - name: Setup Node.js environment
+              uses: actions/setup-node@v3
+              with:
+                  node-version: 20.x
+
+            # cd 到 packages/vscode-extension 目录
+            # 执行 files
+            # 安装依赖
+            - name: Publish
+              run: |
+                  cd packages/vscode-extension
+                  npm run files
+                  npm install
+                  npm install -g @vscode/vsce
+                  vsce publish -p ${{ secrets.VSCE_TOKEN }}

+ 1 - 1
.gitignore

@@ -44,7 +44,7 @@ build
 # 忽略 packages 中 vscode-extension 本地构建的文件 ignore the files built by vscode-extension in packages
 /packages/vscode-extension/.vscodeignore
 /packages/vscode-extension/LICENSE
-/packages/vscode-extension/src/doc
+/packages/vscode-extension/src/docs
 /packages/vscode-extension/src/menuList.js
 
 

+ 4 - 0
packages/vscode-extension/CHANGELOG.md

@@ -1,5 +1,9 @@
 > No change log version, it means that it is just updated with the STDF version and the plug-in itself is not updated.
 
+## 0.0.28
+
+- Support STDF next.
+
 ## 0.0.24
 
 - Update icon.

+ 4 - 0
packages/vscode-extension/CHANGELOG_CN.md

@@ -1,5 +1,9 @@
 > 没有写更新日志的版本,表示只是跟随 STDF 版本更新,未对插件本身进行更新。
 
+## 0.0.28
+
+- 支持 STDF next。
+
 ## 0.0.24
 
 - 更新图标。

+ 2 - 0
packages/vscode-extension/README.md

@@ -1,5 +1,7 @@
 [简体中文](https://github.com/any-tdf/stdf/blob/main/packages/vscode-extension/README_CN.md)
 
+> Please switch to the preview version plugin for STDF next.
+
 # Introduction
 
 A VS Code extension that provides convenience when developing with [STDF](https://stdf.design).

+ 4 - 2
packages/vscode-extension/README_CN.md

@@ -1,8 +1,10 @@
-[English](https://github.com/any-tdf/stdf/blob/main/packages/vscode-extension/README.md)
+[English](https://github.com/any-tdf/stdf/blob/next/packages/vscode-extension/README.md)
+
+> STDF next 请切换到预览版插件。
 
 # 介绍
 
-一个 VS Code 插件,用于在使用 [STDF](https://stdf.design) 开发时提供一些便利。
+一个 VS Code 插件,用于在使用 [STDF](https://next.stdf.design) 开发时提供一些便利。
 
 # 安装
 

+ 3 - 1
packages/vscode-extension/package.json

@@ -2,10 +2,12 @@
 	"name": "stdf-vscode-extension",
 	"displayName": "STDF for VS Code",
 	"description": "A VS Code extension to facilitate STDF development",
-	"version": "0.0.27",
+	"version": "0.0.28",
 	"publisher": "STDF",
 	"icon": "./src/assets/stdf-vscode-extension.png",
 	"main": "./src/extension.js",
+	"type": "module",
+	"preview": true,
 	"engines": {
 		"vscode": "^1.27.0"
 	},

+ 48 - 40
packages/vscode-extension/scripts/files.js

@@ -1,62 +1,70 @@
-const fs = require('fs');
+import fs from 'fs';
 
-// 创建 src/doc/components 目录
-// Create src/doc/components directory
+// 创建 src/docs/components 目录
+// Create src/docs/components directory
 const createDoc = () => {
-	fs.mkdirSync('src/doc');
-	fs.mkdirSync('src/doc/components');
-	console.log('🎉 src/doc/components create success!');
+    fs.mkdirSync('src/docs');
+    fs.mkdirSync('src/docs/components');
+    console.log('🎉 src/docs/components create success!');
 };
 
-// 将 ../../doc/components/**/api.md 和 ../../doc/components/**/api_en.md 文件复制到 src/doc/components/**/ 目录下
-// Copy ../../doc/components/**/api.md and ../../doc/components/**/api_en.md files to src/doc/components/**/ directory
+// 将 ../../docs/mds/components/**/api.md 和 ../../docs/mds/components/**/api_en.md 文件复制到 src/docs/components/**/ 目录下
+// Copy ../../docs/mds/components/**/api.md and ../../docs/mds/components/**/api_en.md files to src/docs/components/**/ directory
 const copyDoc = () => {
-	const components = fs.readdirSync('../../doc/components');
-	// 如果 components 有 .DS_Store 文件,删除
-	// If components has .DS_Store file, delete
-	if (components.includes('.DS_Store')) {
-		components.splice(components.indexOf('.DS_Store'), 1);
-	}
+    const components = fs.readdirSync('../../docs/mds/components');
+    // 如果 components 有 .DS_Store 文件,删除
+    // If components has .DS_Store file, delete
+    if (components.includes('.DS_Store')) {
+        components.splice(components.indexOf('.DS_Store'), 1);
+    }
 
-	components.forEach(component => {
-		const files = fs.readdirSync(`../../doc/components/${component}`);
-		fs.mkdirSync('src/doc/components/' + component);
-		files.forEach(file => {
-			if (file === 'api.md' || file === 'api_en.md') {
-				fs.copyFileSync(`../../doc/components/${component}/${file}`, `src/doc/components/${component}/${file}`);
-			}
-		});
-	});
-	console.log(`🎉 Total copy ${components.length}*2 files!`);
+    components.forEach(component => {
+        const files = fs.readdirSync(`../../docs/mds/components/${component}`);
+        fs.mkdirSync('src/docs/components/' + component);
+        files.forEach(file => {
+            if (file === 'api.md' || file === 'api_en.md') {
+                fs.copyFileSync(`../../docs/mds/components/${component}/${file}`, `src/docs/components/${component}/${file}`);
+            }
+        });
+    });
+    console.log(`🎉 Total copy ${components.length}*2 files!`);
 };
 
-// 复制 ../../demo/src/data/menuList.js 文件到 src 目录下
-// Copy ../../demo/src/data/menuList.js file to src directory
+// 复制 ../../docs/site/src/data/menuList.ts 文件到 src 目录下
+// Copy ../../docs/site/src/data/menuList.ts file to src directory
 const copyMenuList = () => {
-	fs.copyFileSync('../../demo/src/data/menuList.js', './src/menuList.js');
-	console.log('🎉 menuList copy success!');
+    // 读取 ../../docs/site/src/data/menuList.ts 文件
+    const menuList = fs.readFileSync('../../docs/site/src/data/menuList.ts', 'utf-8');
+    console.log(menuList);
+    // 将其中的部分内容替换为另一个文件中的内容
+    // Replace the content of the file with the content of another file
+    const newMenuList = menuList.replace(
+        `export type MenuListChild = {
+	title: string;
+	title_zh: string;
+	title_en: string;
+	nav: string;
+	tip: string;
+	tip_en: string;
+	alias: string;
 };
+export type MenuList = { class: string; class_en: string; childs: MenuListChild[] };
 
-// 将 src/menuList.js 文件中的第一行替换为 module.exports = [
-// Replace the first line of the src/menuList.js file with module.exports = [
-const replaceMenuList = () => {
-	const data = fs.readFileSync('./src/menuList.js', 'utf8');
-	const dataArray = data.split('\n');
-	dataArray.splice(0, 1, 'module.exports = [');
-	const result = dataArray.join('\n');
-	fs.writeFileSync('./src/menuList.js', result, 'utf8');
-	console.log('🎉 menuList replace success!');
+export const menuList: MenuList[] = [`,
+        'export default ['
+    );
+    fs.writeFileSync('./src/menuList.js', newMenuList);
+    console.log('🎉 menuList copy success!');
 };
 
 // 复制 ../../LICENSE 文件到 ./ 目录下
 // Copy ../../LICENSE file to ./ directory
 const copyLicense = () => {
-	fs.copyFileSync('../../LICENSE', './LICENSE');
-	console.log('🎉 LICENSE copy success!');
+    fs.copyFileSync('../../LICENSE', './LICENSE');
+    console.log('🎉 LICENSE copy success!');
 };
 
 createDoc();
 copyDoc();
 copyMenuList();
-replaceMenuList();
 copyLicense();

+ 115 - 100
packages/vscode-extension/src/extension.js

@@ -1,129 +1,144 @@
-const vscode = require('vscode');
-const path = require('path');
-const { exec } = require('child_process');
+import vscode from 'vscode';
+import path from 'path';
+import { exec } from 'child_process';
 
 // 组件列表
 // components list
-const componentListOrgin = require('./menuList');
-const componentList = ArrChildFun(componentListOrgin);
+import menuList from './menuList';
+const componentList = ArrChildFun(menuList);
 
 async function activate() {
-	// 如果没有设置,返回undefined
-	// If not set, return undefined
-	const result = vscode.workspace.getConfiguration().get('STDF');
-	// 获取插件语言
-	// Get plugin language
-	const isZh = result.English ? false : true;
+    // 如果没有设置,返回 undefined
+    // If not set, return undefined
+    const result = vscode.workspace.getConfiguration().get('STDF');
+    // 获取插件语言
+    // Get plugin language
+    const isZh = result.English ? false : true;
 
-	// 读取当前工程的 package.json 文件
-	// Read the package.json file of the current project
-	const packageJson = require(path.join(vscode.workspace.rootPath, 'package.json'));
+    // 读取当前工程的 package.json 文件
+    // Read the package.json file of the current project
+    const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
+    const packageJson = workspaceFolder
+        ? await import(path.join(workspaceFolder.uri.fsPath, 'package.json'), { assert: { type: 'json' } })
+        : null;
 
-	// 判断当前工程是否引入了 stdf 组件库
-	// Determine whether the current project has introduced the stdf component library
-	const isImportStdf = packageJson?.dependencies?.stdf || packageJson?.devDependencies?.stdf ? true : false;
+    // 判断当前工程是否引入了 stdf 组件库
+    // Determine whether the current project has introduced the stdf component library
+    const isImportStdf = packageJson?.dependencies?.stdf || packageJson?.devDependencies?.stdf ? true : false;
 
-	// 如果 isImportStdf 为 true 时,读取 stdf 组件库的版本号做为当前版本号
-	// If isImportStdf is true, read the version number of the stdf component library as the current version number
-	let currentVersion = isImportStdf ? packageJson.dependencies?.stdf || packageJson.devDependencies?.stdf : '';
-	// 如果 currentVersion 开头为 ^,则去掉 ^
-	// If currentVersion starts with ^, remove ^
-	if (currentVersion.startsWith('^')) {
-		currentVersion = currentVersion.slice(1);
-	}
+    // 如果 isImportStdf 为 true 时,读�� stdf 组件库的版本号做为当前版本号
+    // If isImportStdf is true, read the version number of the stdf component library as the current version number
+    let currentVersion = isImportStdf ? packageJson.dependencies?.stdf || packageJson.devDependencies?.stdf : '';
+    // 如果 currentVersion 开头为 ^,则去掉 ^
+    // If currentVersion starts with ^, remove ^
+    if (currentVersion.startsWith('^')) {
+        currentVersion = currentVersion.slice(1);
+    }
 
-	// stdf 组件库的最新版本号
-	// The latest version number of the stdf component library
-	const latestVersion = (await getLatestVersion('stdf')) || (isZh ? '获取失败' : 'Failed to get');
+    // stdf 组件库的最新版本号
+    // The latest version number of the stdf component library
+    const latestVersion = (await getLatestVersion('stdf')) || (isZh ? '获取失败' : 'Failed to get');
 
-	// 当前文件是 .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) {
-		vscode.languages.registerHoverProvider('svelte', {
-			provideHover(document, position) {
-				// 获取当前悬浮的单词
-				// Get the word currently hovering
-				const word = document.getText(document.getWordRangeAtPosition(position));
-				// 将单词首字母小写
-				// Lowercase the first letter of the word
-				const wordLower = word.charAt(0).toLowerCase() + word.slice(1);
-				// 如果单词为 components 数组中的一项,则显示提示信息,内容为 ./doc/components/${wordLower}/api.md 文件的内容
-				// If the word is an item in the components array, display the prompt information, and the content is the content of the ./doc/components/${wordLower}/api.md file
-				if (componentList.includes(word)) {
-					// 组合当前 STDF 版本和最新版本
-					// Combine the current STDF version and the latest version
-					const versionContent = `STDF ${isZh ? '当前' : 'Current'}:${currentVersion}   ${
-						isZh ? '最新' : 'Latest'
-					}:${latestVersion}   [${isZh ? '查看更新日志' : 'See changelog'}](https://stdf.design/#/guide/changelog)`;
+    // 当前文件是 .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) {
+        vscode.languages.registerHoverProvider('svelte', {
+            provideHover: async function (document, position) {
+                // 获取当前悬浮的单词
+                // Get the word currently hovering
+                const word = document.getText(document.getWordRangeAtPosition(position));
+                // 将单词首字母小写
+                // Lowercase the first letter of the word
+                const wordLower = word.charAt(0).toLowerCase() + word.slice(1);
+                // 如果单词为 components 数组中的一项,则显示提示信息,内容为 ./doc/components/${wordLower}/api.md 文件的内容
+                // If the word is an item in the components array, display the prompt information, and the content is the content of the ./doc/components/${wordLower}/api.md file
+                if (componentList.includes(word)) {
+                    // 组合当前 STDF 版本和最新版本
+                    // Combine the current STDF version and the latest version
+                    const versionContent = `STDF ${isZh ? '当前' : 'Current'}:${currentVersion}   ${
+                        isZh ? '最新' : 'Latest'
+                    }:${latestVersion}   [${isZh ? '查看更新日志' : 'See changelog'}](https://next.stdf.design/guide/changelog)`;
 
-					// 获取对应组件的 api.md 文件的路径
-					// Get the path of the api.md file of the corresponding component
-					const apiPath = path.join(__dirname, `./doc/components/${wordLower}/api${isZh ? '' : '_en'}.md`);
+                    // 获取对应组件的 api.md 文件的路径
+                    // Get the path of the api.md file of the corresponding component
+                    const apiPath = path.join(__dirname, `./docs/components/${wordLower}/api${isZh ? '' : '_en'}.md`);
 
-					// 读取 api.md 文件的内容
-					// Read the contents of the api.md file
-					const apiContent = require('fs').readFileSync(apiPath, 'utf-8');
-					// 在 apiContent 后面添加示例、API、指南、组件源码的链接
-					// Add links to examples, API, guides, and component source code after apiContent
-					const baseUrl = 'https://stdf.design/#/components?nav=';
-					const baseUrlCode = 'https://github.com/any-tdf/stdf/blob/main/packages/stdf/components/';
-					const baseUrlCodeGitee = 'https://gitee.com/dufu1991/stdf/blob/main/packages/stdf/components/';
-					const addContent = `**[${isZh ? '示例' : 'Demo'}](${baseUrl}${wordLower}&tab=0&lang=${
-						isZh ? 'zh_CN' : 'en_US'
-					})   [API](${baseUrl}${wordLower}&tab=1&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
-						isZh ? '指南' : 'Guide'
-					}](${baseUrl}${wordLower}&tab=2&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
-						isZh ? '更新日志' : 'Changelog'
-					}](${baseUrl}${wordLower}&tab=4&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
-						isZh ? '源码(GitHub)' : 'Source code(GitHub)'
-					}](${baseUrlCode}${wordLower}/${word}.svelte)   [${
-						isZh ? '源码(Gitee)' : 'Source code(Gitee)'
-					}](${baseUrlCodeGitee}${wordLower}/${word}.svelte)**`;
-					const allContent =
-						versionContent + '\n\n' + '---' + '\n\n' + apiContent + '\n\n' + '---' + '\n\n' + addContent + '\n\n' + '\n\n' + '---';
+                    // 读取 api.md 文件的内容
+                    // Read the contents of the api.md file
+                    const fs = await import('fs/promises');
+                    const apiContent = await fs.readFile(apiPath, 'utf-8');
+                    // 在 apiContent 后面添加示例、API、指南、组件源码的链接
+                    // Add links to examples, API, guides, and component source code after apiContent
+                    const baseUrl = 'https://next.stdf.design/components?nav=';
+                    const baseUrlCode = 'https://github.com/any-tdf/stdf/blob/next/packages/stdf/components/';
+                    const baseUrlCodeGitee = 'https://gitee.com/dufu1991/stdf/blob/main/packages/stdf/components/';
+                    const addContent = `**[${isZh ? '示例' : 'Demo'}](${baseUrl}${wordLower}&tab=0&lang=${
+                        isZh ? 'zh_CN' : 'en_US'
+                    })   [API](${baseUrl}${wordLower}&tab=1&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
+                        isZh ? '指南' : 'Guide'
+                    }](${baseUrl}${wordLower}&tab=2&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
+                        isZh ? '更新日志' : 'Changelog'
+                    }](${baseUrl}${wordLower}&tab=4&lang=${isZh ? 'zh_CN' : 'en_US'})   [${
+                        isZh ? '源码 (GitHub)' : 'Source code(GitHub)'
+                    }](${baseUrlCode}${wordLower}/${word}.svelte)   [${
+                        isZh ? '源码 (Gitee)' : 'Source code(Gitee)'
+                    }](${baseUrlCodeGitee}${wordLower}/${word}.svelte)**`;
+                    const allContent =
+                        versionContent +
+                        '\n\n' +
+                        '---' +
+                        '\n\n' +
+                        apiContent +
+                        '\n\n' +
+                        '---' +
+                        '\n\n' +
+                        addContent +
+                        '\n\n' +
+                        '\n\n' +
+                        '---';
 
-					// 返回提示信息
-					// Return prompt information
-					return new vscode.Hover(allContent);
-				}
-			},
-		});
-	}
+                    // 返回提示信息
+                    // Return prompt information
+                    return new vscode.Hover(allContent);
+                }
+            },
+        });
+    }
 }
 
 //数组处理
 //Array processing
 function ArrChildFun(arr) {
-	let newArr = [];
-	for (let e = 0; e < arr.length; e++) {
-		newArr.push(...arr[e].childs);
-	}
-	//再将 newArr 内的 title_en 组成一维数组
-	//Then the title_en in newArr is composed of one-dimensional array
-	let newArr2 = [];
-	for (let e = 0; e < newArr.length; e++) {
-		newArr2.push(newArr[e].title_en);
-	}
-	return newArr2;
+    let newArr = [];
+    for (let e = 0; e < arr.length; e++) {
+        newArr.push(...arr[e].childs);
+    }
+    //再将 newArr 内的 title_en 组成一维数组
+    //Then the title_en in newArr is composed of one-dimensional array
+    let newArr2 = [];
+    for (let e = 0; e < newArr.length; e++) {
+        newArr2.push(newArr[e].title_en);
+    }
+    return newArr2;
 }
 
 // 获取指定 npm 包的最新版本号
 // Get the latest version number of the specified npm package
 async function getLatestVersion(packageName) {
-	return new Promise(resolve => {
-		exec(`npm show ${packageName} version`, (error, stdout, stderr) => {
-			if (error || stderr) {
-				resolve(null);
-			} else {
-				resolve(stdout.trim());
-			}
-		});
-	});
+    return new Promise(resolve => {
+        exec(`npm show ${packageName} version`, (error, stdout, stderr) => {
+            if (error || stderr) {
+                resolve(null);
+            } else {
+                resolve(stdout.trim());
+            }
+        });
+    });
 }
 
 function deactivate() {}
 
 module.exports = {
-	activate,
-	deactivate,
+    activate,
+    deactivate,
 };