-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-extensions.js
More file actions
executable file
·156 lines (138 loc) · 3.95 KB
/
install-extensions.js
File metadata and controls
executable file
·156 lines (138 loc) · 3.95 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env node
// @ts-check
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
function main() {
console.log("📥 Installing VSCode/Cursor Extensions from Lists...");
install_editor("code", "linux-vscode/.vscode/extensions/list.txt");
install_editor("cursor", "linux-cursor/.cursor/extensions/list.txt");
console.log("✅ Extension installation complete!");
}
/**
* @param {string} command - Editor command ("code" or "cursor")
* @param {string} list_file - Relative path to extension list file
*/
function install_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 (!fs.existsSync(list_file_path)) {
console.log(
` ⚠️ Extensions list not found. Skipping extensions install.`
);
return;
}
if (command_path == null) {
console.log(` ⚠️ Missing ${command} CLI. Skipping extension install.`);
return;
}
pull_from_extensions_list(command_path, list_file_path);
}
/**
* Sync local extensions to match the extension list file
* @param {string} command_path - Full path to editor CLI command
* @param {string} list_file_path - Full path to the list.txt file
*/
function pull_from_extensions_list(command_path, list_file_path) {
// Read desired extensions from file
const desired_extensions = new Set(read_list(list_file_path));
const installed_extensions = new Set(get_installed_extensions(command_path));
const to_install = [...desired_extensions].filter(
(ext) => !installed_extensions.has(ext)
);
const to_uninstall = [...installed_extensions].filter(
(ext) => !desired_extensions.has(ext)
);
install_extensions(command_path, to_install);
uninstall_extensions(command_path, to_uninstall);
if (to_install.length > 0 || to_uninstall.length > 0) {
console.log(
` ✅ Sync complete: ${to_install.length} installed, ${to_uninstall.length} uninstalled`
);
} else {
console.log(
` ✅ Already in sync: ${installed_extensions.size} 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();
}
/**
* @param {string} command_path - Full path to editor CLI command
* @param {string[]} extensions
*/
function install_extensions(command_path, extensions) {
if (extensions.length === 0) {
return;
}
execSync(
`${command_path} ${extensions
.map((ext) => `--install-extension ${ext}`)
.join(" ")}`,
{
stdio: "inherit",
}
);
}
/**
* @param {string} command_path - Full path to editor CLI command
* @param {string[]} extensions
*/
function uninstall_extensions(command_path, extensions) {
console.log(
"Skipping uninstall because Cursor CLI does not support uninstalling multiple extensions."
);
for (const ext of extensions) {
console.log(`Skipping ${ext}`);
}
return;
// TODO: restore when the issue is resolved: https://forum.cursor.com/t/command-line-list-extensions/103565/13
if (extensions.length === 0) {
return;
}
execSync(
`${command_path} ${extensions
.map((ext) => `--uninstall_extension ${ext}`)
.join(" ")}`,
{
stdio: "inherit",
}
);
}
/**
* @param {string} list_file_path - Full path to the list.txt file
*/
function read_list(list_file_path) {
return fs
.readFileSync(list_file_path, "utf-8")
.trim()
.split("\n")
.filter(Boolean);
}
main();