|
| 1 | +import { |
| 2 | + TypeDefinitionWriter, |
| 3 | +} from './lib/TypeDefinitionWriter'; |
| 4 | +import { |
| 5 | + NoMatchError, |
| 6 | +} from './lib/Exceptions'; |
| 7 | +import { |
| 8 | + writeFile, |
| 9 | +} from 'node:fs/promises'; |
| 10 | +import { |
| 11 | + __dirname_from_meta, |
| 12 | +} from './lib/__dirname'; |
| 13 | +import { |
| 14 | + docs, |
| 15 | +} from './lib/helpers'; |
| 16 | +import { |
| 17 | + setup_PerformanceObserver, |
| 18 | +} from './setup_PerformanceObserver'; |
| 19 | +import { |
| 20 | + versions, |
| 21 | +} from './version-configs'; |
| 22 | +import { |
| 23 | + ValidationError, |
| 24 | +} from './lib/DocsTsGenerator'; |
| 25 | + |
| 26 | +const __dirname = __dirname_from_meta(import.meta); |
| 27 | + |
| 28 | +const perf = setup_PerformanceObserver(); |
| 29 | + |
| 30 | +const version = 'version_1_1_0_1'; |
| 31 | +const sub_path = versions.version_1_1_0_1; |
| 32 | +try { |
| 33 | + performance.mark('start'); |
| 34 | + const bar = new TypeDefinitionWriter( |
| 35 | + docs, |
| 36 | + version, |
| 37 | + ); |
| 38 | + performance.measure('bootstrap', 'start'); |
| 39 | + performance.mark('bootstrap done'); |
| 40 | + await bar.write(`${__dirname}/generated-types/${sub_path}/`); |
| 41 | + performance.measure('types generated', 'bootstrap done'); |
| 42 | + const discovery = await bar.discovery; |
| 43 | + const result = await discovery.discover_type_$defs(); |
| 44 | + |
| 45 | + process.stdout.write( |
| 46 | + `${ |
| 47 | + JSON.stringify(result.missing_classes, null, '\t') |
| 48 | + }\n`, |
| 49 | + ); |
| 50 | + console.table({ |
| 51 | + 'Found Types': Object.keys(result.found_types).length, |
| 52 | + 'Missing Types': result.missing_types.length, |
| 53 | + 'Found Classes': result.found_classes.length, |
| 54 | + 'Missing Classes': result.missing_classes.length, |
| 55 | + }); |
| 56 | + await writeFile( |
| 57 | + `${__dirname}/discover-types.${sub_path}.perf.json`, |
| 58 | + `${JSON.stringify(perf(), null, '\t')}`, |
| 59 | + ); |
| 60 | +} catch (err) { |
| 61 | + await writeFile( |
| 62 | + `${__dirname}/discover-types.${sub_path}.perf.json`, |
| 63 | + `${JSON.stringify(perf(), null, '\t')}`, |
| 64 | + ); |
| 65 | + if (err instanceof NoMatchError) { |
| 66 | + console.error('ran into an issue'); |
| 67 | + await writeFile( |
| 68 | + `./discovery-types.${sub_path}.failure.json`, |
| 69 | + JSON.stringify( |
| 70 | + { |
| 71 | + now: performance.now(), |
| 72 | + property: err.property as unknown, |
| 73 | + message: err.message, |
| 74 | + stack: err.stack?.split('\n'), |
| 75 | + }, |
| 76 | + null, |
| 77 | + '\t', |
| 78 | + ), |
| 79 | + ); |
| 80 | + |
| 81 | + console.error(err.message, err.stack); |
| 82 | + } else if (err instanceof ValidationError) { |
| 83 | + console.error('ran into a validation issue'); |
| 84 | + await writeFile( |
| 85 | + `./discovery-types.${sub_path}.failure.json`, |
| 86 | + JSON.stringify( |
| 87 | + { |
| 88 | + now: performance.now(), |
| 89 | + message: err.message, |
| 90 | + stack: err.stack?.split('\n'), |
| 91 | + errors: err.errors, |
| 92 | + }, |
| 93 | + null, |
| 94 | + '\t', |
| 95 | + ), |
| 96 | + ); |
| 97 | + |
| 98 | + console.error(err.message, err.stack); |
| 99 | + } else { |
| 100 | + throw err; |
| 101 | + } |
| 102 | +} |
0 commit comments