@codifycli/plugin-core 1.2.5-beta.1 → 1.2.5-beta.3
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/bin/build.js +0 -0
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
- package/src/utils/index.ts +2 -2
- package/.claude/settings.local.json +0 -13
- package/dist/bin/build.d.ts +0 -1
- package/dist/bin/build.js +0 -80
- package/dist/bin/deploy-plugin.d.ts +0 -2
- package/dist/bin/deploy-plugin.js +0 -8
- package/dist/entities/change-set.d.ts +0 -24
- package/dist/entities/change-set.js +0 -152
- package/dist/entities/errors.d.ts +0 -4
- package/dist/entities/errors.js +0 -7
- package/dist/entities/plan-types.d.ts +0 -25
- package/dist/entities/plan-types.js +0 -1
- package/dist/entities/plan.d.ts +0 -15
- package/dist/entities/plan.js +0 -127
- package/dist/entities/plugin.d.ts +0 -16
- package/dist/entities/plugin.js +0 -80
- package/dist/entities/resource-options.d.ts +0 -31
- package/dist/entities/resource-options.js +0 -76
- package/dist/entities/resource-types.d.ts +0 -11
- package/dist/entities/resource-types.js +0 -1
- package/dist/entities/resource.d.ts +0 -42
- package/dist/entities/resource.js +0 -303
- package/dist/entities/stateful-parameter.d.ts +0 -29
- package/dist/entities/stateful-parameter.js +0 -46
- package/dist/entities/transform-parameter.d.ts +0 -4
- package/dist/entities/transform-parameter.js +0 -2
- package/dist/pty/vitest.config.d.ts +0 -2
- package/dist/pty/vitest.config.js +0 -11
- package/dist/resource/stateful-parameter.d.ts +0 -165
- package/dist/resource/stateful-parameter.js +0 -94
- package/dist/scripts/deploy.d.ts +0 -1
- package/dist/scripts/deploy.js +0 -2
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -5
- package/dist/utils/codify-spawn.d.ts +0 -29
- package/dist/utils/codify-spawn.js +0 -136
- package/dist/utils/internal-utils.d.ts +0 -12
- package/dist/utils/internal-utils.js +0 -74
- package/dist/utils/load-resources.d.ts +0 -1
- package/dist/utils/load-resources.js +0 -46
- package/dist/utils/package-json-utils.d.ts +0 -12
- package/dist/utils/package-json-utils.js +0 -34
- package/dist/utils/spawn-2.d.ts +0 -5
- package/dist/utils/spawn-2.js +0 -7
- package/dist/utils/spawn.d.ts +0 -29
- package/dist/utils/spawn.js +0 -124
- package/dist/utils/utils.d.ts +0 -18
- package/dist/utils/utils.js +0 -86
package/dist/utils/spawn.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { Ajv } from 'ajv';
|
|
2
|
-
import { MessageCmd, SudoRequestResponseDataSchema } from 'codify-schemas';
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
|
-
import { SudoError } from '../errors.js';
|
|
5
|
-
const ajv = new Ajv({
|
|
6
|
-
strict: true,
|
|
7
|
-
});
|
|
8
|
-
const validateSudoRequestResponse = ajv.compile(SudoRequestResponseDataSchema);
|
|
9
|
-
export var SpawnStatus;
|
|
10
|
-
(function (SpawnStatus) {
|
|
11
|
-
SpawnStatus["SUCCESS"] = "success";
|
|
12
|
-
SpawnStatus["ERROR"] = "error";
|
|
13
|
-
})(SpawnStatus || (SpawnStatus = {}));
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param cmd Command to run. Ex: `rm -rf`
|
|
17
|
-
* @param opts Standard options for node spawn. Additional argument:
|
|
18
|
-
* throws determines if a shell will throw a JS error. Defaults to true
|
|
19
|
-
*
|
|
20
|
-
* @see promiseSpawn
|
|
21
|
-
* @see spawn
|
|
22
|
-
*
|
|
23
|
-
* @returns SpawnResult { status: SUCCESS | ERROR; data: string }
|
|
24
|
-
*/
|
|
25
|
-
export async function $(cmd, opts) {
|
|
26
|
-
const throws = opts?.throws ?? true;
|
|
27
|
-
console.log(`Running command: ${cmd}`);
|
|
28
|
-
try {
|
|
29
|
-
// TODO: Need to benchmark the effects of using sh vs zsh for shell.
|
|
30
|
-
// Seems like zsh shells run slower
|
|
31
|
-
let result;
|
|
32
|
-
if (!opts?.requiresRoot) {
|
|
33
|
-
result = await internalSpawn(cmd, opts ?? {});
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
result = await externalSpawnWithSudo(cmd, opts);
|
|
37
|
-
}
|
|
38
|
-
if (result.status !== SpawnStatus.SUCCESS) {
|
|
39
|
-
throw new Error(result.data);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
if (isDebug()) {
|
|
45
|
-
console.error(`CodifySpawn error for command ${cmd}`, error);
|
|
46
|
-
}
|
|
47
|
-
if (error.message?.startsWith('sudo:')) {
|
|
48
|
-
throw new SudoError(cmd);
|
|
49
|
-
}
|
|
50
|
-
if (throws) {
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
if (error instanceof Error) {
|
|
54
|
-
return {
|
|
55
|
-
status: SpawnStatus.ERROR,
|
|
56
|
-
data: error.message,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
status: SpawnStatus.ERROR,
|
|
61
|
-
data: error + '',
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function internalSpawn(cmd, opts) {
|
|
66
|
-
return new Promise((resolve, reject) => {
|
|
67
|
-
const output = [];
|
|
68
|
-
// Source start up shells to emulate a users environment vs. a non-interactive non-login shell script
|
|
69
|
-
// Ignore all stdin
|
|
70
|
-
const _process = spawn(`source ~/.zshrc; ${cmd}`, [], {
|
|
71
|
-
...opts,
|
|
72
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
73
|
-
shell: 'zsh',
|
|
74
|
-
});
|
|
75
|
-
const { stdout, stderr, stdin } = _process;
|
|
76
|
-
stdout.setEncoding('utf8');
|
|
77
|
-
stderr.setEncoding('utf8');
|
|
78
|
-
stdout.on('data', (data) => {
|
|
79
|
-
output.push(data.toString());
|
|
80
|
-
});
|
|
81
|
-
stderr.on('data', (data) => {
|
|
82
|
-
output.push(data.toString());
|
|
83
|
-
});
|
|
84
|
-
_process.on('error', (data) => {
|
|
85
|
-
});
|
|
86
|
-
// please node that this is not a full replacement for 'inherit'
|
|
87
|
-
// the child process can and will detect if stdout is a pty and change output based on it
|
|
88
|
-
// the terminal context is lost & ansi information (coloring) etc will be lost
|
|
89
|
-
if (stdout && stderr) {
|
|
90
|
-
stdout.pipe(process.stdout);
|
|
91
|
-
stderr.pipe(process.stderr);
|
|
92
|
-
}
|
|
93
|
-
_process.on('close', (code) => {
|
|
94
|
-
resolve({
|
|
95
|
-
status: code === 0 ? SpawnStatus.SUCCESS : SpawnStatus.ERROR,
|
|
96
|
-
data: output.join('\n'),
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
async function externalSpawnWithSudo(cmd, opts) {
|
|
102
|
-
return await new Promise((resolve) => {
|
|
103
|
-
const listener = (data) => {
|
|
104
|
-
if (data.cmd === MessageCmd.SUDO_REQUEST + '_Response') {
|
|
105
|
-
process.removeListener('message', listener);
|
|
106
|
-
if (!validateSudoRequestResponse(data.data)) {
|
|
107
|
-
throw new Error(`Invalid response for sudo request: ${JSON.stringify(validateSudoRequestResponse.errors, null, 2)}`);
|
|
108
|
-
}
|
|
109
|
-
resolve(data.data);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
process.on('message', listener);
|
|
113
|
-
process.send({
|
|
114
|
-
cmd: MessageCmd.SUDO_REQUEST,
|
|
115
|
-
data: {
|
|
116
|
-
command: cmd,
|
|
117
|
-
options: opts ?? {},
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
export function isDebug() {
|
|
123
|
-
return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
|
|
124
|
-
}
|
package/dist/utils/utils.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
|
|
2
|
-
export declare const VerbosityLevel: {
|
|
3
|
-
level: number;
|
|
4
|
-
get(): number;
|
|
5
|
-
set(level: number): void;
|
|
6
|
-
};
|
|
7
|
-
export declare function isDebug(): boolean;
|
|
8
|
-
export declare function splitUserConfig<T extends StringIndexedObject>(config: ResourceConfig & T): {
|
|
9
|
-
parameters: T;
|
|
10
|
-
coreParameters: ResourceConfig;
|
|
11
|
-
};
|
|
12
|
-
export declare function setsEqual(set1: Set<unknown>, set2: Set<unknown>): boolean;
|
|
13
|
-
export declare function untildify(pathWithTilde: string): string;
|
|
14
|
-
export declare function tildify(pathWithTilde: string): string;
|
|
15
|
-
export declare function resolvePathWithVariables(pathWithVariables: string): string;
|
|
16
|
-
export declare function addVariablesToPath(pathWithoutVariables: string): string;
|
|
17
|
-
export declare function unhome(pathWithHome: string): string;
|
|
18
|
-
export declare function areArraysEqual(isElementEqual: ((desired: unknown, current: unknown) => boolean) | undefined, desired: unknown, current: unknown): boolean;
|
package/dist/utils/utils.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
export const VerbosityLevel = new class {
|
|
4
|
-
level = 0;
|
|
5
|
-
get() {
|
|
6
|
-
return this.level;
|
|
7
|
-
}
|
|
8
|
-
set(level) {
|
|
9
|
-
this.level = level;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
export function isDebug() {
|
|
13
|
-
return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
|
|
14
|
-
}
|
|
15
|
-
export function splitUserConfig(config) {
|
|
16
|
-
const coreParameters = {
|
|
17
|
-
type: config.type,
|
|
18
|
-
...(config.name ? { name: config.name } : {}),
|
|
19
|
-
...(config.dependsOn ? { dependsOn: config.dependsOn } : {}),
|
|
20
|
-
};
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
-
const { type, name, dependsOn, ...parameters } = config;
|
|
23
|
-
return {
|
|
24
|
-
parameters: parameters,
|
|
25
|
-
coreParameters,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export function setsEqual(set1, set2) {
|
|
29
|
-
return set1.size === set2.size && [...set1].every((v) => set2.has(v));
|
|
30
|
-
}
|
|
31
|
-
const homeDirectory = os.homedir();
|
|
32
|
-
export function untildify(pathWithTilde) {
|
|
33
|
-
return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
|
|
34
|
-
}
|
|
35
|
-
export function tildify(pathWithTilde) {
|
|
36
|
-
return homeDirectory ? pathWithTilde.replace(homeDirectory, '~') : pathWithTilde;
|
|
37
|
-
}
|
|
38
|
-
export function resolvePathWithVariables(pathWithVariables) {
|
|
39
|
-
// @ts-expect-error Ignore this for now
|
|
40
|
-
return pathWithVariables.replace(/\$([A-Z_]+[A-Z0-9_]*)|\${([A-Z0-9_]*)}/ig, (_, a, b) => process.env[a || b]);
|
|
41
|
-
}
|
|
42
|
-
export function addVariablesToPath(pathWithoutVariables) {
|
|
43
|
-
let result = pathWithoutVariables;
|
|
44
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
45
|
-
if (!value || !path.isAbsolute(value) || value === '/' || key === 'HOME' || key === 'PATH' || key === 'SHELL' || key === 'PWD') {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
result = result.replaceAll(value, `$${key}`);
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
export function unhome(pathWithHome) {
|
|
53
|
-
return pathWithHome.includes('$HOME') ? pathWithHome.replaceAll('$HOME', os.homedir()) : pathWithHome;
|
|
54
|
-
}
|
|
55
|
-
export function areArraysEqual(isElementEqual, desired, current) {
|
|
56
|
-
if (!desired || !current) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
if (!Array.isArray(desired) || !Array.isArray(current)) {
|
|
60
|
-
throw new Error(`A non-array value:
|
|
61
|
-
|
|
62
|
-
Desired: ${JSON.stringify(desired, null, 2)}
|
|
63
|
-
|
|
64
|
-
Current: ${JSON.stringify(desired, null, 2)}
|
|
65
|
-
|
|
66
|
-
Was provided even though type array was specified.
|
|
67
|
-
`);
|
|
68
|
-
}
|
|
69
|
-
if (desired.length !== current.length) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
const desiredCopy = [...desired];
|
|
73
|
-
const currentCopy = [...current];
|
|
74
|
-
// Algorithm for to check equality between two un-ordered; un-hashable arrays using
|
|
75
|
-
// an isElementEqual method. Time: O(n^2)
|
|
76
|
-
for (let counter = desiredCopy.length - 1; counter >= 0; counter--) {
|
|
77
|
-
const idx = currentCopy.findIndex((e2) => (isElementEqual
|
|
78
|
-
?? ((a, b) => a === b))(desiredCopy[counter], e2));
|
|
79
|
-
if (idx === -1) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
desiredCopy.splice(counter, 1);
|
|
83
|
-
currentCopy.splice(idx, 1);
|
|
84
|
-
}
|
|
85
|
-
return currentCopy.length === 0;
|
|
86
|
-
}
|