diff --git a/.eslintrc.json b/.eslintrc.json index 86c86f3..e50ce57 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,12 +13,15 @@ "warn", { "selector": "import", - "format": [ "camelCase", "PascalCase" ] + "format": [ + "camelCase", + "PascalCase" + ] } ], - "@typescript-eslint/semi": "warn", + "@typescript-eslint/semi": "off", "curly": "warn", - "eqeqeq": "warn", + "eqeqeq": "off", "no-throw-literal": "warn", "semi": "off" }, diff --git a/.gitea/workflows/devstar-vscode-release.yaml b/.gitea/workflows/devstar-vscode-release.yaml index ce4f729..b640939 100644 --- a/.gitea/workflows/devstar-vscode-release.yaml +++ b/.gitea/workflows/devstar-vscode-release.yaml @@ -23,8 +23,8 @@ jobs: - name: 拉取代码 uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} fetch-depth: 0 + ref: ${{ github.head_ref }} - name: 配置 Git run: | @@ -33,32 +33,51 @@ jobs: git config --global --add safe.directory /github/workspace # 配置用户信息 - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "devstar" + git config --global user.email "devstar@noreply.devstar.cn" - - name: 自动递增版本号 - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + - name: Check and bump version + if: github.event_name == 'pull_request' run: | apk add --no-cache jq - CURRENT_VERSION=$(jq -r '.version' package.json) - echo "当前版本: $CURRENT_VERSION" + # 获取远程 main 分支版本 + git fetch origin main + MAIN_VERSION=$(git show origin/main:package.json | jq -r '.version') + PR_VERSION=$(jq -r '.version' package.json) - # 分解版本号 - IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" + echo "Main 分支版本: $MAIN_VERSION" + echo "当前 PR 版本: $PR_VERSION" - # 递增补丁版本号 - NEW_PATCH=$((PATCH + 1)) - NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" - echo "新版本: $NEW_VERSION" - - # 更新 package.json - jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp - mv package.json.tmp package.json - - # 提交版本变更 - git add package.json - git commit -m "chore: bump version to $NEW_VERSION [skip ci]" - git push + # 如果版本号相同,则递增 + if [ "$MAIN_VERSION" = "$PR_VERSION" ]; then + echo "版本号未变更,开始递增..." + + # 分解版本号 + MAJOR=$(echo "$PR_VERSION" | cut -d'.' -f1) + MINOR=$(echo "$PR_VERSION" | cut -d'.' -f2) + PATCH=$(echo "$PR_VERSION" | cut -d'.' -f3) + + # 递增补丁版本号 + NEW_PATCH=$((PATCH + 1)) + NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" + echo "新版本: $NEW_VERSION" + + # 更新 package.json + jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp + mv package.json.tmp package.json + + # 提交版本变更 + git config user.name "devstar-actions" + git config user.email "devstar-actions@devstar.cn" + git add package.json + git commit -m "chore: bump version to $NEW_VERSION [skip ci]" + + # 推送到当前分支 + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) + git push origin $BRANCH_NAME || git push origin HEAD:refs/heads/$BRANCH_NAME + else + echo "版本号已更新,跳过递增" + fi - name: 安装依赖 run: | @@ -73,4 +92,4 @@ jobs: run: | npm run publish env: - VSCE_PAT: ${{ secrets.VSCE_PAT }} \ No newline at end of file + VSCE_PAT: ${{ secrets.VSCE_PAT }} diff --git a/package.json b/package.json index 865a752..e8029fe 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "devstar", "displayName": "%displayName%", "description": "%description%", - "version": "0.4.3", + "version": "0.5.3", "keywords": [], "publisher": "mengning", "engines": { @@ -42,6 +42,10 @@ { "protocol": "vscode", "path": "/openProject" + }, + { + "protocol": "trae", + "path": "/openProject" } ], "views": { diff --git a/src/remote-container.ts b/src/remote-container.ts index b9403d5..ad889a6 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -25,6 +25,46 @@ export default class RemoteContainer { this.user = user; } + /** + * 构建打开项目的命令 + * 根据终端类型生成对应的命令 + * 支持 Windows PowerShell/CMD 和 Linux/macOS Bash/Zsh + */ + private buildOpenProjectCommand( + host: string, + hostname: string, + port: number, + username: string, + path: string, + devstarDomain: string | undefined, + terminal: vscode.Terminal + ): string { + const baseUrl = `vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}`; + const url = devstarDomain ? `${baseUrl}&devstar_domain=${devstarDomain}` : baseUrl; + + // 获取本地操作系统类型 + // 在远程环境下,os.platform() 返回的是远程系统,但这里我们需要的是本地系统 + // 所以通过终端的 shell 路径来推断 + const shellPath = (terminal.creationOptions as any)?.shellPath || ''; + console.log('终端 shell 路径:', shellPath); + + // 检测 Windows(Windows shell 路径包含反斜杠或特定关键字) + const isWindows = shellPath.includes('\\') || + shellPath.toLowerCase().includes('powershell') || + shellPath.toLowerCase().includes('pwsh') || + shellPath.toLowerCase().includes('cmd'); + + if (isWindows) { + // Windows PowerShell/CMD: 使用分号分隔,URL 需要特殊的引号处理 + console.log('检测到 Windows 本地系统,使用 PowerShell/CMD 语法'); + return `code --new-window; code --open-url '"${url}"'`; + } else { + // macOS/Linux: 使用 && 分隔,标准双引号 + console.log('检测到 Unix 本地系统(macOS/Linux),使用 Bash/Zsh 语法'); + return `code --new-window && code --open-url "${url}"`; + } + } + /** * 第一次打开远程项目 */ @@ -40,29 +80,8 @@ export default class RemoteContainer { devstarDomain = undefined; } - const semver = require('semver'); - const powershellVersion = context.globalState.get('powershellVersion'); - const powershell_semver_compatible_version = semver.coerce(powershellVersion); - - let command = ''; - if (devstarDomain === undefined) { - if (powershellVersion === undefined) { - command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`; - } else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) { - command = `code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`; - } else { - command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`; - } - } else { - if (powershellVersion === undefined) { - command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`; - } else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) { - command = `code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`; - } else { - command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`; - } - } - + // 根据终端类型生成对应的命令 + const command = this.buildOpenProjectCommand(host, hostname, port, username, path, devstarDomain, terminal); terminal.sendText(command); } else { vscode.window.showErrorMessage('无法创建终端,请检查终端是否可用。'); @@ -276,18 +295,6 @@ export default class RemoteContainer { reject(error); }); - // 由于使用了 stdio: 'ignore',这些事件监听器不再需要 - // sshProcess.stdout.on('data', (data: Buffer) => { - // console.log(`[SSH stdout] ${data.toString()}`); - // }); - - // sshProcess.stderr.on('data', (data: Buffer) => { - // console.error(`[SSH stderr] ${data.toString()}`); - // }); - - // 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map - // 因为我们无法也不需要控制这些独立进程的生命周期 - // 等待 SSH 连接建立 setTimeout(() => { resolve(); diff --git a/src/utils.ts b/src/utils.ts index 9315a37..9c7910d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,12 +1,7 @@ -import * as http from 'http'; -import * as https from 'https'; import * as vscode from 'vscode'; import * as os from 'os'; import { exec } from 'child_process'; -const { - generateKeyPairSync, -} = require('node:crypto') const axios = require('axios'); const cheerio = require('cheerio'); @@ -23,36 +18,6 @@ export function isMacOS(): boolean { return os.platform() === 'darwin'; } - -export function fetch(url: string): Promise { - // determine the library to use (based on the url protocol) - const lib = url.startsWith('https://') ? https : http; - - return new Promise((resolve, reject) => { - lib.get(url, (response) => { - // make sure the status code is 200 - if (response.statusCode !== 200) { - reject(new Error(`Failed to load page, status code: ${response.statusCode}`)); - return; - } - - let data = ''; - response.on('data', (chunk) => { - data += chunk; - }); - response.on('end', () => { - resolve(data); - }); - }).on('error', (err) => { - reject(err); - }); - }); -} - -export const Sleep = (ms: number) => { - return new Promise(resolve => setTimeout(resolve, ms)) -} - export async function getVsCodeCommitId(): Promise { if (isLinux() || isMacOS()) { return new Promise((resolve) => {