fix: cannot execute code --version in windows and linux

This commit is contained in:
Levi Yan
2025-01-08 18:36:59 +08:00
parent 7e470461eb
commit bdf708597d
3 changed files with 68 additions and 69 deletions

View File

@@ -1,13 +1,14 @@
import { exec } from 'child_process';
import * as http from 'http';
import * as https from 'https';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { BlobOptions } from 'buffer';
import * as vscode from 'vscode';
const {
generateKeyPairSync,
} = require('node:crypto')
const axios = require('axios');
const cheerio = require('cheerio');
export function fetch(url: string): Promise<string> {
// determine the library to use (based on the url protocol)
@@ -38,26 +39,29 @@ export const Sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
export function getVsCodeCommitId(): Promise<string> {
return new Promise((resolve, reject) => {
exec('code --version', (error, stdout, stderr) => {
if (error) {
reject('Error occurred:' + error.message);
return;
}
if (stderr) {
reject('Error output:' + stderr);
return;
}
const lines = stdout.trim().split('\n');
if (lines.length > 1) {
const commitId = lines[1]; // 第二行是 commit ID
resolve(commitId);
} else {
reject('Unexpected output format:' + stdout);
}
});
})
export async function getVsCodeCommitId(): Promise<string> {
// 获取vscode version
const version = vscode.version
// 根据version提取相应的release页面中的commitid
try{
const { data } = await axios.get(`https://github.com/microsoft/vscode/releases/tag/${version}`);
// Load the HTML into cheerio
const $ = cheerio.load(data);
// Find the <a> tag with the 'data-hovercard-type="commit"' attribute
const commitLink = $('a[data-hovercard-type="commit"]');
// Extract the href attribute and commit hash
const href = commitLink.attr('href'); // href example: /microsoft/vscode/commit/fabdb6a30b49f79a7aba0f2ad9df9b399473380f
const commitHash = href.split('/').pop();
console.log('Commit Hash:', commitHash);
return commitHash
} catch(error) {
console.error('Failed to get commit id: ' + error)
return ""
}
}
export function getDefaultPrivateKeyPath(): string {