@codifycli/plugin-core 1.0.1 → 1.1.0-beta10

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "disabledMcpjsonServers": [
3
+ "supabase"
4
+ ]
5
+ }
@@ -87,7 +87,9 @@ export class Plugin {
87
87
  operatingSystems: resource.settings.operatingSystems,
88
88
  linuxDistros: resource.settings.linuxDistros,
89
89
  sensitiveParameters,
90
- allowMultiple
90
+ allowMultiple,
91
+ defaultConfig: resource.settings.defaultConfig,
92
+ exampleConfigs: resource.settings.exampleConfigs,
91
93
  };
92
94
  }
93
95
  async match(data) {
@@ -119,9 +121,9 @@ export class Plugin {
119
121
  if (!this.resourceControllers.has(core.type)) {
120
122
  throw new Error(`Resource type not found: ${core.type}`);
121
123
  }
122
- const validation = await this.resourceControllers
124
+ const validation = await ptyLocalStorage.run(this.planPty, () => this.resourceControllers
123
125
  .get(core.type)
124
- .validate(core, parameters);
126
+ .validate(core, parameters));
125
127
  validationResults.push(validation);
126
128
  }
127
129
  // Validate that if allow multiple is false, then only 1 of each resource exists
@@ -74,10 +74,11 @@ export class SequentialPty {
74
74
  process.stdout.on('resize', resizeListener);
75
75
  mPty.onExit((result) => {
76
76
  process.stdout.off('resize', resizeListener);
77
+ const raw = stripAnsi(output.join('')).replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim();
77
78
  resolve({
78
79
  status: result.exitCode === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
79
80
  exitCode: result.exitCode,
80
- data: stripAnsi(output.join('\n').trim()),
81
+ data: raw,
81
82
  });
82
83
  });
83
84
  });
@@ -1,7 +1,7 @@
1
1
  import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
2
2
  import { JSONSchemaType } from 'ajv';
3
3
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
4
- import { ArrayParameterSetting, DefaultParameterSetting, InputTransformation, ResourceSettings } from './resource-settings.js';
4
+ import { ArrayParameterSetting, DefaultParameterSetting, ExampleConfigs, InputTransformation, ResourceSettings } from './resource-settings.js';
5
5
  export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
6
6
  type: 'stateful';
7
7
  controller: StatefulParameterController<any, unknown>;
@@ -31,6 +31,8 @@ export declare class ParsedResourceSettings<T extends StringIndexedObject> imple
31
31
  operatingSystems: Array<OS>;
32
32
  linuxDistros?: Array<LinuxDistro>;
33
33
  isSensitive?: boolean;
34
+ defaultConfig: Partial<T>;
35
+ exampleConfigs: ExampleConfigs;
34
36
  private settings;
35
37
  constructor(settings: ResourceSettings<T>);
36
38
  get typeId(): string;
