Skip to content

Commit f0b804d

Browse files
committed
Fixed vscode
1 parent 5ac4935 commit f0b804d

4 files changed

Lines changed: 63 additions & 79 deletions

File tree

package-lock.json

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"ajv": "^8.12.0",
2727
"ajv-formats": "^2.1.1",
2828
"chalk": "^5.3.0",
29-
"codify-plugin-lib": "1.0.182-beta64",
30-
"codify-schemas": "1.0.86-beta7",
29+
"codify-plugin-lib": "1.0.182-beta66",
30+
"codify-schemas": "1.0.86-beta11",
3131
"debug": "^4.3.4",
3232
"lodash.isequal": "^4.5.0",
3333
"nanoid": "^5.0.9",
@@ -52,6 +52,7 @@
5252
"@types/debug": "4.1.12",
5353
"@types/lodash.isequal": "^4.5.8",
5454
"@types/mock-fs": "^4.13.4",
55+
"@types/uuid": "10.0.0",
5556
"@types/node": "^18",
5657
"@types/plist": "^3.0.5",
5758
"@types/semver": "^7.5.4",

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FileResource } from './resources/file/file.js';
1313
import { RemoteFileResource } from './resources/file/remote-file.js';
1414
import { GitResource } from './resources/git/git/git-resource.js';
1515
import { GitLfsResource } from './resources/git/lfs/git-lfs.js';
16-
import { GitCloneResource } from './resources/git/repository/git-repository.js';
16+
import { GitRepositoryResource } from './resources/git/repository/git-repository.js';
1717
import { WaitGithubSshKey } from './resources/git/wait-github-ssh-key/wait-github-ssh-key.js';
1818
import { HomebrewResource } from './resources/homebrew/homebrew.js';
1919
import { JenvResource } from './resources/java/jenv/jenv.js';
@@ -60,7 +60,7 @@ runPlugin(Plugin.create(
6060
new JenvResource(),
6161
new PgcliResource(),
6262
new VscodeResource(),
63-
new GitCloneResource(),
63+
new GitRepositoryResource(),
6464
new AndroidStudioResource(),
6565
new AsdfResource(),
6666
new AsdfPluginResource(),

src/resources/vscode/vscode.ts

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
DestroyPlan,
44
FileUtils,
55
getPty,
6-
LinuxDistro,
76
Resource,
87
ResourceSettings,
98
Utils
@@ -49,12 +48,10 @@ export class VscodeResource extends Resource<VscodeConfig> {
4948
}
5049

5150
override async create(plan: CreatePlan<VscodeConfig>): Promise<void> {
52-
const $ = getPty();
53-
5451
if (Utils.isMacOS()) {
55-
await this.installMacOS($, plan);
52+
await this.installMacOS(plan);
5653
} else if (Utils.isLinux()) {
57-
await this.installLinux($, plan);
54+
await this.installLinux(plan);
5855
} else {
5956
throw new Error('Unsupported operating system');
6057
}
@@ -68,27 +65,13 @@ export class VscodeResource extends Resource<VscodeConfig> {
6865
const location = path.join(directory, `"${VSCODE_APPLICATION_NAME}"`);
6966
await $.spawn(`rm -rf ${location}`);
7067
} else if (Utils.isLinux()) {
71-
const distro = await Utils.getLinuxDistro();
72-
73-
switch(distro) {
74-
case LinuxDistro.DEBIAN:
75-
case LinuxDistro.MANJARO:
76-
case LinuxDistro.UBUNTU:
77-
case LinuxDistro.MINT: {
78-
await $.spawnSafe('apt-get remove code -y', { requiresRoot: true });
79-
return;
80-
}
81-
82-
case LinuxDistro.RHEL:
83-
case LinuxDistro.CENTOS:
84-
case LinuxDistro.FEDORA: {
85-
await $.spawnSafe('dnf remove code -y', { requiresRoot: true });
86-
return;
87-
}
88-
89-
default: {
90-
throw new Error('Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.');
91-
}
68+
69+
if (Utils.isDebianBased()) {
70+
await $.spawnSafe('apt-get remove code -y', { requiresRoot: true });
71+
} else if (Utils.isRedhatBased()) {
72+
await $.spawnSafe('dnf remove code -y', { requiresRoot: true });
73+
} else {
74+
throw new Error('Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.');
9275
}
9376

9477
// Remove user data and config
@@ -119,7 +102,8 @@ export class VscodeResource extends Resource<VscodeConfig> {
119102
return false;
120103
}
121104

122-
private async installMacOS($: ReturnType<typeof getPty>, plan: CreatePlan<VscodeConfig>): Promise<void> {
105+
private async installMacOS(plan: CreatePlan<VscodeConfig>): Promise<void> {
106+
const $ = getPty();
123107
// Create a temporary tmp dir
124108
const temporaryDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-'));
125109

@@ -143,41 +127,31 @@ export class VscodeResource extends Resource<VscodeConfig> {
143127

144128
// Detect distribution and architecture
145129
const isArm = await Utils.isArmArch();
146-
const distro = await Utils.getLinuxDistro();
147-
148-
switch(distro) {
149-
case LinuxDistro.DEBIAN:
150-
case LinuxDistro.MANJARO:
151-
case LinuxDistro.UBUNTU:
152-
case LinuxDistro.MINT: {
153-
const downloadLink = DOWNLOAD_URL_BASE + (isArm ? '?build=stable&os=linux-deb-arm64' : '?build=stable&os=linux-deb-x64');
154-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-'));
155-
const vscodeDebPath = path.join(tmpDir, 'vscode.deb');
156-
157-
try {
158-
await FileUtils.downloadFile(downloadLink, vscodeDebPath);
159-
160-
await $.spawn('debconf-set-selections <<< "code code/add-microsoft-repo boolean true"', { requiresRoot: true });
161-
await $.spawn('apt-get install ./vscode.deb -y', { cwd: tmpDir, requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
162-
} finally {
163-
// await fs.rm(tmpDir, { recursive: true, force: true });
164-
}
165-
166-
return;
167-
}
168130

169-
case LinuxDistro.RHEL:
170-
case LinuxDistro.CENTOS:
171-
case LinuxDistro.FEDORA: {
172-
await $.spawn('rpm --import https://packages.microsoft.com/keys/microsoft.asc &&\n' +
173-
'echo -e "[code]\\nname=Visual Studio Code\\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\\nenabled=1\\nautorefresh=1\\ntype=rpm-md\\ngpgcheck=1\\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | tee /etc/yum.repos.d/vscode.repo > /dev/null', { requiresRoot: true });
174-
await $.spawn('dnf check-update && dnf install code -y', { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
175-
return;
176-
}
131+
if (Utils.isDebianBased()) {
132+
const downloadLink = DOWNLOAD_URL_BASE + (isArm ? '?build=stable&os=linux-deb-arm64' : '?build=stable&os=linux-deb-x64');
133+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-'));
134+
const vscodeDebPath = path.join(tmpDir, 'vscode.deb');
177135

178-
default: {
179-
throw new Error('Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.');
136+
try {
137+
await FileUtils.downloadFile(downloadLink, vscodeDebPath);
138+
139+
await $.spawn('debconf-set-selections <<< "code code/add-microsoft-repo boolean true"', { requiresRoot: true });
140+
await $.spawn('apt-get install ./vscode.deb -y', { cwd: tmpDir, requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
141+
} finally {
142+
await fs.rm(tmpDir, { recursive: true, force: true });
180143
}
144+
145+
return;
181146
}
147+
148+
if (Utils.isRedhatBased()) {
149+
await $.spawn('rpm --import https://packages.microsoft.com/keys/microsoft.asc &&\n' +
150+
'echo -e "[code]\\nname=Visual Studio Code\\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\\nenabled=1\\nautorefresh=1\\ntype=rpm-md\\ngpgcheck=1\\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | tee /etc/yum.repos.d/vscode.repo > /dev/null', { requiresRoot: true });
151+
await $.spawn('dnf check-update && dnf install code -y', { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
152+
return;
153+
}
154+
155+
throw new Error('Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.');
182156
}
183157
}

0 commit comments

Comments
 (0)