codify-plugin-lib 1.0.182-beta62 → 1.0.182-beta64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,25 @@ export declare enum Shell {
8
8
  CSH = "csh",
9
9
  FISH = "fish"
10
10
  }
11
+ export declare enum LinuxDistro {
12
+ ARCH = "arch",
13
+ CENTOS = "centos",
14
+ DEBIAN = "debian",
15
+ FEDORA = "fedora",
16
+ RHEL = "rhel",
17
+ UBUNTU = "ubuntu",
18
+ ALPINE = "alpine",
19
+ AMAZON_LINUX = "amzn",
20
+ OPENSUSE = "opensuse",
21
+ SUSE = "sles",
22
+ MANJARO = "manjaro",
23
+ MINT = "linuxmint",
24
+ POP_OS = "pop",
25
+ ELEMENTARY_OS = "elementary",
26
+ KALI = "kali",
27
+ GENTOO = "gentoo",
28
+ SLACKWARE = "slackware"
29
+ }
11
30
  export interface SystemInfo {
12
31
  os: OS;
13
32
  shell: Shell;
@@ -32,7 +51,13 @@ export declare const Utils: {
32
51
  * Installs a package via the system package manager. This will use Homebrew on macOS and apt on Ubuntu/Debian or dnf on Fedora.
33
52
  * @param packageName
34
53
  */
35
- installViaPkgMgr(packageName: string): Promise<boolean>;
54
+ installViaPkgMgr(packageName: string): Promise<void>;
36
55
  uninstallViaPkgMgr(packageName: string): Promise<boolean>;
37
- linuxDistro(): Promise<"arch" | "centos" | "debian" | "fedora" | "rhel" | "ubuntu" | undefined>;
56
+ getLinuxDistro(): Promise<LinuxDistro | undefined>;
57
+ isUbuntu(): Promise<boolean>;
58
+ isDebian(): Promise<boolean>;
59
+ isArch(): Promise<boolean>;
60
+ isCentOS(): Promise<boolean>;
61
+ isFedora(): Promise<boolean>;
62
+ isRHEL(): Promise<boolean>;
38
63
  };
@@ -14,6 +14,26 @@ export var Shell;
14
14
  Shell["CSH"] = "csh";
15
15
  Shell["FISH"] = "fish";
16
16
  })(Shell || (Shell = {}));
