如何使用NX生成OpenAPI JSON?
我有 nestjs 在monorepo和 nx 是我们的构建系统。
我正在寻找一种在构建时间编译和运行TS文件的方法。 TS文件具有生成OpenApi.json文件的逻辑。 TS文件从项目中的main.js和其他文件导入函数。
代码:
const options = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, options);
const outputPath = path.resolve(process.cwd(), 'swagger.json');
writeFileSync(outputPath, JSON.stringify(document), { encoding: 'utf8'});
await app.close();
问题:由于NX生成了一个文件main.js。如何编译和运行我的TS文件?
PS如果我将其放入main.js的bootstrap方法中,则相同的代码可以正常工作,但这是我不想要的。
I am having NestJS projects in a Monorepo and NX is our build system.
I am looking for a way to compile and run a TS file at build time. The TS file has a logic to generate openapi.json file. TS file imports functions from main.js and other files in the project.
Code:
const options = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, options);
const outputPath = path.resolve(process.cwd(), 'swagger.json');
writeFileSync(outputPath, JSON.stringify(document), { encoding: 'utf8'});
await app.close();
Issue: Since the NX generates a single file main.js. How I can compile and run my TS file?
P.S the same code works if I put it in bootstrap method of main.js but that is something I don't want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论