forked from OWND-Project/OWND-Project-VCI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-json-schema.js
53 lines (47 loc) · 1.65 KB
/
generate-json-schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { exec } from 'child_process';
const typeNames = [
// IssuerMetadata
"IssuerMetadataJwtVcJsonLd",
"IssuerMetadataJwtVcJson",
"IssuerMetadataLdpVc",
"IssuerMetadataVcSdJwt",
// CredentialRequest
"CredentialRequestVcSdJwt",
"CredentialRequestJwtVcJson",
"CredentialRequestLdpVc",
"CredentialRequestJwtVcJsonLd",
]
const typeDefinitionSrc = "./src/oid4vci/types/protocol.types.ts"
const outputDirectory = "./src/oid4vci/types/protocolSchema"
const execPromise = (cmd) => new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(`Error executing command: ${error}`);
} else if (stderr) {
reject(`stderr from command: ${stderr}`);
} else {
resolve(stdout);
}
});
});
const runCommands = async () => {
try {
for (let index = 0; index < typeNames.length; index++) {
const typeName = typeNames[index];
const outputFilePath = `${outputDirectory}/${typeName}.json`;
const cmd = `yarn typescript-json-schema --strictNullChecks true --noExtraProps true --required ${typeDefinitionSrc} ${typeName} --out ${outputFilePath}`;
try {
console.log(`generation schema for ${typeName}...`);
await execPromise(cmd);
} catch (error) {
console.error(`Error in command ${index + 1}:`, error);
process.exit(1);
}
}
console.log('All commands executed successfully.');
} catch (error) {
console.error('A command failed:', error);
process.exit(1);
}
};
runCommands();