|
| 1 | +import { |
| 2 | + Ajv2020 as Ajv, |
| 3 | +} from 'ajv/dist/2020.js'; |
| 4 | + |
| 5 | +import { |
| 6 | + object_has_non_empty_array_property, |
| 7 | +} from '@satisfactory-dev/predicates.ts'; |
| 8 | + |
| 9 | +import type { |
| 10 | + SchemaObjectWith$id, |
| 11 | +} from '@signpostmarv/json-schema-typescript-codegen'; |
| 12 | +import { |
| 13 | + $ref, |
| 14 | + SchemaParser, |
| 15 | +} from '@signpostmarv/json-schema-typescript-codegen'; |
| 16 | + |
| 17 | +import { |
| 18 | + configure_parser, |
| 19 | +} from './src/version-specific/0.8.3.3/SchemaParser.ts'; |
| 20 | + |
| 21 | +import update8_properties from './schema/0.8.3.3/properties.json' with { |
| 22 | + type: 'json', |
| 23 | +}; |
| 24 | + |
| 25 | +import update8_classes__base from './schema/0.8.3.3/base-classes.json' with { |
| 26 | + type: 'json', |
| 27 | +}; |
| 28 | + |
| 29 | +import update8_classes from './schema/0.8.3.3/classes.json' with { |
| 30 | + type: 'json', |
| 31 | +}; |
| 32 | + |
| 33 | +import update8 from './schema/0.8.3.3/docs.json' with { |
| 34 | + type: 'json', |
| 35 | +}; |
| 36 | + |
| 37 | +import update8_data from './data/0.8.3.3/Docs/Docs.utf8.json' with { |
| 38 | + type: 'json', |
| 39 | +}; |
| 40 | + |
| 41 | +import { |
| 42 | + FilenameAdjuster, |
| 43 | +} from './src/FilenameAdjuster.ts'; |
| 44 | + |
| 45 | +import type { |
| 46 | + processed_results, |
| 47 | +} from './src/printer-factory.ts'; |
| 48 | +import { |
| 49 | + get_results, |
| 50 | + handle_results, |
| 51 | + printer_factory, |
| 52 | +} from './src/printer-factory.ts'; |
| 53 | + |
| 54 | +import { |
| 55 | + filenames_by_$id, |
| 56 | +} from './src/version-specific/0.8.3.3/filenames.ts'; |
| 57 | + |
| 58 | +console.log('Generating Update 8'); |
| 59 | + |
| 60 | +const ajv = new Ajv({strict: true, verbose: true}); |
| 61 | + |
| 62 | +const parser = new SchemaParser({ajv}); |
| 63 | + |
| 64 | +configure_parser(parser); |
| 65 | + |
| 66 | +const $ref_instance = parser.types.find( |
| 67 | + (maybe) => maybe instanceof $ref, |
| 68 | +); |
| 69 | + |
| 70 | +if (undefined === $ref_instance) { |
| 71 | + throw new TypeError('Could not find $ref instance!'); |
| 72 | +} |
| 73 | + |
| 74 | +const adjuster = new FilenameAdjuster( |
| 75 | + filenames_by_$id, |
| 76 | + 'docs.json.ts--common--types', |
| 77 | +); |
| 78 | + |
| 79 | +async function* get_results_from_data_schema( |
| 80 | + schema: SchemaObjectWith$id, |
| 81 | + adjuster: FilenameAdjuster, |
| 82 | +) { |
| 83 | + adjuster.current_id = schema.$id; |
| 84 | + |
| 85 | + const printer = printer_factory(adjuster); |
| 86 | + |
| 87 | + let data: unknown = undefined; |
| 88 | + |
| 89 | + switch (schema.$id) { |
| 90 | + case 'docs.json.ts--0.8.3.3': |
| 91 | + data = update8_data; |
| 92 | + break; |
| 93 | + } |
| 94 | + |
| 95 | + if (undefined === data) { |
| 96 | + throw new TypeError(`No data specified for ${schema.$id}`); |
| 97 | + } else if (!Array.isArray(data)) { |
| 98 | + throw new TypeError( |
| 99 | + `Data was not in expected format for ${schema.$id}`, |
| 100 | + ); |
| 101 | + } else if (!object_has_non_empty_array_property(schema, 'prefixItems')) { |
| 102 | + throw new TypeError( |
| 103 | + `Schema was not in expected format for ${schema.$id}`, |
| 104 | + ); |
| 105 | + } |
| 106 | + |
| 107 | + yield await printer.parse( |
| 108 | + data, |
| 109 | + schema, |
| 110 | + parser, |
| 111 | + ); |
| 112 | +} |
| 113 | + |
| 114 | +const results: processed_results = []; |
| 115 | + |
| 116 | +for (const schema of [ |
| 117 | + update8_properties, |
| 118 | + update8_classes__base, |
| 119 | + update8_classes, |
| 120 | + update8, |
| 121 | +]) { |
| 122 | + console.log(`getting results for ${schema.$id}`); |
| 123 | + |
| 124 | + for await (const schema_results of get_results( |
| 125 | + schema as SchemaObjectWith$id, |
| 126 | + adjuster, |
| 127 | + parser, |
| 128 | + get_results_from_data_schema, |
| 129 | + )) { |
| 130 | + results.push(...schema_results); |
| 131 | + parser.clear_imports(); |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +await handle_results(results); |
0 commit comments