({ model, defaultOutputPath, pluginOptions })
| 7 | name: 'TypeScript Schema Generator', |
| 8 | statusText: 'Generating TypeScript schema', |
| 9 | async generate({ model, defaultOutputPath, pluginOptions }) { |
| 10 | // output path |
| 11 | let outDir = defaultOutputPath; |
| 12 | if (typeof pluginOptions['output'] === 'string') { |
| 13 | outDir = path.resolve(defaultOutputPath, pluginOptions['output']); |
| 14 | if (!fs.existsSync(outDir)) { |
| 15 | fs.mkdirSync(outDir, { recursive: true }); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | // lite mode |
| 20 | const lite = pluginOptions['lite'] === true; |
| 21 | |
| 22 | // liteOnly mode |
| 23 | const liteOnly = pluginOptions['liteOnly'] === true; |
| 24 | |
| 25 | // file extension to append to relative imports; when not explicitly set, |
| 26 | // auto-detect from the project's tsconfig (".js" for node16/nodenext ESM) |
| 27 | let importWithFileExtension = pluginOptions['importWithFileExtension']; |
| 28 | if (importWithFileExtension === undefined) { |
| 29 | importWithFileExtension = detectImportFileExtension(outDir); |
| 30 | } else if (typeof importWithFileExtension !== 'string') { |
| 31 | throw new Error('The "importWithFileExtension" option must be a string if specified.'); |
| 32 | } |
| 33 | |
| 34 | // whether to generate models.ts |
| 35 | const generateModelTypes = pluginOptions['generateModels'] !== false; |
| 36 | |
| 37 | // whether to generate input.ts |
| 38 | const generateInputTypes = pluginOptions['generateInput'] !== false; |
| 39 | |
| 40 | await new TsSchemaGenerator().generate(model, { |
| 41 | outDir, |
| 42 | lite, |
| 43 | liteOnly, |
| 44 | importWithFileExtension: importWithFileExtension as string | undefined, |
| 45 | generateModelTypes, |
| 46 | generateInputTypes, |
| 47 | }); |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | export default plugin; |
nothing calls this directly
no test coverage detected