-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_extensions.js
More file actions
52 lines (43 loc) · 1.7 KB
/
update_extensions.js
File metadata and controls
52 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');
const extensionsJsonPath = path.join(__dirname, 'extensions.json');
console.log('Fetching VS Code extensions list...');
class MyFoo { }
// 检测 code 命令是否可用,并执行
exec('code --list-extensions', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing code command: ${error.message}`);
console.error('Please ensure VS Code is installed and the "code" command is in your PATH.');
// 对于 macOS 用户提示如何安装 code 命令
if (process.platform === 'darwin') {
console.log('On macOS, press F1 in VS Code and type "Shell Command: Install \'code\' command in PATH".');
}
return;
}
if (stderr) {
// 有些警告信息可能会输出到 stderr,但不代表失败
console.warn(`Warning: ${stderr}`);
}
// 处理输出:按行分割,去除空行
const extensions = stdout
.split(/\r?\n/)
.map(line => line.trim())
.filter(line => line !== '');
if (extensions.length === 0) {
console.warn('No extensions found.');
return;
}
// 构建 JSON 对象
const jsonContent = {
recommendations: extensions.sort() // 顺便排个序
};
try {
// 写入文件
fs.writeFileSync(extensionsJsonPath, JSON.stringify(jsonContent, null, 2), 'utf8');
console.log(`Successfully updated extensions.json with ${extensions.length} extensions.`);
console.log(`File saved to: ${extensionsJsonPath}`);
} catch (writeError) {
console.error(`Error writing to file: ${writeError.message}`);
}
});