codify-plugin-lib 1.0.182-beta63 → 1.0.182-beta65

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.
@@ -46,6 +46,7 @@ export class Plugin {
46
46
  type: r.typeId,
47
47
  sensitiveParameters,
48
48
  operatingSystems: r.settings.operatingSystems,
49
+ linuxDistros: r.settings.linuxDistros,
49
50
  };
50
51
  })
51
52
  };
@@ -84,6 +85,7 @@ export class Plugin {
84
85
  requiredParameters: requiredPropertyNames,
85
86
  },
86
87
  operatingSystems: resource.settings.operatingSystems,
88
+ linuxDistros: resource.settings.linuxDistros,
87
89
  sensitiveParameters,
88
90
  allowMultiple
89
91
  };
@@ -1,5 +1,5 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
- import { OS, StringIndexedObject } from 'codify-schemas';
2
+ import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
3
3
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
4
4
  import { ArrayParameterSetting, DefaultParameterSetting, InputTransformation, ResourceSettings } from './resource-settings.js';
5
5
  export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
@@ -29,6 +29,7 @@ export declare class ParsedResourceSettings<T extends StringIndexedObject> imple
29
29
  dependencies?: string[] | undefined;
30
30
  transformation?: InputTransformation;
31
31
  operatingSystems: Array<OS>;
32
+ linuxDistros?: Array<LinuxDistro>;
32
33
  isSensitive?: boolean;
33
34
  private settings;
34
35
  constructor(settings: ResourceSettings<T>);
@@ -11,6 +11,7 @@ export class ParsedResourceSettings {
11
11
  dependencies;
12
12
  transformation;
13
13
  operatingSystems;
14
+ linuxDistros;
14
15
  isSensitive;
15
16
  settings;
16
17
  constructor(settings) {
@@ -1,5 +1,5 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
- import { OS, StringIndexedObject } from 'codify-schemas';
2
+ import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
3
3
  import { ZodObject } from 'zod';
4
4
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
5
5
  import { ParsedResourceSettings } from './parsed-resource-settings.js';
@@ -20,6 +20,10 @@ export interface ResourceSettings<T extends StringIndexedObject> {
20
20
  * List of supported operating systems
21
21
  */
22
22
  operatingSystems: Array<OS>;
23
+ /**
24
+ * List of supported linux distros
25
+ */
26
+ linuxDistros?: Array<LinuxDistro>;
23
27
  /**
24
28
  * Schema to validate user configs with. Must be in the format JSON Schema draft07
25
29
  */
@@ -1,4 +1,4 @@
1
- import { OS } from 'codify-schemas';
1
+ import { LinuxDistro, OS } from 'codify-schemas';
2
2
  export declare function isDebug(): boolean;
3
3
  export declare enum Shell {
4
4
  ZSH = "zsh",
@@ -34,5 +34,13 @@ export declare const Utils: {
34
34
  */
35
35
  installViaPkgMgr(packageName: string): Promise<void>;
36
36
  uninstallViaPkgMgr(packageName: string): Promise<boolean>;
37
- linuxDistro(): Promise<"arch" | "centos" | "debian" | "fedora" | "rhel" | "ubuntu" | undefined>;
37
+ getLinuxDistro(): Promise<LinuxDistro | undefined>;
38
+ isUbuntu(): Promise<boolean>;
39
+ isDebian(): Promise<boolean>;
40
+ isArch(): Promise<boolean>;
41
+ isCentOS(): Promise<boolean>;
42
+ isFedora(): Promise<boolean>;
43
+ isRHEL(): Promise<boolean>;
44
+ isDebianBased(): boolean;
45
+ isRPMBased(): boolean;
38
46
  };
@@ -1,7 +1,9 @@
1
+ import { LinuxDistro } from 'codify-schemas';
1
2
  import * as fs from 'node:fs/promises';
2
3
  import os from 'node:os';
3
4
  import path from 'node:path';
4
5
  import { SpawnStatus, getPty } from '../pty/index.js';
6
+ import * as fsSync from 'node:fs';
5
7
  export function isDebug() {
6
8
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
7
9
  }
@@ -219,14 +221,39 @@ Brew can be installed using Codify:
219
221
  }
220
222
  return false;
221
223
  },
222
- async linuxDistro() {
224
+ async getLinuxDistro() {
223
225
  const osRelease = await fs.readFile('/etc/os-release', 'utf8');
224
226
  const lines = osRelease.split('\n');
225
227
  for (const line of lines) {
226
228
  if (line.startsWith('ID=')) {
227
- return line.slice(3).trim();
229
+ const distroId = line.slice(3).trim().replace(/"/g, '');
230
+ return Object.values(LinuxDistro).includes(distroId) ? distroId : undefined;
228
231
  }
229
232
  }
230
233
  return undefined;
234
+ },
235
+ async isUbuntu() {
236
+ return (await this.getLinuxDistro()) === LinuxDistro.UBUNTU;
237
+ },
238
+ async isDebian() {
239
+ return (await this.getLinuxDistro()) === LinuxDistro.DEBIAN;
240
+ },
241
+ async isArch() {
242
+ return (await this.getLinuxDistro()) === LinuxDistro.ARCH;
243
+ },
244
+ async isCentOS() {
245
+ return (await this.getLinuxDistro()) === LinuxDistro.CENTOS;
246
+ },
247
+ async isFedora() {
248
+ return (await this.getLinuxDistro()) === LinuxDistro.FEDORA;
249
+ },
250
+ async isRHEL() {
251
+ return (await this.getLinuxDistro()) === LinuxDistro.RHEL;
252
+ },
253
+ isDebianBased() {
254
+ return fsSync.existsSync('/etc/debian_version');
255
+ },
256
+ isRPMBased() {
257
+ return fsSync.existsSync('/etc/redhat-release');
231
258
  }
232
259
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.182-beta63",
3
+ "version": "1.0.182-beta65",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "ajv": "^8.12.0",
23
23
  "ajv-formats": "^2.1.1",
24
24
  "clean-deep": "^3.4.0",
25
- "codify-schemas": "1.0.86-beta10",
25
+ "codify-schemas": "1.0.86-beta11",
26
26
  "lodash.isequal": "^4.5.0",
27
27
  "nanoid": "^5.0.9",
28
28
  "strip-ansi": "^7.1.0",
@@ -77,6 +77,7 @@ export class Plugin {
77
77
  type: r.typeId,
78
78
  sensitiveParameters,
79
79
  operatingSystems: r.settings.operatingSystems,
80
+ linuxDistros: r.settings.linuxDistros,
80
81
  }
81
82
  })
82
83
  }
@@ -124,6 +125,7 @@ export class Plugin {
124
125
  requiredParameters: requiredPropertyNames,
125
126
  },
126
127
  operatingSystems: resource.settings.operatingSystems,
128
+ linuxDistros: resource.settings.linuxDistros,
127
129
  sensitiveParameters,
128
130
  allowMultiple
129
131
  }
