-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discover-types--1.0.ts
82 lines (77 loc) · 1.9 KB
/
discover-types--1.0.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
71
72
73
74
75
76
77
78
79
80
81
82
import {
TypeDefinitionWriter,
} from './lib/TypeDefinitionWriter';
import {
NoMatchError,
} from './lib/Exceptions';
import {
writeFile,
} from 'node:fs/promises';
import {
__dirname_from_meta,
} from './lib/__dirname';
import {
docs,
} from './lib/helpers';
import {
setup_PerformanceObserver,
} from './setup_PerformanceObserver';
import {
versions,
} from './version-configs';
const __dirname = __dirname_from_meta(import.meta);
const perf = setup_PerformanceObserver();
const version = 'version_1_0_0_4';
const sub_path = versions.version_1_0_0_4;
try {
performance.mark('start');
const bar = new TypeDefinitionWriter(
docs,
version,
);
performance.measure('bootstrap', 'start');
performance.mark('bootstrap done');
await bar.write(`${__dirname}/generated-types/${sub_path}/`);
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(
`${__dirname}/discover-types.${sub_path}.perf.json`,
`${JSON.stringify(perf(), null, '\t')}`,
);
} catch (err) {
await writeFile(
`${__dirname}/discover-types.${sub_path}.perf.json`,
`${JSON.stringify(perf(), null, '\t')}`,
);
if (err instanceof NoMatchError) {
console.error('ran into an issue');
await writeFile(
`./discovery-types.${sub_path}.failure.json`,
JSON.stringify(
{
now: performance.now(),
property: err.property as unknown,
message: err.message,
stack: err.stack?.split('\n'),
},
null,
'\t',
),
);
console.error(err.message, err.stack);
} else {
throw err;
}
}