-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-common-types.ts
70 lines (67 loc) · 1.55 KB
/
generate-common-types.ts
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
64
65
66
67
68
69
70
import {
TypeDefinitionWriter,
} from './lib/TypeDefinitionWriter';
import {
NoMatchError,
} from './lib/Exceptions';
import {
writeFile,
} from 'node:fs/promises';
import {
docs,
} from './lib/helpers';
try {
performance.mark('start');
const bar = new TypeDefinitionWriter(
docs,
'common',
);
performance.measure('bootstrap', 'start');
performance.mark('bootstrap done');
await bar.write(`${import.meta.dirname}/generated-types/common/`);
performance.measure('types generated', 'bootstrap done');
const discovery = await bar.discovery;
const result = await discovery.discover_type_$defs();
process.stdout.write(
`${
JSON.stringify(result.missing_classes, null, '\t')
}\n`,
);
console.table({
'Found Types': Object.keys(result.found_types).length,
'Missing Types': result.missing_types.length,
'Found Classes': result.found_classes.length,
'Missing Classes': result.missing_classes.length,
});
/*
await writeFile(
`${import.meta.dirname}/discover-types.common.perf.json`,
`${JSON.stringify(perf(), null, '\t')}`,
);
*/
} catch (err) {
/*
await writeFile(
`${import.meta.dirname}/discover-types.common.perf.json`,
`${JSON.stringify(perf(), null, '\t')}`,
);
*/
if (err instanceof NoMatchError) {
console.error('ran into an issue');
await writeFile(
`./discovery-types.common.failure.json`,
JSON.stringify(
{
property: err.property as unknown,
message: err.message,
stack: err.stack?.split('\n'),
},
null,
'\t',
),
);
console.error(err.message, err.stack);
} else {
throw err;
}
}