17
+ export var LinuxDistro;
18
+ (function (LinuxDistro) {
19
+ LinuxDistro["ARCH"] = "arch";
20
+ LinuxDistro["CENTOS"] = "centos";
21
+ LinuxDistro["DEBIAN"] = "debian";
22
+ LinuxDistro["FEDORA"] = "fedora";
23
+ LinuxDistro["RHEL"] = "rhel";
24
+ LinuxDistro["UBUNTU"] = "ubuntu";
25
+ LinuxDistro["ALPINE"] = "alpine";
26
+ LinuxDistro["AMAZON_LINUX"] = "amzn";
27
+ LinuxDistro["OPENSUSE"] = "opensuse";
28
+ LinuxDistro["SUSE"] = "sles";
29
+ LinuxDistro["MANJARO"] = "manjaro";
30
+ LinuxDistro["MINT"] = "linuxmint";
31
+ LinuxDistro["POP_OS"] = "pop";
32
+ LinuxDistro["ELEMENTARY_OS"] = "elementary";
33
+ LinuxDistro["KALI"] = "kali";
34
+ LinuxDistro["GENTOO"] = "gentoo";
35
+ LinuxDistro["SLACKWARE"] = "slackware";
36
+ })(LinuxDistro || (LinuxDistro = {}));
17
37
  export const Utils = {
18
38
  getUser() {
19
39
  return os.userInfo().username;
@@ -159,28 +179,38 @@ Brew can be installed using Codify:
159
179
  const $ = getPty();
160
180
  if (Utils.isMacOS()) {
161
181
  await this.assertBrewInstalled();
162
- const { status } = await $.spawnSafe(`brew install ${packageName}`, { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
163
- return status === SpawnStatus.SUCCESS;
182
+ await $.spawn(`brew install ${packageName}`, { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
164
183
  }
165
184
  if (Utils.isLinux()) {
166
185
  const isAptInstalled = await $.spawnSafe('which apt');
167
186
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
168
- const { status } = await $.spawnSafe(`apt -y install ${packageName}`, { interactive: true, requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
169
- return status === SpawnStatus.SUCCESS;
187
+ await $.spawn('apt-get update', { requiresRoot: true });
188
+ const { status, data } = await $.spawnSafe(`apt-get -y install ${packageName}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
189
+ if (status === SpawnStatus.ERROR && data.includes('E: dpkg was interrupted, you must manually run \'sudo dpkg --configure -a\' to correct the problem.')) {
190
+ await $.spawn('dpkg --configure -a', { requiresRoot: true });
191
+ await $.spawn(`apt-get -y install ${packageName}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
192
+ return;
193
+ }
194
+ if (status === SpawnStatus.ERROR) {
195
+ throw new Error(`Failed to install package ${packageName} via apt: ${data}`);
196
+ }
170
197
  }
171
198
  const isDnfInstalled = await $.spawnSafe('which dnf');
172
199
  if (isDnfInstalled.status === SpawnStatus.SUCCESS) {
173
- const { status } = await $.spawnSafe(`dnf install ${packageName} -y`, { interactive: true, requiresRoot: true });
174
- return status === SpawnStatus.SUCCESS;
200
+ await $.spawn('dnf update', { requiresRoot: true });
201
+ await $.spawn(`dnf install ${packageName} -y`, { requiresRoot: true });
175
202
  }
176
203
  const isYumInstalled = await $.spawnSafe('which yum');
177
204
  if (isYumInstalled.status === SpawnStatus.SUCCESS) {
178
- const { status } = await $.spawnSafe(`yum install ${packageName} -y`, { interactive: true, requiresRoot: true });
179
- return status === SpawnStatus.SUCCESS;
205
+ await $.spawn('yum update', { requiresRoot: true });
206
+ await $.spawn(`yum install ${packageName} -y`, { requiresRoot: true });
207
+ }
208
+ const isPacmanInstalled = await $.spawnSafe('which pacman');
209
+ if (isPacmanInstalled.status === SpawnStatus.SUCCESS) {
210
+ await $.spawn('pacman -Syu', { requiresRoot: true });
211
+ await $.spawn(`pacman -S ${packageName} --noconfirm`, { requiresRoot: true });
180
212
  }
181
- return false;
182
213
  }
183
- return false;
184
214
  },
185
215
  async uninstallViaPkgMgr(packageName) {
186
216
  const $ = getPty();
@@ -192,31 +222,50 @@ Brew can be installed using Codify:
192
222
  if (Utils.isLinux()) {
193
223
  const isAptInstalled = await $.spawnSafe('which apt');
194
224
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
195
- const { status } = await $.spawnSafe(`apt autoremove -y --purge ${packageName}`, { interactive: true, requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
225
+ const { status } = await $.spawnSafe(`apt-get autoremove -y --purge ${packageName}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
196
226
  return status === SpawnStatus.SUCCESS;
197
227
  }
198
228
  const isDnfInstalled = await $.spawnSafe('which dnf');
199
229
  if (isDnfInstalled.status === SpawnStatus.SUCCESS) {
200
- const { status } = await $.spawnSafe(`dnf autoremove ${packageName} -y`, { interactive: true, requiresRoot: true });
230
+ const { status } = await $.spawnSafe(`dnf autoremove ${packageName} -y`, { requiresRoot: true });
201
231
  return status === SpawnStatus.SUCCESS;
202
232
  }
203
233
  const isYumInstalled = await $.spawnSafe('which yum');
204
234
  if (isYumInstalled.status === SpawnStatus.SUCCESS) {
205
- const { status } = await $.spawnSafe(`yum autoremove ${packageName} -y`, { interactive: true, requiresRoot: true });
235
+ const { status } = await $.spawnSafe(`yum autoremove ${packageName} -y`, { requiresRoot: true });
206
236
  return status === SpawnStatus.SUCCESS;
207
237
  }
208
238
  return false;
209
239
  }
210
240
  return false;
211
241
  },
212
- async linuxDistro() {
242
+ async getLinuxDistro() {
213
243
  const osRelease = await fs.readFile('/etc/os-release', 'utf8');
214
244
  const lines = osRelease.split('\n');
215
245
  for (const line of lines) {
216
246
  if (line.startsWith('ID=')) {
217
- return line.slice(3).trim();
247
+ const distroId = line.slice(3).trim().replace(/"/g, '');
248
+ return Object.values(LinuxDistro).includes(distroId) ? distroId : undefined;
218
249
  }
219
250
  }
220
251
  return undefined;
221
- }
252
+ },
253
+ async isUbuntu() {
254
+ return (await this.getLinuxDistro()) === LinuxDistro.UBUNTU;
255
+ },
256
+ async isDebian() {
257
+ return (await this.getLinuxDistro()) === LinuxDistro.DEBIAN;
258
+ },
259
+ async isArch() {
260
+ return (await this.getLinuxDistro()) === LinuxDistro.ARCH;
261
+ },
262
+ async isCentOS() {
263
+ return (await this.getLinuxDistro()) === LinuxDistro.CENTOS;
264
+ },
265
+ async isFedora() {
266
+ return (await this.getLinuxDistro()) === LinuxDistro.FEDORA;
267
+ },
268
+ async isRHEL() {
269
+ return (await this.getLinuxDistro()) === LinuxDistro.RHEL;
270
+ },
222
271
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.182-beta62",
3
+ "version": "1.0.182-beta64",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -18,6 +18,26 @@ export enum Shell {
18
18
  FISH = 'fish',
19
19
  }
20
20
 
21
+ export enum LinuxDistro {
22
+ ARCH = 'arch',
23
+ CENTOS = 'centos',
24
+ DEBIAN = 'debian',
25
+ FEDORA = 'fedora',
26
+ RHEL = 'rhel',
27
+ UBUNTU = 'ubuntu',
28
+ ALPINE = 'alpine',
29
+ AMAZON_LINUX = 'amzn',
30
+ OPENSUSE = 'opensuse',
31
+ SUSE = 'sles',
32
+ MANJARO = 'manjaro',
33
+ MINT = 'linuxmint',
34
+ POP_OS = 'pop',
35
+ ELEMENTARY_OS = 'elementary',
36
+ KALI = 'kali',
37
+ GENTOO = 'gentoo',
38
+ SLACKWARE = 'slackware',
39
+ }
40
+
21
41
  export interface SystemInfo {
22
42
  os: OS;
23
43
  shell: Shell;
@@ -196,38 +216,51 @@ Brew can be installed using Codify:
196
216
  * Installs a package via the system package manager. This will use Homebrew on macOS and apt on Ubuntu/Debian or dnf on Fedora.
197
217
  * @param packageName
198
218
  */
199
- async installViaPkgMgr(packageName: string): Promise<boolean> {
219
+ async installViaPkgMgr(packageName: string): Promise<void> {
200
220
  const $ = getPty();
201
221
 
202
222
  if (Utils.isMacOS()) {
203
223
  await this.assertBrewInstalled();
204
- const { status } = await $.spawnSafe(`brew install ${packageName}`, { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
205
- return status === SpawnStatus.SUCCESS;
224
+ await $.spawn(`brew install ${packageName}`, { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
206
225
  }
207
226
 
208
227
  if (Utils.isLinux()) {
209
228
  const isAptInstalled = await $.spawnSafe('which apt');
210
229
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
211
- const { status } = await $.spawnSafe(`apt -y install ${packageName}`, { interactive: true, requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
212
- return status === SpawnStatus.SUCCESS;
230
+ await $.spawn('apt-get update', { requiresRoot: true });
231
+ const { status, data } = await $.spawnSafe(`apt-get -y install ${packageName}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
232
+
233
+ if (status === SpawnStatus.ERROR && data.includes('E: dpkg was interrupted, you must manually run \'sudo dpkg --configure -a\' to correct the problem.')) {
234
+ await $.spawn('dpkg --configure -a', { requiresRoot: true });
235
+ await $.spawn(`apt-get -y install ${packageName}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
236
+
237
+ return;
238
+ }
239
+
240
+ if (status === SpawnStatus.ERROR) {
241
+ throw new Error(`Failed to install package ${packageName} via apt: ${data}`);
242
+ }
213
243
  }
214
244
 
215
245
  const isDnfInstalled = await $.spawnSafe('which dnf');
216
246
  if (isDnfInstalled.status === SpawnStatus.SUCCESS) {
217
- const { status } = await $.spawnSafe(`dnf install ${packageName} -y`, { interactive: true, requiresRoot: true });
218
- return status === SpawnStatus.SUCCESS;
247
+ await $.spawn('dnf update', { requiresRoot: true });
248
+ await $.spawn(`dnf install ${packageName} -y`, { requiresRoot: true });
219
249
  }
220
250
 
221
251
  const isYumInstalled = await $.spawnSafe('which yum');
222
252
  if (isYumInstalled.status === SpawnStatus.SUCCESS) {
223
- const { status } = await $.spawnSafe(`yum install ${packageName} -y`, { interactive: true, requiresRoot: true });
224
- return status === SpawnStatus.SUCCESS;
253
+ await $.spawn('yum update', { requiresRoot: true });
254
+ await $.spawn(`yum install ${packageName} -y`, { requiresRoot: true });
225
255
  }
226
256
 
227
- return false;
228
- }
257
+ const isPacmanInstalled = await $.spawnSafe('which pacman');
258
+ if (isPacmanInstalled.status === SpawnStatus.SUCCESS) {
259
+ await $.spawn('pacman -Syu', { requiresRoot: true });
260
+ await $.spawn(`pacman -S ${packageName} --noconfirm`, { requiresRoot: true });
261
+ }
229
262
 
230
- return false;
263
+ }
231
264
  },
232
265
 
233
266
  async uninstallViaPkgMgr(packageName: string): Promise<boolean> {
@@ -242,19 +275,19 @@ Brew can be installed using Codify:
242
275
  if (Utils.isLinux()) {
243
276
  const isAptInstalled = await $.spawnSafe('which apt');
244
277
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
245
- const { status } = await $.spawnSafe(`apt autoremove -y --purge ${packageName}`, { interactive: true, requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
278
+ const { status } = await $.spawnSafe(`apt-get autoremove -y --purge ${packageName}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' } });
246
279
  return status === SpawnStatus.SUCCESS;
247
280
  }
248
281
 
249
282
  const isDnfInstalled = await $.spawnSafe('which dnf');
250
283
  if (isDnfInstalled.status === SpawnStatus.SUCCESS) {
251
- const { status } = await $.spawnSafe(`dnf autoremove ${packageName} -y`, { interactive: true, requiresRoot: true });
284
+ const { status } = await $.spawnSafe(`dnf autoremove ${packageName} -y`, { requiresRoot: true });
252
285
  return status === SpawnStatus.SUCCESS;
253
286
  }
254
287
 
255
288
  const isYumInstalled = await $.spawnSafe('which yum');
256
289
  if (isYumInstalled.status === SpawnStatus.SUCCESS) {
257
- const { status } = await $.spawnSafe(`yum autoremove ${packageName} -y`, { interactive: true, requiresRoot: true });
290
+ const { status } = await $.spawnSafe(`yum autoremove ${packageName} -y`, { requiresRoot: true });
258
291
  return status === SpawnStatus.SUCCESS;
259
292
  }
260
293
 
@@ -264,18 +297,42 @@ Brew can be installed using Codify:
264
297
  return false;
265
298
  },
266
299
 
267
-
268
- async linuxDistro(): Promise<'arch' | 'centos' | 'debian' | 'fedora' | 'rhel' | 'ubuntu' | undefined> {
300
+ async getLinuxDistro(): Promise<LinuxDistro | undefined> {
269
301
  const osRelease = await fs.readFile('/etc/os-release', 'utf8');
270
302
  const lines = osRelease.split('\n');
271
303
  for (const line of lines) {
272
304
  if (line.startsWith('ID=')) {
273
- return line.slice(3).trim() as any;
305
+ const distroId = line.slice(3).trim().replace(/"/g, '');
306
+ return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
274
307
  }
275
308
  }
276
309
 
277
310
  return undefined;
278
- }
311
+ },
312
+
313
+ async isUbuntu(): Promise<boolean> {
314
+ return (await this.getLinuxDistro()) === LinuxDistro.UBUNTU;
315
+ },
316
+
317
+ async isDebian(): Promise<boolean> {
318
+ return (await this.getLinuxDistro()) === LinuxDistro.DEBIAN;
319
+ },
320
+
321
+ async isArch(): Promise<boolean> {
322
+ return (await this.getLinuxDistro()) === LinuxDistro.ARCH;
323
+ },
324
+
325
+ async isCentOS(): Promise<boolean> {
326
+ return (await this.getLinuxDistro()) === LinuxDistro.CENTOS;
327
+ },
328
+
329
+ async isFedora(): Promise<boolean> {
330
+ return (await this.getLinuxDistro()) === LinuxDistro.FEDORA;
331
+ },
332
+
333
+ async isRHEL(): Promise<boolean> {
334
+ return (await this.getLinuxDistro()) === LinuxDistro.RHEL;
335
+ },
279
336
  };
280
337
 
281
338