2024-08-22 11:48:02 +08:00
|
|
|
import { exec } from 'child_process';
|
2024-09-18 13:53:31 +08:00
|
|
|
import * as http from 'http';
|
|
|
|
import * as https from 'https';
|
|
|
|
|
|
|
|
export function fetch(url: string): Promise<string> {
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-08-22 11:48:02 +08:00
|
|
|
|
2024-07-30 23:35:52 +08:00
|
|
|
export const Sleep = (ms:number)=> {
|
|
|
|
return new Promise(resolve=>setTimeout(resolve, ms))
|
2024-08-22 11:48:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2024-09-18 13:53:31 +08:00
|
|
|
}
|