gmt-lazynest
v1.5.0
Published
A CLI tool for generating NestJS modules, controllers, services, and entities with interactive prompts
Maintainers
Readme
LazyNest
A powerful CLI tool for generating NestJS modules, controllers, services, and entities with interactive prompts. LazyNest helps you scaffold NestJS applications quickly and efficiently.
Features
- 🚀 Interactive CLI: User-friendly prompts for generating modules
- 📁 Module Generator: Complete module structure with controller, service, repository, DTOs, and entities
- 🏗️ Project Initialization: Set up common NestJS project structure
- 🎯 TypeORM Integration: Built-in support for TypeORM entities and repositories
- � Git Hooks: Pre-configured Husky hooks for code quality (lint, format, commit validation)
- 📝 Template-based: Consistent code generation using predefined templates
- 🎨 Conventional Commits: Enforce commit message standards with commitlint
- 🔧 Customizable: Flexible attribute types and configurations
- 📦 Node Version Management: Automatic .nvmrc generation for consistent Node versions
Installation
Install globally using npm:
npm install -g gmt-lazynestOr using pnpm:
pnpm add -g gmt-lazynestUsage
Initialize a new project
lzn initThis command will:
- Set up common NestJS project structure (common, config, database folders)
- Configure TypeORM integration
- Generate base classes and utilities
- Create Husky git hooks for code quality:
- Pre-commit hook (lint & format)
- Commit-msg hook (conventional commits validation)
- Pre-push hook (run tests)
- Add
.nvmrcfile for Node version management - Add
commitlint.config.jsfor commit message linting - Add
.lintstagedrc.jsfor staged files linting - Update
package.jsonwith TypeORM migration scripts - Automatically clean and reinstall dependencies using pnpm
The init command will automatically run rm -rf node_modules pnpm-lock.yaml && pnpm install at the end to ensure all dependencies are properly installed.
Note: Make sure you have
pnpminstalled globally. If not, install it first:npm install -g pnpm
Generate a new module
lzn moduleThis command will generate:
- Module file
- Controller with CRUD endpoints
- Service with business logic
- Repository for database operations
- DTOs for request/response
- Entity with TypeORM decorators
Generated Structure
When you generate a module, LazyNest creates a complete structure:
src/
modules/
your-module/
├── your-module.module.ts
├── your-module.controller.ts
├── your-module.service.ts
├── your-module.repository.ts
├── dto/
│ ├── create-your-module.dto.ts
│ ├── update-your-module.dto.ts
│ ├── filtering-your-module.dto.ts
│ └── response-your-module.dto.ts
├── entities/
│ └── your-module.entity.ts
└── interfaces/
└── your-module.interface.tsExamples
Creating a User Module
$ lzn module
? Enter your module name: User
? Enter your attribute name (user): name
? Select attribute type (user - name): String
? Enter your attribute name (user): email
? Select attribute type (user - email): String
? Enter your attribute name (user): age
? Select attribute type (user - age): Number
? Do you want to add another attribute? NoThis generates a complete user module with name, email, and age attributes.
Check version
lzn versionDisplays the current LazyNest version.
Project Structure After Init
After running lzn init, your project will have:
.
├── .husky/
│ ├── pre-commit # Runs lint & format before commit
│ ├── commit-msg # Validates commit messages
│ └── pre-push # Runs tests before push
├── .nvmrc # Node version specification
├── commitlint.config.js # Commit message linting rules
├── .lintstagedrc.js # Lint-staged configuration
└── src/
├── common/ # Common utilities and base classes
│ ├── bases/ # Base entity, repository, service classes
│ ├── decorators/ # Custom decorators
│ ├── dto/ # Common DTOs (pagination, query params)
│ ├── interfaces/ # Shared interfaces
│ └── swagger/ # Swagger documentation helpers
├── config/ # Configuration module
├── database/ # Database configuration and migrations
├── app.module.ts # Root application module
└── main.ts # Application entry pointRequirements
- Node.js >= 16
- NestJS project
- TypeORM (for database integration)
Development
Local Development Testing
To test LazyNest locally without publishing to npm:
- Build the project:
pnpm (for dependency management) - Install with:
npm install -g pnpmcd /path/to/lazynest npm run build
Run directly:
node dist/src/main.js init # or node dist/src/main.js moduleUsing npm link (optional):
npm link # Then in another project: lzn initUsing npm pack:
npm pack # Install in test project: npm install /path/to/gmt-lazynest-1.x.x.tgz
Publishing Updates
Commit your changes:
git add . git commit -m "feat: your feature description"Update version (choose one):
npm run release:patch # Bug fixes (1.1.3 -> 1.1.4) npm run release:minor # New features (1.1.3 -> 1.2.0) npm run release:major # Breaking changes (1.1.3 -> 2.0.0)Publish to npm:
npm run publish:npmPush to GitHub:
git push --follow-tags origin master
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you find this tool helpful, please consider giving it a ⭐ on GitHub!
Author
Created by Developer Gamatecha
Stay in touch
- Author - Developer Gamatecha
- Website - https://gamatecha.com/
License
Nest is MIT licensed.
lazynest
[Backend]
