@codifycli/plugin-core 1.1.0-beta1 → 1.1.0-beta11
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.
- package/dist/plugin/plugin.d.ts +1 -4
- package/dist/plugin/plugin.js +2 -2
- package/dist/pty/seqeuntial-pty.js +2 -1
- package/dist/resource/resource-settings.d.ts +6 -5
- package/dist/utils/file-utils.d.ts +1 -0
- package/dist/utils/file-utils.js +9 -0
- package/dist/utils/index.js +6 -6
- package/package.json +2 -2
- package/src/plugin/plugin.ts +8 -5
- package/src/pty/seqeuntial-pty.ts +3 -1
- package/src/resource/parsed-resource-settings.ts +2 -1
- package/src/resource/resource-settings.ts +6 -5
- package/src/utils/file-utils.ts +13 -0
- package/src/utils/index.ts +6 -6
package/dist/plugin/plugin.d.ts
CHANGED
|
@@ -11,10 +11,7 @@ export declare class Plugin {
|
|
|
11
11
|
constructor(name: string, resourceControllers: Map<string, ResourceController<ResourceConfig>>);
|
|
12
12
|
static create(name: string, resources: Resource<any>[]): Plugin;
|
|
13
13
|
initialize(data: InitializeRequestData): Promise<InitializeResponseData>;
|
|
14
|
-
getResourceInfo(data: GetResourceInfoRequestData):
|
|
15
|
-
defaultConfig: unknown;
|
|
16
|
-
exampleConfigs: unknown;
|
|
17
|
-
} & GetResourceInfoResponseData;
|
|
14
|
+
getResourceInfo(data: GetResourceInfoRequestData): GetResourceInfoResponseData;
|
|
18
15
|
match(data: MatchRequestData): Promise<MatchResponseData>;
|
|
19
16
|
import(data: ImportRequestData): Promise<ImportResponseData>;
|
|
20
17
|
validate(data: ValidateRequestData): Promise<ValidateResponseData>;
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -121,9 +121,9 @@ export class Plugin {
|
|
|
121
121
|
if (!this.resourceControllers.has(core.type)) {
|
|
122
122
|
throw new Error(`Resource type not found: ${core.type}`);
|
|
123
123
|
}
|
|
124
|
-
const validation = await this.resourceControllers
|
|
124
|
+
const validation = await ptyLocalStorage.run(this.planPty, () => this.resourceControllers
|
|
125
125
|
.get(core.type)
|
|
126
|
-
.validate(core, parameters);
|
|
126
|
+
.validate(core, parameters));
|
|
127
127
|
validationResults.push(validation);
|
|
128
128
|
}
|
|
129
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:
|
|
81
|
+
data: raw,
|
|
81
82
|
});
|
|
82
83
|
});
|
|
83
84
|
});
|
|
@@ -4,13 +4,14 @@ 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 {
|
|
7
|
+
export interface ExampleConfig extends Record<string, unknown> {
|
|
8
|
+
title: string;
|
|
8
9
|
configs: Array<Record<string, unknown>>;
|
|
9
|
-
description
|
|
10
|
+
description?: string;
|
|
10
11
|
}
|
|
11
12
|
export interface ExampleConfigs {
|
|
12
|
-
example1
|
|
13
|
-
example2
|
|
13
|
+
example1?: ExampleConfig;
|
|
14
|
+
example2?: ExampleConfig;
|
|
14
15
|
}
|
|
15
16
|
export interface InputTransformation {
|
|
16
17
|
to: (input: any) => Promise<any> | any;
|
|
@@ -180,7 +181,7 @@ export interface ResourceSettings<T extends StringIndexedObject> {
|
|
|
180
181
|
* A collection of example configs used to give users an idea on how to use this specific resource. These examples
|
|
181
182
|
* don't need to be limited to just the current resource. They can include other resources as well
|
|
182
183
|
*/
|
|
183
|
-
exampleConfigs
|
|
184
|
+
exampleConfigs?: ExampleConfigs;
|
|
184
185
|
}
|
|
185
186
|
/**
|
|
186
187
|
* The type of parameter. This value is mainly used to determine a pre-set equality method for comparing the current
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -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
|
}
|
package/dist/utils/index.js
CHANGED
|
@@ -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 {
|
|
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.1.0-
|
|
3
|
+
"version": "1.1.0-beta11",
|
|
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.
|
|
38
|
+
"@codifycli/schemas": "1.1.0-beta4",
|
|
39
39
|
"@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
|
|
40
40
|
"ajv": "^8.18.0",
|
|
41
41
|
"ajv-formats": "^2.1.1",
|
package/src/plugin/plugin.ts
CHANGED
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
PlanRequestData,
|
|
12
12
|
PlanResponseData,
|
|
13
13
|
ResourceConfig,
|
|
14
|
-
ResourceJson,
|
|
14
|
+
ResourceJson,
|
|
15
|
+
SetVerbosityRequestData,
|
|
15
16
|
ValidateRequestData,
|
|
16
17
|
ValidateResponseData
|
|
17
18
|
} from '@codifycli/schemas';
|
|
@@ -83,7 +84,7 @@ export class Plugin {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
getResourceInfo(data: GetResourceInfoRequestData):
|
|
87
|
+
getResourceInfo(data: GetResourceInfoRequestData): GetResourceInfoResponseData {
|
|
87
88
|
if (!this.resourceControllers.has(data.type)) {
|
|
88
89
|
throw new Error(`Cannot get info for resource ${data.type}, resource doesn't exist`);
|
|
89
90
|
}
|
|
@@ -173,9 +174,11 @@ export class Plugin {
|
|
|
173
174
|
throw new Error(`Resource type not found: ${core.type}`);
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
const validation = await this.
|
|
177
|
-
.
|
|
178
|
-
|
|
177
|
+
const validation = await ptyLocalStorage.run(this.planPty, () =>
|
|
178
|
+
this.resourceControllers
|
|
179
|
+
.get(core.type)!
|
|
180
|
+
.validate(core, parameters)
|
|
181
|
+
);
|
|
179
182
|
|
|
180
183
|
validationResults.push(validation);
|
|
181
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:
|
|
108
|
+
data: raw,
|
|
107
109
|
})
|
|
108
110
|
})
|
|
109
111
|
})
|
|
@@ -5,7 +5,8 @@ import { z, ZodObject } from 'zod';
|
|
|
5
5
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
6
6
|
import {
|
|
7
7
|
ArrayParameterSetting,
|
|
8
|
-
DefaultParameterSetting,
|
|
8
|
+
DefaultParameterSetting,
|
|
9
|
+
ExampleConfigs,
|
|
9
10
|
InputTransformation,
|
|
10
11
|
ParameterSetting,
|
|
11
12
|
resolveElementEqualsFn,
|
|
@@ -15,14 +15,15 @@ import {
|
|
|
15
15
|
import { ParsedResourceSettings } from './parsed-resource-settings.js';
|
|
16
16
|
import { RefreshContext } from './resource.js';
|
|
17
17
|
|
|
18
|
-
export interface ExampleConfig {
|
|
18
|
+
export interface ExampleConfig extends Record<string, unknown> {
|
|
19
|
+
title: string;
|
|
19
20
|
configs: Array<Record<string, unknown>>;
|
|
20
|
-
description
|
|
21
|
+
description?: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export interface ExampleConfigs {
|
|
24
|
-
example1
|
|
25
|
-
example2
|
|
25
|
+
example1?: ExampleConfig;
|
|
26
|
+
example2?: ExampleConfig;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface InputTransformation {
|
|
@@ -216,7 +217,7 @@ export interface ResourceSettings<T extends StringIndexedObject> {
|
|
|
216
217
|
* A collection of example configs used to give users an idea on how to use this specific resource. These examples
|
|
217
218
|
* don't need to be limited to just the current resource. They can include other resources as well
|
|
218
219
|
*/
|
|
219
|
-
exampleConfigs
|
|
220
|
+
exampleConfigs?: ExampleConfigs
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
/**
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -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
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -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 {
|
|
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
|
});
|