codify-plugin-lib 1.0.182-beta52 → 1.0.182-beta54
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 +86 -5
- package/dist/messages/handlers.js +6 -1
- package/dist/plugin/plugin.d.ts +2 -1
- package/dist/plugin/plugin.js +3 -0
- package/package.json +2 -2
- package/src/messages/handlers.ts +7 -1
- package/src/plugin/plugin.ts +5 -1
package/bin/build.js
CHANGED
|
@@ -5,9 +5,8 @@ import mergeJsonSchemas from 'merge-json-schemas';
|
|
|
5
5
|
import { fork } from 'node:child_process';
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import * as url from 'node:url';
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { SequentialPty, VerbosityLevel } from '../dist/index.js';
|
|
11
10
|
|
|
12
11
|
const ajv = new Ajv({
|
|
13
12
|
strict: true
|
|
@@ -36,6 +35,58 @@ function sendMessageAndAwaitResponse(process, message) {
|
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
function fetchDocumentationMaps() {
|
|
39
|
+
console.log('Building documentation...');
|
|
40
|
+
|
|
41
|
+
const results = new Map();
|
|
42
|
+
const resourcesPath = path.resolve(process.cwd(), 'src', 'resources');
|
|
43
|
+
const resourcesDir = fs.readdirSync(resourcesPath);
|
|
44
|
+
|
|
45
|
+
for (const resource of resourcesDir) {
|
|
46
|
+
const resourcePath = path.join(resourcesPath, resource);
|
|
47
|
+
if (!isDirectory(resourcePath)) continue;
|
|
48
|
+
|
|
49
|
+
const contents = fs.readdirSync(resourcePath);
|
|
50
|
+
const isGroup = contents.some((content) => isDirectory(path.join(resourcePath, content)));
|
|
51
|
+
const isAllDir = contents.every((content) => isDirectory(path.join(resourcePath, content)));
|
|
52
|
+
|
|
53
|
+
if (isGroup && !isAllDir) {
|
|
54
|
+
throw new Error(`Documentation groups must only contain directories. ${resourcePath} does not`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!isGroup) {
|
|
58
|
+
if (contents.includes('README.md')) {
|
|
59
|
+
results.set(resource, resource);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
for (const innerDir of contents) {
|
|
63
|
+
const innerDirReadme = path.join(resourcePath, innerDir, 'README.md');
|
|
64
|
+
if (isFile(innerDirReadme)) {
|
|
65
|
+
results.set(innerDir, path.relative('./src/resources', path.join(resourcePath, innerDir)));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isDirectory(path) {
|
|
75
|
+
try {
|
|
76
|
+
return fs.statSync(path).isDirectory();
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isFile(path) {
|
|
83
|
+
try {
|
|
84
|
+
return fs.statSync(path).isFile();
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
39
90
|
VerbosityLevel.set(3);
|
|
40
91
|
const $ = new SequentialPty();
|
|
41
92
|
|
|
@@ -60,6 +111,7 @@ const initializeResult = await sendMessageAndAwaitResponse(plugin, {
|
|
|
60
111
|
|
|
61
112
|
const { resourceDefinitions } = initializeResult;
|
|
62
113
|
const resourceTypes = resourceDefinitions.map((i) => i.type);
|
|
114
|
+
const resourceInfoMap = new Map();
|
|
63
115
|
|
|
64
116
|
const schemasMap = new Map()
|
|
65
117
|
for (const type of resourceTypes) {
|
|
@@ -69,8 +121,11 @@ for (const type of resourceTypes) {
|
|
|
69
121
|
})
|
|
70
122
|
|
|
71
123
|
schemasMap.set(type, resourceInfo.schema);
|
|
124
|
+
resourceInfoMap.set(type, resourceInfo);
|
|
72
125
|
}
|
|
73
126
|
|
|
127
|
+
console.log(resourceInfoMap);
|
|
128
|
+
|
|
74
129
|
const mergedSchemas = [...schemasMap.entries()].map(([type, schema]) => {
|
|
75
130
|
// const resolvedSchema = await $RefParser.dereference(schema)
|
|
76
131
|
const resourceSchema = JSON.parse(JSON.stringify(ResourceSchema));
|
|
@@ -97,12 +152,38 @@ await $.spawn('npm run rollup', { interactive: true }); // re-run rollup without
|
|
|
97
152
|
|
|
98
153
|
console.log('Generated JSON Schemas for all resources')
|
|
99
154
|
|
|
100
|
-
const distFolder = path.resolve(
|
|
155
|
+
const distFolder = path.resolve(process.cwd(), 'dist');
|
|
101
156
|
const schemaOutputPath = path.resolve(distFolder, 'schemas.json');
|
|
102
157
|
fs.writeFileSync(schemaOutputPath, JSON.stringify(mergedSchemas, null, 2));
|
|
103
158
|
|
|
104
|
-
console.log('Successfully wrote schema to ./dist/schemas.json')
|
|
105
|
-
|
|
159
|
+
console.log('Successfully wrote schema to ./dist/schemas.json');
|
|
160
|
+
|
|
161
|
+
const documentationMap = fetchDocumentationMaps();
|
|
162
|
+
|
|
163
|
+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
164
|
+
|
|
165
|
+
fs.writeFileSync('./dist/manifest.json', JSON.stringify({
|
|
166
|
+
name: packageJson.name,
|
|
167
|
+
version: packageJson.version,
|
|
168
|
+
description: packageJson.description,
|
|
169
|
+
resources: [...resourceInfoMap.values()].map((info) => ({
|
|
170
|
+
type: info.type,
|
|
171
|
+
description: info.description ?? info.schema?.description,
|
|
172
|
+
sensitiveParameters: info.sensitiveParameters,
|
|
173
|
+
schema: info.schema,
|
|
174
|
+
operatingSystems: info.operatingSystems,
|
|
175
|
+
documentationKey: documentationMap.get(info.type),
|
|
176
|
+
})),
|
|
177
|
+
}, null, 2), 'utf8');
|
|
178
|
+
|
|
179
|
+
for (const key of documentationMap.values()) {
|
|
180
|
+
fs.mkdirSync(path.join('dist', 'documentation', key), { recursive: true })
|
|
181
|
+
|
|
182
|
+
fs.copyFileSync(
|
|
183
|
+
path.resolve(path.join('src', 'resources', key, 'README.md')),
|
|
184
|
+
path.resolve(path.join('dist', 'documentation', key, 'README.md')),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
106
187
|
|
|
107
188
|
plugin.kill(9);
|
|
108
189
|
process.exit(0);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ajv } from 'ajv';
|
|
2
2
|
import addFormats from 'ajv-formats';
|
|
3
|
-
import { ApplyRequestDataSchema, ApplyResponseDataSchema, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, IpcMessageV2Schema, MatchRequestDataSchema, MatchResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from 'codify-schemas';
|
|
3
|
+
import { ApplyRequestDataSchema, ApplyResponseDataSchema, EmptyResponseDataSchema, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, IpcMessageV2Schema, MatchRequestDataSchema, MatchResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, SetVerbosityRequestDataSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from 'codify-schemas';
|
|
4
4
|
import { SudoError } from '../errors.js';
|
|
5
5
|
const SupportedRequests = {
|
|
6
6
|
'initialize': {
|
|
@@ -18,6 +18,11 @@ const SupportedRequests = {
|
|
|
18
18
|
requestValidator: GetResourceInfoRequestDataSchema,
|
|
19
19
|
responseValidator: GetResourceInfoResponseDataSchema
|
|
20
20
|
},
|
|
21
|
+
'setVerbosityLevel': {
|
|
22
|
+
handler: async (plugin, data) => plugin.setVerbosityLevel(data),
|
|
23
|
+
requestValidator: SetVerbosityRequestDataSchema,
|
|
24
|
+
responseValidator: EmptyResponseDataSchema
|
|
25
|
+
},
|
|
21
26
|
'match': {
|
|
22
27
|
handler: async (plugin, data) => plugin.match(data),
|
|
23
28
|
requestValidator: MatchRequestDataSchema,
|
package/dist/plugin/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, ImportRequestData, ImportResponseData, InitializeRequestData, InitializeResponseData, MatchRequestData, MatchResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ResourceJson, ValidateRequestData, ValidateResponseData } from 'codify-schemas';
|
|
1
|
+
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, ImportRequestData, ImportResponseData, InitializeRequestData, InitializeResponseData, MatchRequestData, MatchResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ResourceJson, SetVerbosityRequestData, ValidateRequestData, ValidateResponseData } from 'codify-schemas';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { BackgroundPty } from '../pty/background-pty.js';
|
|
4
4
|
import { Resource } from '../resource/resource.js';
|
|
@@ -17,6 +17,7 @@ export declare class Plugin {
|
|
|
17
17
|
validate(data: ValidateRequestData): Promise<ValidateResponseData>;
|
|
18
18
|
plan(data: PlanRequestData): Promise<PlanResponseData>;
|
|
19
19
|
apply(data: ApplyRequestData): Promise<void>;
|
|
20
|
+
setVerbosityLevel(data: SetVerbosityRequestData): Promise<void>;
|
|
20
21
|
kill(): Promise<void>;
|
|
21
22
|
private resolvePlan;
|
|
22
23
|
protected crossValidateResources(resources: ResourceJson[]): Promise<void>;
|
package/dist/plugin/plugin.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-lib",
|
|
3
|
-
"version": "1.0.182-
|
|
3
|
+
"version": "1.0.182-beta54",
|
|
4
4
|
"description": "Library plugin library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"ajv": "^8.12.0",
|
|
23
23
|
"ajv-formats": "^2.1.1",
|
|
24
24
|
"clean-deep": "^3.4.0",
|
|
25
|
-
"codify-schemas": "1.0.86-
|
|
25
|
+
"codify-schemas": "1.0.86-beta9",
|
|
26
26
|
"lodash.isequal": "^4.5.0",
|
|
27
27
|
"nanoid": "^5.0.9",
|
|
28
28
|
"strip-ansi": "^7.1.0",
|
package/src/messages/handlers.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Ajv, SchemaObject, ValidateFunction } from 'ajv';
|
|
|
2
2
|
import addFormats from 'ajv-formats';
|
|
3
3
|
import {
|
|
4
4
|
ApplyRequestDataSchema,
|
|
5
|
-
ApplyResponseDataSchema,
|
|
5
|
+
ApplyResponseDataSchema, EmptyResponseDataSchema,
|
|
6
6
|
GetResourceInfoRequestDataSchema,
|
|
7
7
|
GetResourceInfoResponseDataSchema,
|
|
8
8
|
ImportRequestDataSchema,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
PlanRequestDataSchema,
|
|
20
20
|
PlanResponseDataSchema,
|
|
21
21
|
ResourceSchema,
|
|
22
|
+
SetVerbosityRequestDataSchema,
|
|
22
23
|
ValidateRequestDataSchema,
|
|
23
24
|
ValidateResponseDataSchema
|
|
24
25
|
} from 'codify-schemas';
|
|
@@ -42,6 +43,11 @@ const SupportedRequests: Record<string, { handler: (plugin: Plugin, data: any) =
|
|
|
42
43
|
requestValidator: GetResourceInfoRequestDataSchema,
|
|
43
44
|
responseValidator: GetResourceInfoResponseDataSchema
|
|
44
45
|
},
|
|
46
|
+
'setVerbosityLevel': {
|
|
47
|
+
handler: async (plugin: Plugin, data: any) => plugin.setVerbosityLevel(data),
|
|
48
|
+
requestValidator: SetVerbosityRequestDataSchema,
|
|
49
|
+
responseValidator: EmptyResponseDataSchema
|
|
50
|
+
},
|
|
45
51
|
'match': {
|
|
46
52
|
handler: async (plugin: Plugin, data: any) => plugin.match(data),
|
|
47
53
|
requestValidator: MatchRequestDataSchema,
|
package/src/plugin/plugin.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
PlanRequestData,
|
|
13
13
|
PlanResponseData,
|
|
14
14
|
ResourceConfig,
|
|
15
|
-
ResourceJson,
|
|
15
|
+
ResourceJson, SetVerbosityRequestData,
|
|
16
16
|
ValidateRequestData,
|
|
17
17
|
ValidateResponseData
|
|
18
18
|
} from 'codify-schemas';
|
|
@@ -257,6 +257,10 @@ export class Plugin {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
async setVerbosityLevel(data: SetVerbosityRequestData): Promise<void> {
|
|
261
|
+
VerbosityLevel.set(data.verbosityLevel);
|
|
262
|
+
}
|
|
263
|
+
|
|
260
264
|
async kill() {
|
|
261
265
|
await this.planPty.kill();
|
|
262
266
|
}
|