소스 검색

[vscode]Add stdf-vscode-extension

dufu1991 3 년 전
부모
커밋
f1ebcbc78d

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

@@ -0,0 +1,3 @@
+# 0.0.1
+
+- Init version.

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

@@ -0,0 +1,3 @@
+# 0.0.1
+
+- 初始版本。

+ 21 - 0
packages/vscode-extension/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 dufu1991
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

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

@@ -0,0 +1,13 @@
+[English](https://github.com/dufu1991/stdf/blob/main/packages/vscode-extension/README.md)
+
+# 介绍
+
+一个 VS Code 插件,用于在使用 [STDF](https://stdf.design) 时提供一些便利功能。
+
+# 安装
+
+在 VS Code 中搜索 `stdf`,然后点击安装。
+
+# 许可证
+
+本项目基于 [MIT 许可证](https://github.com/dufu1991/stdf/blob/main/LICENSE)。请随意享受并贡献给这个开源项目。

+ 97 - 0
packages/vscode-extension/README_CN.md

@@ -0,0 +1,97 @@
+[English](https://github.com/dufu1991/stdf/blob/main/packages/vscode-extension/README.md)
+
+# 介绍
+
+一个 VS Code 插件,用于在使用 [STDF](https://stdf.design) 时提供一些便利功能。
+
+# 安装
+
+在 VS Code 中搜索 `stdf`,然后点击安装。
+
+一个用于创建新的 [STDF](https://stdf.design) 项目的命令行工具。只需运行以下命令...
+
+使用 PNPM:
+
+```bash
+pnpm create stdf
+```
+
+使用 NPM:
+
+```bash
+npm create stdf@latest
+# 或者
+npm init stdf@latest
+# 或者
+npx create-stdf@latest
+```
+
+...然后按照提示进行操作。
+
+你也可以通过额外的命令行选项直接指定项目名称和要使用的模板。例如,如果要使用 **Vite + Svelte + Tailwind + STDF** 模板创建一个名为 `my-app` 的新项目,请运行:
+
+```bash
+# pnpm
+pnpm create stdf my-app
+
+# npm
+npm create stdf@latest my-app
+```
+
+如果要使用 **Vite + UnoCSS + Svelte + STDF** 模板,请运行:
+
+```bash
+# pnpm
+pnpm create stdf my-app --template vu
+# 或者
+pnpm create stdf my-app -t vu
+
+# npm
+npm create stdf@latest my-app --template vu
+# 或者
+npm create stdf@latest my-app -t vu
+```
+
+模板预设包括:
+
+| 简写 | 模板                                         | 描述     |
+| ---- | -------------------------------------------- | -------- |
+| vt   | Vite + Tailwind + Svelte + STDF              | 默认     |
+| vu   | Vite + UnoCSS + Svelte + STDF                | -        |
+| skt  | SvelteKit + Tailwind + STDF                  | 尚未适配 |
+| sku  | SvelteKit + UnoCSS + STDF                    | 尚未适配 |
+| vtt  | Vite + Tailwind + TypeScript + Svelte + STDF | 尚未适配 |
+| vut  | Vite + UnoCSS + TypeScript + Svelte + STDF   | 尚未适配 |
+| sktt | SvelteKit + Tailwind + TypeScript + STDF     | 尚未适配 |
+| skut | SvelteKit + UnoCSS + TypeScript + STDF       | 尚未适配 |
+
+# 命令选项
+
+| 命令            | 类型   | 默认  | 描述                                                                                 |
+| --------------- | ------ | ----- | ------------------------------------------------------------------------------------ |
+| -               | string | -     | 项目名称,可以直接输入。                                                             |
+| -t / --template | string | vt    | 要使用的模板。可用的模板有:`vt`、`vu`、`skt`、`sku`、`vtt`、`vut`、`sktt`、`skut`。 |
+| -l / --language | string | en_US | 提示语言。                                                                           |
+
+# 支持的语言
+
+| 代码  | 语言         |
+| ----- | ------------ |
+| en_US | 英语(美式) |
+| zh_CN | 中文(简体) |
+| zh_TW | 中文(繁体) |
+| ja_JP | 日语         |
+| ko_KR | 韩语         |
+| es_ES | 西班牙语     |
+| ru_RU | 俄语         |
+
+例如:
+
+```bash
+pnpm create stdf my-app -l zh_CN
+```
+
+
+# 许可证
+
+本项目基于 [MIT 许可证](https://github.com/dufu1991/stdf/blob/main/LICENSE)。请随意享受并贡献给这个开源项目。

+ 54 - 0
packages/vscode-extension/package.json

@@ -0,0 +1,54 @@
+{
+    "name": "stdf-vscode-extension",
+    "displayName": "stdf-vscode-extension",
+    "description": "A VS Code extension to facilitate STDF development",
+    "version": "0.0.2",
+    "publisher": "STDF",
+    "icon": "./src/assets/stdf-vscode-extension.png",
+    "main": "./src/extension.js",
+    "engines": {
+        "vscode": "^1.27.0"
+    },
+    "scripts": {
+        "package": "vsce package",
+        "publish": "vsce publish"
+    },
+    "categories": [
+        "Programming Languages"
+    ],
+    "activationEvents": [
+        "onLanguage:svelte"
+    ],
+    "keywords": [
+        "svelte",
+        "stdf",
+        "component",
+        "api"
+    ],
+    "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-extension"
+    },
+    "homepage": "https://github.com/dufu1991/stdf/tree/main/packages/vscode-extension/README.md",
+    "LICENSE": "https://github.com/dufu1991/stdf/blob/main/LICENSE"
+}

BIN
packages/vscode-extension/src/assets/stdf-vscode-extension.png


+ 41 - 0
packages/vscode-extension/src/componentList.js

@@ -0,0 +1,41 @@
+const componentList = [
+    'Button',
+    'BottomSheet',
+    'Icon',
+    'Mask',
+    'Popup',
+    'Divider',
+    'Grids',
+    'Placeholder',
+    'Skeleton',
+    'IndexBar',
+    'NavBar',
+    'Pagination',
+    'Steps',
+    'TabBar',
+    'Tabs',
+    'ActionSheet',
+    'AsyncPicker',
+    'Calendar',
+    'Checkbox',
+    'Input',
+    'Picker',
+    'Radio',
+    'Rate',
+    'Slider',
+    'Switch',
+    'TimePicker',
+    'Avatar',
+    'Badge',
+    'Cell',
+    'NoticeBar',
+    'Progress',
+    'ProgressLoop',
+    'Swiper',
+    'Dialog',
+    'Loading',
+    'Modal',
+    'Toast',
+];
+
+module.exports = componentList;

+ 67 - 0
packages/vscode-extension/src/extension.js

@@ -0,0 +1,67 @@
+const vscode = require('vscode');
+const path = require('path');
+
+// 组件列表
+// components list
+const componentList = require('./componentList');
+
+function activate(context) {
+    // 如果没有设置,返回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'));
+    // 判断当前工程是否引入了 stdf 组件库
+    // Determine whether the current project has introduced the stdf component library
+    const isImportStdf = packageJson?.dependencies?.stdf || packageJson?.devDependencies?.stdf ? true : false;
+
+    // 当前文件是 .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, token) {
+                // 获取当前悬浮的单词
+                // 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/${componentspaths}/api.md 文件的内容
+                // If the word is an item in the components array, the prompt information is displayed, and the content is the content of the ../../doc/components/${componentspaths}/api.md file
+                if (componentList.includes(word)) {
+                    // 获取对应组件的 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 文件的内容
+                    // Read the contents of the api.md file
+                    const apiContent = require('fs').readFileSync(apiPath, 'utf-8');
+                    // 在 apiContent 后面添加示例、API、指南的链接
+                    // Add links to examples, API, and guides after apiContent
+                    const baseUrl = 'https://stdf.design/#/components?nav=';
+                    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'})**`;
+                    const allContent = apiContent + '\n\n' + '---' + '\n\n' + addContent;
+
+                    // 返回提示信息
+                    // Return prompt information
+                    return new vscode.Hover(allContent);
+                }
+            },
+        });
+    }
+}
+
+function deactivate() {}
+
+module.exports = {
+    activate,
+    deactivate,
+};