MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / generate

Function generate

packages/cli/src/plugins/typescript.ts:9–48  ·  view source on GitHub ↗
({ model, defaultOutputPath, pluginOptions })

Source from the content-addressed store, hash-verified

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
51export default plugin;

Callers

nothing calls this directly

Calls 3

resolveMethod · 0.80
generateMethod · 0.65

Tested by

no test coverage detected