@@ -1,5 +1,5 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
- import { OS, StringIndexedObject } from 'codify-schemas';
2
+ import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
3
3
  import { ZodObject, z } from 'zod';
4
4
 
5
5
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
@@ -52,6 +52,8 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
52
52
  transformation?: InputTransformation;
53
53
 
54
54
  operatingSystems!: Array<OS>;
55
+ linuxDistros?: Array<LinuxDistro>;
56
+
55
57
  isSensitive?: boolean;
56
58
 
57
59
  private settings: ResourceSettings<T>;
@@ -1,5 +1,5 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
- import { OS, StringIndexedObject } from 'codify-schemas';
2
+ import { LinuxDistro, OS, StringIndexedObject } from 'codify-schemas';
3
3
  import isObjectsEqual from 'lodash.isequal'
4
4
  import path from 'node:path';
5
5
  import { ZodObject } from 'zod';
@@ -35,6 +35,11 @@ export interface ResourceSettings<T extends StringIndexedObject> {
35
35
  */
36
36
  operatingSystems: Array<OS>;
37
37
 
38
+ /**
39
+ * List of supported linux distros
40
+ */
41
+ linuxDistros?: Array<LinuxDistro>;
42
+
38
43
  /**
39
44
  * Schema to validate user configs with. Must be in the format JSON Schema draft07
40
45
  */
@@ -1,9 +1,10 @@
1
- import { OS } from 'codify-schemas';
1
+ import { LinuxDistro, OS } from 'codify-schemas';
2
2
  import * as fs from 'node:fs/promises';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
5
 
6
6
  import { SpawnStatus, getPty } from '../pty/index.js';
7
+ import * as fsSync from 'node:fs';
7
8
 
8
9
  export function isDebug(): boolean {
9
10
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
@@ -277,17 +278,49 @@ Brew can be installed using Codify:
277
278
  return false;
278
279
  },
279
280
 
280
-
281
- async linuxDistro(): Promise<'arch' | 'centos' | 'debian' | 'fedora' | 'rhel' | 'ubuntu' | undefined> {
281
+ async getLinuxDistro(): Promise<LinuxDistro | undefined> {
282
282
  const osRelease = await fs.readFile('/etc/os-release', 'utf8');
283
283
  const lines = osRelease.split('\n');
284
284
  for (const line of lines) {
285
285
  if (line.startsWith('ID=')) {
286
- return line.slice(3).trim() as any;
286
+ const distroId = line.slice(3).trim().replace(/"/g, '');
287
+ return Object.values(LinuxDistro).includes(distroId as LinuxDistro) ? distroId as LinuxDistro : undefined;
287
288
  }
288
289
  }
289
290
 
290
291
  return undefined;
292
+ },
293
+
294
+ async isUbuntu(): Promise<boolean> {
295
+ return (await this.getLinuxDistro()) === LinuxDistro.UBUNTU;
296
+ },
297
+
298
+ async isDebian(): Promise<boolean> {
299
+ return (await this.getLinuxDistro()) === LinuxDistro.DEBIAN;
300
+ },
301
+
302
+ async isArch(): Promise<boolean> {
303
+ return (await this.getLinuxDistro()) === LinuxDistro.ARCH;
304
+ },
305
+
306
+ async isCentOS(): Promise<boolean> {
307
+ return (await this.getLinuxDistro()) === LinuxDistro.CENTOS;
308
+ },
309
+
310
+ async isFedora(): Promise<boolean> {
311
+ return (await this.getLinuxDistro()) === LinuxDistro.FEDORA;
312
+ },
313
+
314
+ async isRHEL(): Promise<boolean> {
315
+ return (await this.getLinuxDistro()) === LinuxDistro.RHEL;
316
+ },
317
+
318
+ isDebianBased(): boolean {
319
+ return fsSync.existsSync('/etc/debian_version');
320
+ },
321
+
322
+ isRPMBased(): boolean {
323
+ return fsSync.existsSync('/etc/redhat-release');
291
324
  }
292
325
  };
293
326