@codifycli/plugin-core 1.0.0-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/.eslintignore +2 -0
- package/.eslintrc.json +30 -0
- package/.github/workflows/release.yaml +19 -0
- package/.github/workflows/unit-test-ci.yaml +18 -0
- package/.prettierrc.json +1 -0
- package/bin/build.js +189 -0
- package/dist/bin/build.d.ts +1 -0
- package/dist/bin/build.js +80 -0
- package/dist/bin/deploy-plugin.d.ts +2 -0
- package/dist/bin/deploy-plugin.js +8 -0
- package/dist/common/errors.d.ts +8 -0
- package/dist/common/errors.js +24 -0
- package/dist/entities/change-set.d.ts +24 -0
- package/dist/entities/change-set.js +152 -0
- package/dist/entities/errors.d.ts +4 -0
- package/dist/entities/errors.js +7 -0
- package/dist/entities/plan-types.d.ts +25 -0
- package/dist/entities/plan-types.js +1 -0
- package/dist/entities/plan.d.ts +15 -0
- package/dist/entities/plan.js +127 -0
- package/dist/entities/plugin.d.ts +16 -0
- package/dist/entities/plugin.js +80 -0
- package/dist/entities/resource-options.d.ts +31 -0
- package/dist/entities/resource-options.js +76 -0
- package/dist/entities/resource-types.d.ts +11 -0
- package/dist/entities/resource-types.js +1 -0
- package/dist/entities/resource.d.ts +42 -0
- package/dist/entities/resource.js +303 -0
- package/dist/entities/stateful-parameter.d.ts +29 -0
- package/dist/entities/stateful-parameter.js +46 -0
- package/dist/entities/transform-parameter.d.ts +4 -0
- package/dist/entities/transform-parameter.js +2 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +7 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +26 -0
- package/dist/messages/handlers.d.ts +14 -0
- package/dist/messages/handlers.js +134 -0
- package/dist/messages/sender.d.ts +11 -0
- package/dist/messages/sender.js +57 -0
- package/dist/plan/change-set.d.ts +53 -0
- package/dist/plan/change-set.js +153 -0
- package/dist/plan/plan-types.d.ts +23 -0
- package/dist/plan/plan-types.js +1 -0
- package/dist/plan/plan.d.ts +66 -0
- package/dist/plan/plan.js +328 -0
- package/dist/plugin/plugin.d.ts +24 -0
- package/dist/plugin/plugin.js +200 -0
- package/dist/pty/background-pty.d.ts +21 -0
- package/dist/pty/background-pty.js +127 -0
- package/dist/pty/index.d.ts +50 -0
- package/dist/pty/index.js +20 -0
- package/dist/pty/promise-queue.d.ts +5 -0
- package/dist/pty/promise-queue.js +26 -0
- package/dist/pty/seqeuntial-pty.d.ts +17 -0
- package/dist/pty/seqeuntial-pty.js +119 -0
- package/dist/pty/vitest.config.d.ts +2 -0
- package/dist/pty/vitest.config.js +11 -0
- package/dist/resource/config-parser.d.ts +11 -0
- package/dist/resource/config-parser.js +21 -0
- package/dist/resource/parsed-resource-settings.d.ts +47 -0
- package/dist/resource/parsed-resource-settings.js +196 -0
- package/dist/resource/resource-controller.d.ts +36 -0
- package/dist/resource/resource-controller.js +402 -0
- package/dist/resource/resource-settings.d.ts +303 -0
- package/dist/resource/resource-settings.js +147 -0
- package/dist/resource/resource.d.ts +144 -0
- package/dist/resource/resource.js +44 -0
- package/dist/resource/stateful-parameter.d.ts +165 -0
- package/dist/resource/stateful-parameter.js +94 -0
- package/dist/scripts/deploy.d.ts +1 -0
- package/dist/scripts/deploy.js +2 -0
- package/dist/stateful-parameter/stateful-parameter-controller.d.ts +21 -0
- package/dist/stateful-parameter/stateful-parameter-controller.js +81 -0
- package/dist/stateful-parameter/stateful-parameter.d.ts +144 -0
- package/dist/stateful-parameter/stateful-parameter.js +43 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +5 -0
- package/dist/utils/codify-spawn.d.ts +29 -0
- package/dist/utils/codify-spawn.js +136 -0
- package/dist/utils/debug.d.ts +2 -0
- package/dist/utils/debug.js +10 -0
- package/dist/utils/file-utils.d.ts +23 -0
- package/dist/utils/file-utils.js +186 -0
- package/dist/utils/functions.d.ts +12 -0
- package/dist/utils/functions.js +74 -0
- package/dist/utils/index.d.ts +46 -0
- package/dist/utils/index.js +271 -0
- package/dist/utils/internal-utils.d.ts +12 -0
- package/dist/utils/internal-utils.js +74 -0
- package/dist/utils/load-resources.d.ts +1 -0
- package/dist/utils/load-resources.js +46 -0
- package/dist/utils/package-json-utils.d.ts +12 -0
- package/dist/utils/package-json-utils.js +34 -0
- package/dist/utils/pty-local-storage.d.ts +2 -0
- package/dist/utils/pty-local-storage.js +2 -0
- package/dist/utils/spawn-2.d.ts +5 -0
- package/dist/utils/spawn-2.js +7 -0
- package/dist/utils/spawn.d.ts +29 -0
- package/dist/utils/spawn.js +124 -0
- package/dist/utils/utils.d.ts +18 -0
- package/dist/utils/utils.js +86 -0
- package/dist/utils/verbosity-level.d.ts +5 -0
- package/dist/utils/verbosity-level.js +9 -0
- package/package.json +59 -0
- package/rollup.config.js +24 -0
- package/src/common/errors.test.ts +43 -0
- package/src/common/errors.ts +31 -0
- package/src/errors.ts +8 -0
- package/src/index.test.ts +6 -0
- package/src/index.ts +30 -0
- package/src/messages/handlers.test.ts +329 -0
- package/src/messages/handlers.ts +181 -0
- package/src/messages/sender.ts +69 -0
- package/src/plan/change-set.test.ts +280 -0
- package/src/plan/change-set.ts +236 -0
- package/src/plan/plan-types.ts +27 -0
- package/src/plan/plan.test.ts +413 -0
- package/src/plan/plan.ts +499 -0
- package/src/plugin/plugin.test.ts +533 -0
- package/src/plugin/plugin.ts +291 -0
- package/src/pty/background-pty.test.ts +69 -0
- package/src/pty/background-pty.ts +154 -0
- package/src/pty/index.test.ts +129 -0
- package/src/pty/index.ts +66 -0
- package/src/pty/promise-queue.ts +33 -0
- package/src/pty/seqeuntial-pty.ts +151 -0
- package/src/pty/sequential-pty.test.ts +194 -0
- package/src/resource/config-parser.ts +42 -0
- package/src/resource/parsed-resource-settings.test.ts +186 -0
- package/src/resource/parsed-resource-settings.ts +307 -0
- package/src/resource/resource-controller-stateful-mode.test.ts +253 -0
- package/src/resource/resource-controller.test.ts +1081 -0
- package/src/resource/resource-controller.ts +563 -0
- package/src/resource/resource-settings.test.ts +1213 -0
- package/src/resource/resource-settings.ts +545 -0
- package/src/resource/resource.ts +157 -0
- package/src/stateful-parameter/stateful-parameter-controller.test.ts +244 -0
- package/src/stateful-parameter/stateful-parameter-controller.ts +111 -0
- package/src/stateful-parameter/stateful-parameter.ts +160 -0
- package/src/utils/debug.ts +11 -0
- package/src/utils/file-utils.test.ts +7 -0
- package/src/utils/file-utils.ts +231 -0
- package/src/utils/functions.ts +103 -0
- package/src/utils/index.ts +340 -0
- package/src/utils/internal-utils.test.ts +52 -0
- package/src/utils/pty-local-storage.ts +3 -0
- package/src/utils/test-utils.test.ts +96 -0
- package/src/utils/verbosity-level.ts +11 -0
- package/tsconfig.json +26 -0
- package/tsconfig.test.json +9 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { addVariablesToPath, resolvePathWithVariables, splitUserConfig } from './functions.js';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
|
|
5
|
+
describe('Utils tests', () => {
|
|
6
|
+
it('Can split a config correctly', () => {
|
|
7
|
+
const { parameters, coreParameters } = splitUserConfig({
|
|
8
|
+
type: 'type',
|
|
9
|
+
name: 'name',
|
|
10
|
+
dependsOn: ['a', 'b', 'c'],
|
|
11
|
+
os: ['linux'],
|
|
12
|
+
propA: 'propA',
|
|
13
|
+
propB: 'propB',
|
|
14
|
+
propC: 'propC',
|
|
15
|
+
propD: 'propD',
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
expect(coreParameters).toMatchObject({
|
|
19
|
+
type: 'type',
|
|
20
|
+
name: 'name',
|
|
21
|
+
dependsOn: ['a', 'b', 'c'],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
expect(parameters).toMatchObject({
|
|
25
|
+
propA: 'propA',
|
|
26
|
+
propB: 'propB',
|
|
27
|
+
propC: 'propC',
|
|
28
|
+
propD: 'propD',
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Can remove variables from a path', () => {
|
|
33
|
+
const testPath1 = '$HOME/my/path';
|
|
34
|
+
const result1 = resolvePathWithVariables(testPath1);
|
|
35
|
+
|
|
36
|
+
const home = os.homedir();
|
|
37
|
+
expect(result1).to.eq(home + '/my/path');
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const testPath2 = '/var$HOME/my/path';
|
|
41
|
+
const result2 = resolvePathWithVariables(testPath2);
|
|
42
|
+
expect(result2).to.eq('/var' + home + '/my/path');
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('Can add variables to a path (ignores home)', () => {
|
|
46
|
+
const testPath1 = os.homedir() + '/my/path';
|
|
47
|
+
const result1 = addVariablesToPath(testPath1);
|
|
48
|
+
|
|
49
|
+
const home = os.homedir();
|
|
50
|
+
expect(result1).to.eq(home + '/my/path');
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { OS, ResourceConfig, StringIndexedObject } from 'codify-schemas';
|
|
2
|
+
import { ResourceSettings } from '../resource/resource-settings.js';
|
|
3
|
+
import { Plan } from '../plan/plan.js';
|
|
4
|
+
import { Resource } from '../resource/resource.js';
|
|
5
|
+
import { CreatePlan, DestroyPlan } from '../plan/plan-types.js';
|
|
6
|
+
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
7
|
+
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
|
|
8
|
+
import { describe, it } from 'vitest';
|
|
9
|
+
|
|
10
|
+
export function testPlan<T extends StringIndexedObject>(params: {
|
|
11
|
+
desired?: Partial<T> | null;
|
|
12
|
+
current?: Partial<T>[] | null;
|
|
13
|
+
state?: Partial<T> | null;
|
|
14
|
+
core?: ResourceConfig;
|
|
15
|
+
settings?: ResourceSettings<T>;
|
|
16
|
+
isStateful?: boolean;
|
|
17
|
+
}) {
|
|
18
|
+
return Plan.calculate({
|
|
19
|
+
desired: params.desired ?? null,
|
|
20
|
+
currentArray: params.current ?? null,
|
|
21
|
+
state: params.state ?? null,
|
|
22
|
+
core: params.core ?? { type: 'type' },
|
|
23
|
+
settings: params.settings ?
|
|
24
|
+
new ParsedResourceSettings<T>(params.settings)
|
|
25
|
+
: new ParsedResourceSettings<T>({ id: 'type' }),
|
|
26
|
+
isStateful: params.isStateful ?? false,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TestConfig extends StringIndexedObject {
|
|
31
|
+
propA: string;
|
|
32
|
+
propB: number;
|
|
33
|
+
propC?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class TestResource extends Resource<TestConfig> {
|
|
37
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
38
|
+
return {
|
|
39
|
+
id: 'type',
|
|
40
|
+
operatingSystems: [OS.Darwin]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
create(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
45
|
+
return Promise.resolve(undefined);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
|
|
49
|
+
return Promise.resolve(undefined);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Partial<TestConfig> | null> {
|
|
53
|
+
return {
|
|
54
|
+
propA: 'a',
|
|
55
|
+
propB: 10,
|
|
56
|
+
propC: 'c',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class TestStatefulParameter extends StatefulParameter<TestConfig, string> {
|
|
62
|
+
async refresh(desired: string | null): Promise<string | null> {
|
|
63
|
+
return 'd';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async add(valueToAdd: string, plan: Plan<TestConfig>): Promise<void> {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async modify(newValue: string, previousValue: string, plan: Plan<TestConfig>): Promise<void> {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async remove(valueToRemove: string, plan: Plan<TestConfig>): Promise<void> {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export class TestArrayStatefulParameter extends ArrayStatefulParameter<TestConfig, string> {
|
|
80
|
+
async refresh(): Promise<any | null> {
|
|
81
|
+
return ['3.11.9']
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
addItem(item: string, plan: Plan<TestConfig>): Promise<void> {
|
|
85
|
+
return Promise.resolve(undefined);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
removeItem(item: string, plan: Plan<TestConfig>): Promise<void> {
|
|
89
|
+
return Promise.resolve(undefined);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
describe('Empty tests', () => {
|
|
94
|
+
it('empty', () => {
|
|
95
|
+
})
|
|
96
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "Node16",
|
|
6
|
+
"alwaysStrict": true,
|
|
7
|
+
"noImplicitAny": true,
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"strictNullChecks": true,
|
|
11
|
+
"emitDecoratorMetadata": true,
|
|
12
|
+
"experimentalDecorators": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"rootDir": "src",
|
|
15
|
+
"strict": true,
|
|
16
|
+
"target": "es2022"
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"src/**/*.ts"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"src/**/*.test.ts",
|
|
24
|
+
"**/vitest.config.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|