nest-ts-code-gen
v1.0.2
Published
a code generator to generate nest template files and typescript definition files
Downloads
3
Maintainers
Readme
what it is
nest-ts-gen
is a code generator to generate back-end nest template code(controller, service, module) and front-end ts type, see in the demo demo/
requirement
contract/
: write back-end type and controller mapping configuration in the contract folder- setup codeGen in your code: setup mapping, output folder and output file name
mkdir
all your output folder, make sure it exist
notification
nest-ts-gen
will replace controller output file and module output file, and as you know nest.service is not a template file, so the service file will be keep if exist, and only replace service method and related type :)
mapping config
write the key _config
in the mapping config like this:
export default {
_config: {
// specify Controller promised common response type, it should be a generic type, so response type will be generated as CommonRes or CommonRes<SomeDto>
promiseGenericRes: "CommonRes"
},
// controller, service, entity => we name it as model name
model1: {
// method name
getStr: {
// request dto type, you should define it in your contract folder first
req: 'GetStrRequest'
// response dto type, define before you write
res: 'GetStrResponse'
}
},
model2: {
_config: {
// stop to generate controller file
disableController: true,
// stop to generate entity (in service imports and module imports)
disableEntity: true
}
getStr: {
// if you don't write req and res, default req: any and res: _config.promiseGenericRes will be generated
}
}
and see props in the file src/type/global.ts