-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave-extensions.js
More file actions
executable file
·84 lines (72 loc) · 2.13 KB
/
save-extensions.js
File metadata and controls
executable file
·84 lines (72 loc) · 2.13 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
// @ts-check
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
function main() {
console.log("💾 Saving VSCode/Cursor Extension Lists...");
save_editor("code", "linux-vscode/.vscode/extensions/list.txt");
save_editor("cursor", "linux-cursor/.cursor/extensions/list.txt");
console.log("✅ Extension lists saved!");
}
/**
* @param {string} command - Editor command ("code" or "cursor")
* @param {string} list_file - Relative path to extension list file
*/
function save_editor(command, list_file) {
console.log(`📋 ${command.toUpperCase()}:`);
const list_file_path = path.join(__dirname, list_file);
const command_path = get_command_path(command);
if (command_path == null) {
console.log(` ⚠️ Missing ${command} CLI. Skipping extension save.`);
return;
}
const installed_extensions = get_installed_extensions(command_path);
write_list(list_file_path, installed_extensions);
}
/**
* @param {string} command
* @returns {string|null}
*/
function get_command_path(command) {
try {
const result = execSync(`command -v ${command}`, {
encoding: "utf-8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
return result || null;
} catch {
return null;
}
}
/**
* @param {string} command_path - Full path to editor CLI command
*/
function get_installed_extensions(command_path) {
return execSync(`${command_path} --list-extensions`, {
encoding: "utf-8",
})
.trim()
.split("\n")
.filter(Boolean)
.sort();
}
/**
* Update the extension list file with currently installed extensions
* @param {string} list_file_path - Full path to the list.txt file
* @param {string[]} extensions
*/
function write_list(list_file_path, extensions) {
// Ensure directory exists
const dir = path.dirname(list_file_path);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(list_file_path, extensions.join("\n") + "\n");
console.log(
` ✅ List updated: ${
extensions.length
} extensions written to ${path.relative(__dirname, list_file_path)}`
);
}
main();