@naybala/nest-code-generator
v1.0.2
Published
An interactive CLI tool for scaffolding complete NestJS feature modules. It streamlines the creation of boilerplate code including Controllers, Services, Repositories, DTOs (with Swagger and class-validator), and Response models.
Readme
@naybala/nest-code-generator
An interactive CLI tool for scaffolding complete NestJS feature modules. It streamlines the creation of boilerplate code including Controllers, Services, Repositories, DTOs (with Swagger and class-validator), and Response models.
It also includes interactive prompts to automatically gather entity fields and configure DTOs and Response properties for you.
Installation
You can install the package globally to use it anywhere:
npm install -g @naybala/nest-code-generatorOr you can use it directly via npx without installing:
npx @naybala/nest-code-generatorUsage
Simply run the command in the root directory of your NestJS project:
make-nest-feature(If you installed locally or are running from package scripts, you can also use npm run make:feature if you add it to your package.json)
Interactive Prompts
The CLI will ask you a series of questions to configure your new feature:
- Feature name: The singular PascalCase name of your entity (e.g.,
Product,User,Order). - Add fields: Whether you want to interactively add properties to your entity.
- If yes, you will be prompted to enter the Field name, Field type (string, number, boolean, int, float, text), and whether it is optional.
- Permissions root prefix: A root name for your feature's permission checks (defaults to the lowercase feature name).
Generated Code Structure
The generator will create a new directory inside src/modules/ with the pluralized name of your feature and scaffold the following files:
src/modules/[plural-name]/
├── controller/[plural-name].controller.ts
├── dto/
│ ├── create-[kebab-singular].dto.ts
│ └── update-[kebab-singular].dto.ts
├── repository/[plural-name].repository.ts
├── responses/[kebab-singular].response.ts
├── service/[plural-name].service.ts
└── [plural-name].module.tsAutomatic Post-Generation Guidance
After successful generation, the CLI will output clear "Next Steps" providing the exact Prisma schema definition (based on the fields you collected) and the import statement needed to register your new module in your application.
Features
- Interactive CLI: Easy-to-use prompts powered by
inquirer. - Automatic DTO Validation: Automatically generates class-validator decorators (
@IsString,@IsNumber,@IsOptional, etc.) based on your field types. - Swagger Integration: Automatically includes
@ApiProperty()decorators in DTOs and Response objects. - Naming Conventions: Automatically handles pluralization, camelCase, PascalCase, and kebab-case conversions to keep your codebase consistent.
- Prisma Ready: Provides the exact schema snippets required to update your database.
