Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Deploy Medium ExtractorNew to Visual Studio Code? Get it now.
Deploy Medium Extractor

Deploy Medium Extractor

liq0521

|
2 installs
| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

1. 创建插件项目

首先,您需要安装 Yeoman 和 VS Code Extension Generator:

npm install -g yo generator-code

然后,使用以下命令创建一个新的插件项目:

yo code

选择“New Extension (TypeScript)”并按照提示完成项目设置。

2. 修改插件代码

在生成的项目中,打开 src/extension.ts 文件,并添加以下代码:

import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('extension.extractFrontendInfo', async () => {
        const project = await vscode.window.showInputBox({ prompt: '输入项目名称(例如:新银行或库融)' });
        const environment = await vscode.window.showInputBox({ prompt: '输入环境(例如:UAT或prod)' });
        const version = await vscode.window.showInputBox({ prompt: '输入版本号(例如:v2.1.18)' });

        if (project && environment && version) {
            const filePath = path.join(__dirname, 'your_file_path.md'); // 替换为实际文件路径
            const data = fs.readFileSync(filePath, 'utf-8');
            const frontendInfo = extractFrontendInfo(data, project, environment, version);
            vscode.window.showInformationMessage(frontendInfo);
        }
    });

    context.subscriptions.push(disposable);
}

function extractFrontendInfo(data: string, project: string, environment: string, version: string): string {
    const regex = new RegExp(`\\|\\s*(\\d+)\\s*\\|\\s*([\\w-]+)\\s*\\|\\s*([^|]*)\\s*\\|\\s*([^|]*)\\s*\\|\\s*([^|]*)\\s*\\|\\s*([^|]*)\\s*\\|\\s*([^|]*)\\s*`, 'g');
    let match;
    let result = '';

    while ((match = regex.exec(data)) !== null) {
        const [_, index, serviceName, imageName, branch, commitID, isPublished, remark] = match;
        result += `| ${index} | ${serviceName} | ${imageName} | ${branch} | ${commitID} | ${isPublished} | ${remark} |\n`;
    }

    return result || '未找到相关信息';
}

export function deactivate() {}

3. 配置插件

在 package.json 中,添加命令和激活事件:

"contributes": {
    "commands": [
        {
            "command": "extension.extractFrontendInfo",
            "title": "提取前端介质信息"
        }
    ]
},
"activationEvents": [
    "onCommand:extension.extractFrontendInfo"
]

4. 测试插件

  1. 在 VS Code 中打开命令面板(Ctrl + Shift + P),输入并选择“提取前端介质信息”。
  2. 输入项目、环境和版本号(如新一代,测试,2.3.8)。
  3. 插件将读取指定的 Markdown 文件并提取前端介质信息。

5. 打包和发布插件

您可以使用 vsce 工具将插件打包并发布到 Visual Studio Code Marketplace。

npm install -g @vscode/vsce
@vscode/vsce package 或 npx @vscode/vsce package
vsce publish 或 npx @vscode/vsce publish

注意事项

  • 确保您在 extractFrontendInfo 函数中指定了正确的文件路径。
  • 根据实际需求,您可能需要调整正则表达式以匹配特定格式。
  • 处理文件读取和正则表达式时,请确保处理异常情况。

通过以上步骤,您可以创建一个简单的 VS Code 插件来提取前端介质信息。根据需要,您可以进一步扩展功能和优化用户体验。

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft