codify-plugin-lib 1.0.182-beta47 → 1.0.182-beta49
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 +113 -0
- package/dist/bin/build.js +0 -0
- package/package.json +2 -2
- package/bin/build.ts +0 -1
package/bin/build.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Ajv } from 'ajv';
|
|
3
|
+
import { IpcMessageSchema, MessageStatus, ResourceSchema } from 'codify-schemas';
|
|
4
|
+
import mergeJsonSchemas from 'merge-json-schemas';
|
|
5
|
+
import { fork } from 'node:child_process';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import * as url from 'node:url';
|
|
9
|
+
|
|
10
|
+
import { VerbosityLevel } from '../src/index.ts';
|
|
11
|
+
import { SequentialPty } from '../src/pty/seqeuntial-pty.ts';
|
|
12
|
+
|
|
13
|
+
const ajv = new Ajv({
|
|
14
|
+
strict: true
|
|
15
|
+
});
|
|
16
|
+
const ipcMessageValidator = ajv.compile(IpcMessageSchema);
|
|
17
|
+
|
|
18
|
+
function sendMessageAndAwaitResponse(process, message): Promise<any> {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
process.on('message', (response) => {
|
|
21
|
+
if (!ipcMessageValidator(response)) {
|
|
22
|
+
throw new Error(`Invalid message from plugin. ${JSON.stringify(message, null, 2)}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Wait for the message response. Other messages such as sudoRequest may be sent before the response returns
|
|
26
|
+
if (response.cmd === message.cmd + '_Response') {
|
|
27
|
+
if (response.status === MessageStatus.SUCCESS) {
|
|
28
|
+
resolve(response.data)
|
|
29
|
+
} else {
|
|
30
|
+
reject(new Error(String(response.data)))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Send message last to ensure listeners are all registered
|
|
36
|
+
process.send(message);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
VerbosityLevel.set(3);
|
|
41
|
+
const $ = new SequentialPty();
|
|
42
|
+
|
|
43
|
+
await $.spawn('rm -rf ./dist')
|
|
44
|
+
await $.spawn('npm run rollup -- -f es', { interactive: true });
|
|
45
|
+
|
|
46
|
+
const plugin = fork(
|
|
47
|
+
'./dist/index.js',
|
|
48
|
+
[],
|
|
49
|
+
{
|
|
50
|
+
// Use default true to test plugins in secure mode (un-able to request sudo directly)
|
|
51
|
+
detached: true,
|
|
52
|
+
env: { ...process.env },
|
|
53
|
+
execArgv: ['--import', 'tsx/esm'],
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const initializeResult = await sendMessageAndAwaitResponse(plugin, {
|
|
58
|
+
cmd: 'initialize',
|
|
59
|
+
data: {}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const { resourceDefinitions } = initializeResult;
|
|
63
|
+
const resourceTypes = resourceDefinitions.map((i) => i.type);
|
|
64
|
+
|
|
65
|
+
const schemasMap = new Map()
|
|
66
|
+
for (const type of resourceTypes) {
|
|
67
|
+
const resourceInfo = await sendMessageAndAwaitResponse(plugin, {
|
|
68
|
+
cmd: 'getResourceInfo',
|
|
69
|
+
data: { type }
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
schemasMap.set(type, resourceInfo.schema);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const mergedSchemas = [...schemasMap.entries()].map(([type, schema]) => {
|
|
76
|
+
// const resolvedSchema = await $RefParser.dereference(schema)
|
|
77
|
+
const resourceSchema = JSON.parse(JSON.stringify(ResourceSchema));
|
|
78
|
+
|
|
79
|
+
delete resourceSchema.$id;
|
|
80
|
+
delete resourceSchema.$schema;
|
|
81
|
+
delete resourceSchema.title;
|
|
82
|
+
delete resourceSchema.oneOf;
|
|
83
|
+
delete resourceSchema.properties.type;
|
|
84
|
+
|
|
85
|
+
if (schema) {
|
|
86
|
+
delete schema.$id;
|
|
87
|
+
delete schema.$schema;
|
|
88
|
+
delete schema.title;
|
|
89
|
+
delete schema.oneOf;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return mergeJsonSchemas([schema ?? {}, resourceSchema, { properties: { type: { const: type, type: 'string' } } }]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
await $.spawn('rm -rf ./dist')
|
|
97
|
+
await $.spawn('npm run rollup', { interactive: true }); // re-run rollup without building for es
|
|
98
|
+
|
|
99
|
+
console.log('Generated JSON Schemas for all resources')
|
|
100
|
+
|
|
101
|
+
const distFolder = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'dist');
|
|
102
|
+
const schemaOutputPath = path.resolve(distFolder, 'schemas.json');
|
|
103
|
+
fs.writeFileSync(schemaOutputPath, JSON.stringify(mergedSchemas, null, 2));
|
|
104
|
+
|
|
105
|
+
console.log('Successfully wrote schema to ./dist/schemas.json')
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
plugin.kill(9);
|
|
109
|
+
process.exit(0);
|
|
110
|
+
|
|
111
|
+
async function loadReadmes(){
|
|
112
|
+
const readmes = new Map();
|
|
113
|
+
}
|
package/dist/bin/build.js
CHANGED
|
File without changes
|
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-beta49",
|
|
4
4
|
"description": "Library plugin library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"prepublishOnly": "tsc"
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
14
|
-
"codify-build": "
|
|
14
|
+
"codify-build": "./bin/build.js"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [],
|
|
17
17
|
"author": "",
|
package/bin/build.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log('HI');
|