codify-plugin-lib 1.0.181 → 1.0.182-beta1
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/plugin.js +5 -2
- package/dist/pty/background-pty.js +12 -4
- package/dist/pty/index.d.ts +17 -1
- package/dist/pty/seqeuntial-pty.d.ts +16 -0
- package/dist/pty/seqeuntial-pty.js +84 -0
- package/dist/resource/parsed-resource-settings.d.ts +3 -1
- package/dist/resource/parsed-resource-settings.js +4 -6
- package/dist/resource/resource-settings.d.ts +5 -1
- package/dist/resource/resource-settings.js +1 -1
- package/dist/utils/index.d.ts +25 -0
- package/dist/utils/index.js +108 -0
- package/dist/utils/internal-utils.d.ts +18 -0
- package/dist/utils/internal-utils.js +86 -0
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/plan/plan.test.ts +6 -1
- package/src/plugin/plugin.test.ts +11 -2
- package/src/plugin/plugin.ts +5 -2
- package/src/pty/background-pty.ts +14 -4
- package/src/pty/index.test.ts +7 -4
- package/src/pty/index.ts +17 -1
- package/src/pty/seqeuntial-pty.ts +105 -0
- package/src/pty/sequential-pty.test.ts +61 -0
- package/src/resource/parsed-resource-settings.ts +8 -7
- package/src/resource/resource-controller-stateful-mode.test.ts +2 -1
- package/src/resource/resource-controller.test.ts +22 -4
- package/src/resource/resource-settings.test.ts +29 -2
- package/src/resource/resource-settings.ts +13 -2
- package/src/utils/index.ts +140 -0
- package/src/utils/{utils.test.ts → internal-utils.test.ts} +1 -1
- package/src/utils/test-utils.test.ts +5 -2
- /package/src/utils/{utils.ts → internal-utils.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { spy } from 'sinon';
|
|
4
|
-
import { ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
4
|
+
import { OS, ParameterOperation, ResourceOperation } from 'codify-schemas';
|
|
5
5
|
import {
|
|
6
6
|
TestArrayStatefulParameter,
|
|
7
7
|
TestConfig,
|
|
@@ -26,6 +26,7 @@ describe('Resource parameter tests', () => {
|
|
|
26
26
|
getSettings(): ResourceSettings<TestConfig> {
|
|
27
27
|
return {
|
|
28
28
|
id: 'type',
|
|
29
|
+
operatingSystems: [OS.Darwin],
|
|
29
30
|
parameterSettings: {
|
|
30
31
|
propA: { type: 'stateful', definition: statefulParameter }
|
|
31
32
|
},
|
|
@@ -71,6 +72,7 @@ describe('Resource parameter tests', () => {
|
|
|
71
72
|
getSettings(): ResourceSettings<TestConfig> {
|
|
72
73
|
return {
|
|
73
74
|
id: 'type',
|
|
75
|
+
operatingSystems: [OS.Darwin],
|
|
74
76
|
parameterSettings: {
|
|
75
77
|
propA: { type: 'stateful', definition: statefulParameterSpy }
|
|
76
78
|
},
|
|
@@ -105,6 +107,7 @@ describe('Resource parameter tests', () => {
|
|
|
105
107
|
getSettings(): ResourceSettings<TestConfig> {
|
|
106
108
|
return {
|
|
107
109
|
id: 'type',
|
|
110
|
+
operatingSystems: [OS.Darwin],
|
|
108
111
|
parameterSettings: {
|
|
109
112
|
propA: { type: 'stateful', definition: statefulParameterSpy },
|
|
110
113
|
propB: { canModify: true },
|
|
@@ -137,7 +140,8 @@ describe('Resource parameter tests', () => {
|
|
|
137
140
|
const statefulParameter = spy(new class extends TestStatefulParameter {
|
|
138
141
|
getSettings(): ParameterSetting {
|
|
139
142
|
return {
|
|
140
|
-
default: 'abc'
|
|
143
|
+
default: 'abc',
|
|
144
|
+
operatingSystems: [OS.Darwin],
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -150,6 +154,7 @@ describe('Resource parameter tests', () => {
|
|
|
150
154
|
getSettings(): ResourceSettings<TestConfig> {
|
|
151
155
|
return {
|
|
152
156
|
id: 'type',
|
|
157
|
+
operatingSystems: [OS.Darwin],
|
|
153
158
|
parameterSettings: {
|
|
154
159
|
propA: { type: 'stateful', definition: statefulParameter }
|
|
155
160
|
},
|
|
@@ -191,6 +196,7 @@ describe('Resource parameter tests', () => {
|
|
|
191
196
|
getSettings(): ResourceSettings<TestConfig> {
|
|
192
197
|
return {
|
|
193
198
|
id: 'type',
|
|
199
|
+
operatingSystems: [OS.Darwin],
|
|
194
200
|
parameterSettings: {
|
|
195
201
|
propA: { type: 'stateful', definition: statefulParameterSpy },
|
|
196
202
|
},
|
|
@@ -225,6 +231,7 @@ describe('Resource parameter tests', () => {
|
|
|
225
231
|
getSettings(): ResourceSettings<TestConfig> {
|
|
226
232
|
return {
|
|
227
233
|
id: 'type',
|
|
234
|
+
operatingSystems: [OS.Darwin],
|
|
228
235
|
parameterSettings: {
|
|
229
236
|
propA: { type: 'stateful', definition: statefulParameterSpy }
|
|
230
237
|
},
|
|
@@ -251,6 +258,7 @@ describe('Resource parameter tests', () => {
|
|
|
251
258
|
getSettings(): ResourceSettings<TestConfig> {
|
|
252
259
|
return {
|
|
253
260
|
id: 'type',
|
|
261
|
+
operatingSystems: [OS.Darwin],
|
|
254
262
|
parameterSettings: {
|
|
255
263
|
hosts: {
|
|
256
264
|
type: 'array',
|
|
@@ -360,6 +368,7 @@ describe('Resource parameter tests', () => {
|
|
|
360
368
|
getSettings(): ResourceSettings<TestConfig> {
|
|
361
369
|
return {
|
|
362
370
|
id: 'type',
|
|
371
|
+
operatingSystems: [OS.Darwin],
|
|
363
372
|
parameterSettings: {
|
|
364
373
|
propA: { type: 'stateful', definition: statefulParameterSpy }
|
|
365
374
|
},
|
|
@@ -416,6 +425,7 @@ describe('Resource parameter tests', () => {
|
|
|
416
425
|
getSettings(): ResourceSettings<TestConfig> {
|
|
417
426
|
return {
|
|
418
427
|
id: 'resourceType',
|
|
428
|
+
operatingSystems: [OS.Darwin],
|
|
419
429
|
parameterSettings: {
|
|
420
430
|
propA: { type: 'stateful', definition: statefulParameterA, order: 3 },
|
|
421
431
|
propB: { type: 'stateful', definition: statefulParameterB, order: 1 },
|
|
@@ -494,6 +504,7 @@ describe('Resource parameter tests', () => {
|
|
|
494
504
|
getSettings(): ResourceSettings<TestConfig> {
|
|
495
505
|
return {
|
|
496
506
|
id: 'resourceType',
|
|
507
|
+
operatingSystems: [OS.Darwin],
|
|
497
508
|
parameterSettings: {
|
|
498
509
|
propA: { type: 'stateful', definition: statefulParameterA, order: 3 },
|
|
499
510
|
propB: { type: 'stateful', definition: statefulParameterB, order: 1 },
|
|
@@ -569,6 +580,7 @@ describe('Resource parameter tests', () => {
|
|
|
569
580
|
getSettings(): ResourceSettings<TestConfig> {
|
|
570
581
|
return {
|
|
571
582
|
id: 'resourceType',
|
|
583
|
+
operatingSystems: [OS.Darwin],
|
|
572
584
|
transformation: {
|
|
573
585
|
to: (desired) => ({
|
|
574
586
|
propA: 'propA',
|
|
@@ -610,6 +622,7 @@ describe('Resource parameter tests', () => {
|
|
|
610
622
|
getSettings(): ResourceSettings<TestConfig> {
|
|
611
623
|
return {
|
|
612
624
|
id: 'resourceType',
|
|
625
|
+
operatingSystems: [OS.Darwin],
|
|
613
626
|
transformation: {
|
|
614
627
|
to: (desired) => ({
|
|
615
628
|
propA: 'propA',
|
|
@@ -649,6 +662,7 @@ describe('Resource parameter tests', () => {
|
|
|
649
662
|
getSettings(): ResourceSettings<TestConfig> {
|
|
650
663
|
return {
|
|
651
664
|
id: 'resourceType',
|
|
665
|
+
operatingSystems: [OS.Darwin],
|
|
652
666
|
importAndDestroy: {
|
|
653
667
|
requiredParameters: [
|
|
654
668
|
'propA',
|
|
@@ -668,6 +682,7 @@ describe('Resource parameter tests', () => {
|
|
|
668
682
|
getSettings(): ResourceSettings<TestConfig> {
|
|
669
683
|
return {
|
|
670
684
|
id: 'resourceType',
|
|
685
|
+
operatingSystems: [OS.Darwin],
|
|
671
686
|
parameterSettings: {
|
|
672
687
|
propA: { type: 'directory' }
|
|
673
688
|
}
|
|
@@ -695,6 +710,7 @@ describe('Resource parameter tests', () => {
|
|
|
695
710
|
getSettings(): ResourceSettings<TestConfig> {
|
|
696
711
|
return {
|
|
697
712
|
id: 'resourceType',
|
|
713
|
+
operatingSystems: [OS.Darwin],
|
|
698
714
|
parameterSettings: {
|
|
699
715
|
propA: { type: 'string', setting: true },
|
|
700
716
|
propB: { type: 'number' }
|
|
@@ -737,6 +753,7 @@ describe('Resource parameter tests', () => {
|
|
|
737
753
|
getSettings(): ResourceSettings<TestConfig> {
|
|
738
754
|
return {
|
|
739
755
|
id: 'resourceType',
|
|
756
|
+
operatingSystems: [OS.Darwin],
|
|
740
757
|
importAndDestroy: {
|
|
741
758
|
requiredParameters: ['propA'],
|
|
742
759
|
refreshKeys: ['propB', 'propA'],
|
|
@@ -754,6 +771,7 @@ describe('Resource parameter tests', () => {
|
|
|
754
771
|
getSettings(): ResourceSettings<TestConfig> {
|
|
755
772
|
return {
|
|
756
773
|
id: 'resourceType',
|
|
774
|
+
operatingSystems: [OS.Darwin],
|
|
757
775
|
parameterSettings: {
|
|
758
776
|
propA: { type: 'string', isEqual: 'version' }
|
|
759
777
|
}
|
|
@@ -780,6 +798,7 @@ describe('Resource parameter tests', () => {
|
|
|
780
798
|
getSettings(): ResourceSettings<TestConfig> {
|
|
781
799
|
return {
|
|
782
800
|
id: 'resourceType',
|
|
801
|
+
operatingSystems: [OS.Darwin],
|
|
783
802
|
parameterSettings: {
|
|
784
803
|
propD: { type: 'object' }
|
|
785
804
|
}
|
|
@@ -822,6 +841,7 @@ describe('Resource parameter tests', () => {
|
|
|
822
841
|
getSettings(): ResourceSettings<TestConfig> {
|
|
823
842
|
return {
|
|
824
843
|
id: 'resourceType',
|
|
844
|
+
operatingSystems: [OS.Darwin],
|
|
825
845
|
parameterSettings: {
|
|
826
846
|
propD: { type: 'object' }
|
|
827
847
|
}
|
|
@@ -863,6 +883,7 @@ describe('Resource parameter tests', () => {
|
|
|
863
883
|
getSettings(): ResourceSettings<TestConfig> {
|
|
864
884
|
return {
|
|
865
885
|
id: 'resourceType',
|
|
886
|
+
operatingSystems: [OS.Darwin],
|
|
866
887
|
parameterSettings: {
|
|
867
888
|
propD: {
|
|
868
889
|
type: 'array',
|
|
@@ -968,6 +989,7 @@ describe('Resource parameter tests', () => {
|
|
|
968
989
|
getSettings(): ResourceSettings<TestConfig> {
|
|
969
990
|
return {
|
|
970
991
|
id: 'resourceType',
|
|
992
|
+
operatingSystems: [OS.Darwin],
|
|
971
993
|
parameterSettings: {
|
|
972
994
|
propD: { type: 'stateful', definition: sp }
|
|
973
995
|
}
|
|
@@ -1007,6 +1029,7 @@ describe('Resource parameter tests', () => {
|
|
|
1007
1029
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1008
1030
|
return {
|
|
1009
1031
|
id: 'resourceType',
|
|
1032
|
+
operatingSystems: [OS.Darwin],
|
|
1010
1033
|
parameterSettings: {
|
|
1011
1034
|
propA: { type: 'array', itemType: 'version' }
|
|
1012
1035
|
}
|
|
@@ -1036,6 +1059,7 @@ describe('Resource parameter tests', () => {
|
|
|
1036
1059
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1037
1060
|
return {
|
|
1038
1061
|
id: 'resourceType',
|
|
1062
|
+
operatingSystems: [OS.Darwin],
|
|
1039
1063
|
parameterSettings: {
|
|
1040
1064
|
propA: { type: 'array', itemType: 'directory' }
|
|
1041
1065
|
}
|
|
@@ -1065,6 +1089,7 @@ describe('Resource parameter tests', () => {
|
|
|
1065
1089
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1066
1090
|
return {
|
|
1067
1091
|
id: 'resourceType',
|
|
1092
|
+
operatingSystems: [OS.Darwin],
|
|
1068
1093
|
parameterSettings: {
|
|
1069
1094
|
propA: { type: 'array', itemType: 'directory' }
|
|
1070
1095
|
},
|
|
@@ -1101,6 +1126,7 @@ describe('Resource parameter tests', () => {
|
|
|
1101
1126
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1102
1127
|
return {
|
|
1103
1128
|
id: 'resourceType',
|
|
1129
|
+
operatingSystems: [OS.Darwin],
|
|
1104
1130
|
parameterSettings: {
|
|
1105
1131
|
propA: { type: 'array', itemType: 'directory' }
|
|
1106
1132
|
},
|
|
@@ -1127,6 +1153,7 @@ describe('Resource parameter tests', () => {
|
|
|
1127
1153
|
getSettings(): ResourceSettings<TestConfig> {
|
|
1128
1154
|
return {
|
|
1129
1155
|
id: 'resourceType',
|
|
1156
|
+
operatingSystems: [OS.Darwin],
|
|
1130
1157
|
parameterSettings: {
|
|
1131
1158
|
propA: { type: 'directory' }
|
|
1132
1159
|
},
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { StringIndexedObject } from 'codify-schemas';
|
|
2
|
+
import { OS, StringIndexedObject } from 'codify-schemas';
|
|
3
3
|
import isObjectsEqual from 'lodash.isequal'
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
addVariablesToPath,
|
|
9
|
+
areArraysEqual,
|
|
10
|
+
resolvePathWithVariables,
|
|
11
|
+
tildify,
|
|
12
|
+
untildify
|
|
13
|
+
} from '../utils/internal-utils.js';
|
|
8
14
|
import { RefreshContext } from './resource.js';
|
|
9
15
|
|
|
10
16
|
export interface InputTransformation {
|
|
@@ -22,6 +28,11 @@ export interface ResourceSettings<T extends StringIndexedObject> {
|
|
|
22
28
|
*/
|
|
23
29
|
id: string;
|
|
24
30
|
|
|
31
|
+
/**
|
|
32
|
+
* List of supported operating systems
|
|
33
|
+
*/
|
|
34
|
+
operatingSystems: Array<OS>;
|
|
35
|
+
|
|
25
36
|
/**
|
|
26
37
|
* Schema to validate user configs with. Must be in the format JSON Schema draft07
|
|
27
38
|
*/
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { OS } from 'codify-schemas';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export enum Shell {
|
|
6
|
+
ZSH = 'zsh',
|
|
7
|
+
BASH = 'bash',
|
|
8
|
+
SH = 'sh',
|
|
9
|
+
KSH = 'ksh',
|
|
10
|
+
CSH = 'csh',
|
|
11
|
+
FISH = 'fish',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SystemInfo {
|
|
15
|
+
os: OS;
|
|
16
|
+
shell: Shell;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const Utils = {
|
|
20
|
+
getUser(): string {
|
|
21
|
+
return os.userInfo().username;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
getSystemInfo() {
|
|
25
|
+
return {
|
|
26
|
+
os: os.type(),
|
|
27
|
+
shell: this.getShell(),
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
isMacOS(): boolean {
|
|
32
|
+
return os.platform() === 'darwin';
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
isLinux(): boolean {
|
|
36
|
+
return os.platform() === 'linux';
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
getShell(): Shell | undefined {
|
|
40
|
+
const shell = process.env.SHELL || '';
|
|
41
|
+
|
|
42
|
+
if (shell.endsWith('bash')) {
|
|
43
|
+
return Shell.BASH
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (shell.endsWith('zsh')) {
|
|
47
|
+
return Shell.ZSH
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (shell.endsWith('sh')) {
|
|
51
|
+
return Shell.SH
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (shell.endsWith('csh')) {
|
|
55
|
+
return Shell.CSH
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (shell.endsWith('ksh')) {
|
|
59
|
+
return Shell.KSH
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (shell.endsWith('fish')) {
|
|
63
|
+
return Shell.FISH
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return undefined;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
getPrimaryShellRc(): string {
|
|
71
|
+
return this.getShellRcFiles()[0];
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
getShellRcFiles(): string[] {
|
|
75
|
+
const shell = process.env.SHELL || '';
|
|
76
|
+
const homeDir = os.homedir();
|
|
77
|
+
|
|
78
|
+
if (shell.endsWith('bash')) {
|
|
79
|
+
// Linux typically uses .bashrc, macOS uses .bash_profile
|
|
80
|
+
if (Utils.isLinux()) {
|
|
81
|
+
return [
|
|
82
|
+
path.join(homeDir, '.bashrc'),
|
|
83
|
+
path.join(homeDir, '.bash_profile'),
|
|
84
|
+
path.join(homeDir, '.profile'),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [
|
|
89
|
+
path.join(homeDir, '.bash_profile'),
|
|
90
|
+
path.join(homeDir, '.bashrc'),
|
|
91
|
+
path.join(homeDir, '.profile'),
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (shell.endsWith('zsh')) {
|
|
96
|
+
return [
|
|
97
|
+
path.join(homeDir, '.zshrc'),
|
|
98
|
+
path.join(homeDir, '.zprofile'),
|
|
99
|
+
path.join(homeDir, '.zshenv'),
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (shell.endsWith('sh')) {
|
|
104
|
+
return [
|
|
105
|
+
path.join(homeDir, '.profile'),
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (shell.endsWith('ksh')) {
|
|
110
|
+
return [
|
|
111
|
+
path.join(homeDir, '.profile'),
|
|
112
|
+
path.join(homeDir, '.kshrc'),
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (shell.endsWith('csh')) {
|
|
117
|
+
return [
|
|
118
|
+
path.join(homeDir, '.cshrc'),
|
|
119
|
+
path.join(homeDir, '.login'),
|
|
120
|
+
path.join(homeDir, '.logout'),
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (shell.endsWith('fish')) {
|
|
125
|
+
return [
|
|
126
|
+
path.join(homeDir, '.config/fish/config.fish'),
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Default to bash-style files
|
|
131
|
+
return [
|
|
132
|
+
path.join(homeDir, '.bashrc'),
|
|
133
|
+
path.join(homeDir, '.bash_profile'),
|
|
134
|
+
path.join(homeDir, '.profile'),
|
|
135
|
+
];
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { addVariablesToPath, resolvePathWithVariables, splitUserConfig } from './utils.js';
|
|
2
|
+
import { addVariablesToPath, resolvePathWithVariables, splitUserConfig } from './internal-utils.js';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
|
|
5
5
|
describe('Utils tests', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
|
|
1
|
+
import { OS, ResourceConfig, StringIndexedObject } from 'codify-schemas';
|
|
2
2
|
import { ResourceSettings } from '../resource/resource-settings.js';
|
|
3
3
|
import { Plan } from '../plan/plan.js';
|
|
4
4
|
import { Resource } from '../resource/resource.js';
|
|
@@ -35,7 +35,10 @@ export interface TestConfig extends StringIndexedObject {
|
|
|
35
35
|
|
|
36
36
|
export class TestResource extends Resource<TestConfig> {
|
|
37
37
|
getSettings(): ResourceSettings<TestConfig> {
|
|
38
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
id: 'type',
|
|
40
|
+
operatingSystems: [OS.Darwin]
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
create(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
File without changes
|