@betsys-nestjs/schematics
v1.3.0
Published
NestJS CLI Schematics for Code Generation
Downloads
18
Readme
Getting Started With Schematics
This repository contains helper schematics for generating unified structure of NestJS components written in hexagonal architecture and CQRS pattern.
Current Schematics
Component
Generates a new component, prepares modules and nested folders (application, domain, infrastructure, ui)
Running nest g -c @betsys/nestjs-schematics component
for a component named example
will generate the following structure:
└── src/
└── component/
└── example/
├── application/
│ └── example-application.module.ts
├── domain/
│ └── example-domain.module.ts
├── infrastructure/
│ └── example-infrastructure.module.ts
├── ui/
│ ├── http/
│ │ └── example-http.module.ts
│ └── example-ui.module.ts
└── example.module.ts
CQRS
Generates a command or query with a handler.
Running nest g -c @betsys/nestjs-schematics cqrs
for a component named example
will generate the following structure:
└── src/
└── component/
└── example/
└── application/
├── command/
│ ├── example-command.handler.ts
│ └── example-command.ts
└── query/
├── example-query.handler.ts
└── example-query.ts
Usage
To install, simply do:
npm install --save-dev @betsys-nestjs/schematics
Then in the project start generating your code by using the nest-cli.
nest g -c @betsys/nestjs-schematics ${schematic}
That's it! The cli wizard will walk you through the configuration.
Monorepo and nested directories
By default the library works for <project-root>/src/component/<component-name>
directory structure.
If you are using a monorepo, you can specify the root dir by a rooDir
parameter.
└── apps/
└── my-app1/
└── my-app2/
└── src/
└── component/
└── example/
└── application/
├── command/
│ ├── example-command.handler.ts
│ └── example-command.ts
└── query/
├── example-query.handler.ts
└── example-query.ts
nest g -c @betsys/nestjs-schematics ${schematic} --rootDir=apps/my-app2
This command will generate the files in <project-root>/apps/my-app2/src/
directory.