@@ -13,6 +13,8 @@ export class ParsedResourceSettings {
13
13
  operatingSystems;
14
14
  linuxDistros;
15
15
  isSensitive;
16
+ defaultConfig;
17
+ exampleConfigs;
16
18
  settings;
17
19
  constructor(settings) {
18
20
  this.settings = settings;
@@ -4,6 +4,15 @@ import { ZodObject } from 'zod';
4
4
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
5
5
  import { ParsedResourceSettings } from './parsed-resource-settings.js';
6
6
  import { RefreshContext } from './resource.js';
7
+ export interface ExampleConfig extends Record<string, unknown> {
8
+ title: string;
9
+ configs: Array<Record<string, unknown>>;
10
+ description?: string;
11
+ }
12
+ export interface ExampleConfigs {
13
+ example1?: ExampleConfig;
14
+ example2?: ExampleConfig;
15
+ }
7
16
  export interface InputTransformation {
8
17
  to: (input: any) => Promise<any> | any;
9
18
  from: (current: any, original: any) => Promise<any> | any;
@@ -162,6 +171,17 @@ export interface ResourceSettings<T extends StringIndexedObject> {
162
171
  */
163
172
  refreshMapper?: (input: Partial<T>, context: RefreshContext<T>) => Partial<T>;
164
173
  };
174
+ /**
175
+ * Represents the default config that is added to the editor with prefilled properties. For some resources
176
+ *
177
+ * @type {Partial<T>}
178
+ */
179
+ defaultConfig?: Partial<T>;
180
+ /**
181
+ * A collection of example configs used to give users an idea on how to use this specific resource. These examples
182
+ * don't need to be limited to just the current resource. They can include other resources as well
183
+ */
184
+ exampleConfigs?: ExampleConfigs;
165
185
  }
166
186
  /**
167
187
  * The type of parameter. This value is mainly used to determine a pre-set equality method for comparing the current
@@ -20,4 +20,5 @@ export declare class FileUtils {
20
20
  static checkDirExistsOrThrowIfFile(path: string): Promise<boolean>;
21
21
  static createDirIfNotExists(path: string): Promise<void>;
22
22
  private static calculateEndingNewLines;
23
+ static createShellRcIfNotExists(): Promise<void>;
23
24
  }
@@ -19,6 +19,7 @@ export class FileUtils {
19
19
  console.log(`Finished downloading to ${destination}`);
20
20
  }
21
21
  static async addToShellRc(line) {
22
+ await FileUtils.createShellRcIfNotExists();
22
23
  const lineToInsert = addLeadingSpacer(addTrailingSpacer(line));
23
24
  await fs.appendFile(Utils.getPrimaryShellRc(), lineToInsert);
24
25
  function addLeadingSpacer(line) {
@@ -33,6 +34,7 @@ export class FileUtils {
33
34
  }
34
35
  }
35
36
  static async addAllToShellRc(lines) {
37
+ await FileUtils.createShellRcIfNotExists();
36
38
  const formattedLines = '\n' + lines.join('\n') + '\n';
37
39
  const shellRc = Utils.getPrimaryShellRc();
38
40
  console.log(`Adding to ${path.basename(shellRc)}:
@@ -46,6 +48,7 @@ ${lines.join('\n')}`);
46
48
  * @param prepend - Whether to prepend the path to the existing PATH variable.
47
49
  */
48
50
  static async addPathToShellRc(value, prepend) {
51
+ await FileUtils.createShellRcIfNotExists();
49
52
  if (await Utils.isDirectoryOnPath(value)) {
50
53
  return;
51
54
  }
@@ -183,4 +186,10 @@ ${lines.join('\n')}`);
183
186
  }
184
187
  }
185
188
  }
189
+ static async createShellRcIfNotExists() {
190
+ const shellRc = Utils.getPrimaryShellRc();
191
+ if (!await FileUtils.fileExists(shellRc)) {
192
+ await fs.writeFile(shellRc, '', 'utf8');
193
+ }
194
+ }
186
195
  }
@@ -3,7 +3,7 @@ import * as fsSync from 'node:fs';
3
3
  import * as fs from 'node:fs/promises';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
- import { SpawnStatus, getPty } from '../pty/index.js';
6
+ import { getPty, SpawnStatus } from '../pty/index.js';
7
7
  export function isDebug() {
8
8
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
9
9
  }
@@ -56,7 +56,7 @@ export const Utils = {
56
56
  return query.status === SpawnStatus.SUCCESS;
57
57
  },
58
58
  getShell() {
59
- const shell = process.env.SHELL || '';
59
+ const shell = process.env.SHELL || os.userInfo().shell || '';
60
60
  if (shell.endsWith('bash')) {
61
61
  return Shell.BASH;
62
62
  }
@@ -81,7 +81,7 @@ export const Utils = {
81
81
  return this.getShellRcFiles()[0];
82
82
  },
83
83
  getShellRcFiles() {
84
- const shell = process.env.SHELL || '';
84
+ const shell = process.env.SHELL || os.userInfo().shell || '';
85
85
  const homeDir = os.homedir();
86
86
  if (shell.endsWith('bash')) {
87
87
  // Linux typically uses .bashrc, macOS uses .bash_profile
@@ -167,9 +167,9 @@ Brew can be installed using Codify:
167
167
  const isAptInstalled = await $.spawnSafe('which apt');
168
168
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
169
169
  await $.spawn('apt-get update', { requiresRoot: true });
170
- const { status, data } = await $.spawnSafe(`apt-get -y install ${packageName}`, {
170
+ const { status, data } = await $.spawnSafe(`apt-get -y -qq install -o Dpkg::Use-Pty=0 -o Dpkg::Progress-Fancy=0 ${packageName}`, {
171
171
  requiresRoot: true,
172
- env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a' }
172
+ env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a', }
173
173
  });
174
174
  if (status === SpawnStatus.ERROR && data.includes('E: dpkg was interrupted, you must manually run \'sudo dpkg --configure -a\' to correct the problem.')) {
175
175
  await $.spawn('dpkg --configure -a', { requiresRoot: true });
@@ -213,7 +213,7 @@ Brew can be installed using Codify:
213
213
  if (Utils.isLinux()) {
214
214
  const isAptInstalled = await $.spawnSafe('which apt');
215
215
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
216
- const { status } = await $.spawnSafe(`apt-get autoremove -y --purge ${packageName}`, {
216
+ const { status } = await $.spawnSafe(`apt-get -qq autoremove -y -o Dpkg::Use-Pty=0 -o Dpkg::Progress-Fancy=0 --purge ${packageName}`, {
217
217
  requiresRoot: true,
218
218
  env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a' }
219
219
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codifycli/plugin-core",
3
- "version": "1.0.1",
3
+ "version": "1.1.0-beta10",
4
4
  "description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "license": "ISC",
37
37
  "dependencies": {
38
- "@codifycli/schemas": "1.0.0",
38
+ "@codifycli/schemas": "1.1.0-beta3",
39
39
  "@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
40
40
  "ajv": "^8.18.0",
41
41
  "ajv-formats": "^2.1.1",
@@ -11,7 +11,8 @@ import {
11
11
  PlanRequestData,
12
12
  PlanResponseData,
13
13
  ResourceConfig,
14
- ResourceJson, SetVerbosityRequestData,
14
+ ResourceJson,
15
+ SetVerbosityRequestData,
15
16
  ValidateRequestData,
16
17
  ValidateResponseData
17
18
  } from '@codifycli/schemas';
@@ -127,7 +128,9 @@ export class Plugin {
127
128
  operatingSystems: resource.settings.operatingSystems,
128
129
  linuxDistros: resource.settings.linuxDistros,
129
130
  sensitiveParameters,
130
- allowMultiple
131
+ allowMultiple,
132
+ defaultConfig: resource.settings.defaultConfig,
133
+ exampleConfigs: resource.settings.exampleConfigs,
131
134
  }
132
135
  }
133
136
 
@@ -171,9 +174,11 @@ export class Plugin {
171
174
  throw new Error(`Resource type not found: ${core.type}`);
172
175
  }
173
176
 
174
- const validation = await this.resourceControllers
175
- .get(core.type)!
176
- .validate(core, parameters);
177
+ const validation = await ptyLocalStorage.run(this.planPty, () =>
178
+ this.resourceControllers
179
+ .get(core.type)!
180
+ .validate(core, parameters)
181
+ );
177
182
 
178
183
  validationResults.push(validation);
179
184
  }
@@ -100,10 +100,12 @@ export class SequentialPty implements IPty {
100
100
  mPty.onExit((result) => {
101
101
  process.stdout.off('resize', resizeListener);
102
102
 
103
+ const raw = stripAnsi(output.join('')).replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim();
104
+
103
105
  resolve({
104
106
  status: result.exitCode === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
105
107
  exitCode: result.exitCode,
106
- data: stripAnsi(output.join('\n').trim()),
108
+ data: raw,
107
109
  })
108
110
  })
109
111
  })
@@ -6,6 +6,7 @@ import { StatefulParameterController } from '../stateful-parameter/stateful-para
6
6
  import {
7
7
  ArrayParameterSetting,
8
8
  DefaultParameterSetting,
9
+ ExampleConfigs,
9
10
  InputTransformation,
10
11
  ParameterSetting,
11
12
  resolveElementEqualsFn,
@@ -56,6 +57,9 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
56
57
 
57
58
  isSensitive?: boolean;
58
59
 
60
+ defaultConfig!: Partial<T>;
61
+ exampleConfigs!: ExampleConfigs;
62
+
59
63
  private settings: ResourceSettings<T>;
60
64
 
61
65
  constructor(settings: ResourceSettings<T>) {
@@ -15,6 +15,17 @@ import {
15
15
  import { ParsedResourceSettings } from './parsed-resource-settings.js';
16
16
  import { RefreshContext } from './resource.js';
17
17
 
18
+ export interface ExampleConfig extends Record<string, unknown> {
19
+ title: string;
20
+ configs: Array<Record<string, unknown>>;
21
+ description?: string;
22
+ }
23
+
24
+ export interface ExampleConfigs {
25
+ example1?: ExampleConfig;
26
+ example2?: ExampleConfig;
27
+ }
28
+
18
29
  export interface InputTransformation {
19
30
  to: (input: any) => Promise<any> | any;
20
31
  from: (current: any, original: any) => Promise<any> | any;
@@ -194,6 +205,19 @@ export interface ResourceSettings<T extends StringIndexedObject> {
194
205
  */
195
206
  refreshMapper?: (input: Partial<T>, context: RefreshContext<T>) => Partial<T>;
196
207
  }
208
+
209
+ /**
210
+ * Represents the default config that is added to the editor with prefilled properties. For some resources
211
+ *
212
+ * @type {Partial<T>}
213
+ */
214
+ defaultConfig?: Partial<T>
215
+
216
+ /**
217
+ * A collection of example configs used to give users an idea on how to use this specific resource. These examples
218
+ * don't need to be limited to just the current resource. They can include other resources as well
219
+ */
220
+ exampleConfigs?: ExampleConfigs
197
221
  }
198
222
 
199
223
  /**
@@ -26,6 +26,8 @@ export class FileUtils {
26
26
  }
27
27
 
28
28
  static async addToShellRc(line: string): Promise<void> {
29
+ await FileUtils.createShellRcIfNotExists();
30
+
29
31
  const lineToInsert = addLeadingSpacer(
30
32
  addTrailingSpacer(line)
31
33
  );
@@ -46,6 +48,8 @@ export class FileUtils {
46
48
  }
47
49
 
48
50
  static async addAllToShellRc(lines: string[]): Promise<void> {
51
+ await FileUtils.createShellRcIfNotExists();
52
+
49
53
  const formattedLines = '\n' + lines.join('\n') + '\n';
50
54
  const shellRc = Utils.getPrimaryShellRc();
51
55
 
@@ -62,6 +66,8 @@ ${lines.join('\n')}`)
62
66
  * @param prepend - Whether to prepend the path to the existing PATH variable.
63
67
  */
64
68
  static async addPathToShellRc(value: string, prepend: boolean): Promise<void> {
69
+ await FileUtils.createShellRcIfNotExists();
70
+
65
71
  if (await Utils.isDirectoryOnPath(value)) {
66
72
  return;
67
73
  }
@@ -228,4 +234,11 @@ ${lines.join('\n')}`)
228
234
  }
229
235
  }
230
236
  }
237
+
238
+ static async createShellRcIfNotExists(): Promise<void> {
239
+ const shellRc = Utils.getPrimaryShellRc();
240
+ if (!await FileUtils.fileExists(shellRc)) {
241
+ await fs.writeFile(shellRc, '', 'utf8');
242
+ }
243
+ }
231
244
  }
@@ -4,7 +4,7 @@ import * as fs from 'node:fs/promises';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
 
7
- import { SpawnStatus, getPty } from '../pty/index.js';
7
+ import { getPty, SpawnStatus } from '../pty/index.js';
8
8
 
9
9
  export function isDebug(): boolean {
10
10
  return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
@@ -73,7 +73,7 @@ export const Utils = {
73
73
  },
74
74
 
75
75
  getShell(): Shell | undefined {
76
- const shell = process.env.SHELL || '';
76
+ const shell = process.env.SHELL || os.userInfo().shell || '';
77
77
 
78
78
  if (shell.endsWith('bash')) {
79
79
  return Shell.BASH
@@ -108,7 +108,7 @@ export const Utils = {
108
108
  },
109
109
 
110
110
  getShellRcFiles(): string[] {
111
- const shell = process.env.SHELL || '';
111
+ const shell = process.env.SHELL || os.userInfo().shell || '';
112
112
  const homeDir = os.homedir();
113
113
 
114
114
  if (shell.endsWith('bash')) {
@@ -209,9 +209,9 @@ Brew can be installed using Codify:
209
209
  const isAptInstalled = await $.spawnSafe('which apt');
210
210
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
211
211
  await $.spawn('apt-get update', { requiresRoot: true });
212
- const { status, data } = await $.spawnSafe(`apt-get -y install ${packageName}`, {
212
+ const { status, data } = await $.spawnSafe(`apt-get -y -qq install -o Dpkg::Use-Pty=0 -o Dpkg::Progress-Fancy=0 ${packageName}`, {
213
213
  requiresRoot: true,
214
- env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a' }
214
+ env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a', }
215
215
  });
216
216
 
217
217
  if (status === SpawnStatus.ERROR && data.includes('E: dpkg was interrupted, you must manually run \'sudo dpkg --configure -a\' to correct the problem.')) {
@@ -265,7 +265,7 @@ Brew can be installed using Codify:
265
265
  if (Utils.isLinux()) {
266
266
  const isAptInstalled = await $.spawnSafe('which apt');
267
267
  if (isAptInstalled.status === SpawnStatus.SUCCESS) {
268
- const { status } = await $.spawnSafe(`apt-get autoremove -y --purge ${packageName}`, {
268
+ const { status } = await $.spawnSafe(`apt-get -qq autoremove -y -o Dpkg::Use-Pty=0 -o Dpkg::Progress-Fancy=0 --purge ${packageName}`, {
269
269
  requiresRoot: true,
270
270
  env: { DEBIAN_FRONTEND: 'noninteractive', NEEDRESTART_MODE: 'a' }
271
271
  });