So i have an application on NestJS and Typescript. My goal is to basically extract to a file each controller name, route, and some metadata about it.
@Controller('baseurl')
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('hello')
@MetaData('abc')
getHello(): string {
return this.appService.getHello();
}
@Post('hello')
@MetaData('abc')
getHello(): string {
return this.appService.getHello();
}
}
The output file would be something like this (formatting don't matter, just the data):
[
{
'module': 'AppController',
'controller': 'baseurl',
'route': 'hello',
'method': 'GET',
'medatada': 'abc'
},
{
'module': 'AppController',
'controller': 'baseurl',
'route': 'hello',
'method': 'POST',
'medatada': 'abc'
},
{ ... }
]
Ideally this is done on as a standalone script that i can run on either a githook or as part of the pre-compile process for the actual application. This file is a file that I would use to feed other processes, so it's not part of the runtime of the application itself.
I imagine there is a way to capture this data in a typescript/node sort of way, but I'm really clueless as to what the right process would be (without parsing each file by hand), or what to otherwise google to get on the right track.