-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.mjs
63 lines (53 loc) · 1.56 KB
/
generate.mjs
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
54
55
56
57
58
59
60
61
62
63
import * as url from 'node:url';
import { exec } from 'child_process';
import { promisify } from 'util';
/*
//Unable to run programmatically https://github.com/vega/ts-json-schema-generator/issues/1303
function main() {
// @type {import('ts-json-schema-generator/dist/src/Config').Config}
const config = {
path: "./types/NFTCollection.ts",
type: "*", // Or <type-name> if you want to generate schema for that one type only
};
const output_path = "./schemas/schemas.json";
const schema = tsj.createGenerator(config).createSchema(config.type);
const schemaString = JSON.stringify(schema, null, 2);
writeFile(output_path, schemaString, (err) => {
if (err) throw err;
});
}
*/
async function main() {
const schemas = [
'IPFSImageUpload.ts',
'NFTAsset.ts',
'NFTTrait.ts',
'NFTCollection.ts',
'NFTGenerativeTrait/index.ts',
'NFTGenerativeCollection.ts',
];
const promises = schemas.map((schema) => {
const cmd = `./node_modules/.bin/ts-json-schema-generator --path src/types/${schema} > src/schemas/${schema.replace(
'.ts',
'.json',
)}`;
return promisify(exec)(cmd);
});
await Promise.all(promises);
}
//https://2ality.com/2022/07/nodejs-esm-main.html
/*
if (require.main === module) {
// Main CommonJS module
main()
}
*/
if (import.meta.url.startsWith('file:')) {
// (A)
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
// (B)
// Main ESM module
await main();
}
}