@benrasha/nest-generator
v1.1.2
Published
NestJS CLI util for generating project from the templates
Readme
nest-generator
A CLI tool that scaffolds NestJS projects from configurable Git-based templates. Choose a template, and the generator clones it, copies files into your current directory, and runs npm install.
Table of contents
Installation
Global install (recommended)
npm install -g @benrasha/nest-generatorThen run from any directory:
nest-generatorRun without installing (npx)
npx @benrasha/nest-generatorOr run the generate command explicitly:
npx @benrasha/nest-generator generateFrom source
git clone https://github.com/ivvan-grishchenko/nestjs-generator.git
cd nestjs-generator
npm ci
npm run build
node dist/main.js
# or link globally: npm linkUsage
Commands
| Command | Alias | Description |
| ----------- | ----- | ------------------------------ |
| generate | gen | Generate project from a template |
Basic flow
Go to the folder where you want the project (can be an empty directory or an existing one; existing files may be overwritten).
mkdir my-app && cd my-appRun the CLI.
nest-generator # or nest-generator generate # or nest-generator genChoose a template from the interactive list (arrow keys + Enter).
The CLI will:
- Clone the template repository (shallow clone, single branch)
- Copy all files into the current directory (excluding
.git) - Run
npm install
When it finishes, you get a ready-to-use project in the current directory.
Example
mkdir my-nest-app
cd my-nest-app
nest-generator
# Select "nestjs-scaffold" (or another template)
# Wait for clone, copy, and npm install
# Start coding
npm run start:devImportant notes
Current directory
The tool always uses the current working directory. It does not create a new subfolder; it writes into.(overwriting existing files when names conflict).Overwrite behavior
Files from the template are copied withoverwrite: true. Existing files in the same paths will be replaced. Use an empty directory if you want a clean scaffold.Network and Git
Cloning requires network access and a reachable template Git URL. The template repo is cloned with--depth=1and a specific branch.npm install
After copying, the CLI runsnpm installin the current directory. Ensure Node.js and npm are available and that you have no lockfile/registry issues.
How it works
- Prompt — You are asked to select a template from a list (names come from the built-in template config).
- Clone — The template repo is cloned into a temporary directory (
.temp-template-clone) with a shallow clone of the configured branch. - Copy — All files from that temp directory are copied into
process.cwd(), excluding.git. - Install —
npm installis executed in the current directory. - Cleanup — The temporary directory is removed. On failure, cleanup is still attempted.
The temporary directory is created under the current working directory and is removed when the command exits (success or failure).
Available templates
Templates are defined in the CLI and point to Git repositories and branches.
| Template ID | Description | Repository |
| ----------------- | --------------------- | ---------- |
| nestjs-scaffold | Basic NestJS scaffold | nestjs-scaffold |
More templates can be added in future releases. The list is fixed at runtime (no config file for end users).
Requirements
- Node.js — Compatible with the version used by the template (e.g. LTS). The project uses Node 24 in development (see
.nvmrc). - npm — Used to run
npm installafter copying files. - Git — Used internally to clone template repositories.
- Network — Required to clone the template and install dependencies.
Development
Setup
git clone https://github.com/ivvan-grishchenko/nestjs-generator.git
cd nestjs-generator
npm ciScripts
| Script | Description |
| ---------------- | ------------------------------------ |
| npm run build | Build the CLI (output in dist/) |
| npm run start | Run the built CLI |
| npm run start:dev | Run in watch mode |
| npm run lint | Run ESLint |
| npm run format | Format with Prettier |
| npm run test | Run unit tests (Vitest) |
| npm run test:e2e | Run e2e tests (Vitest) |
| npm run test:cov | Run tests with coverage |
Adding a new template
Templates are defined in src/generate-command/generate.constant.ts. Each entry has:
- Key — Template ID shown in the list (e.g.
nestjs-scaffold). - repo — Git clone URL.
- branch — Branch to clone (e.g.
main). - description — Short description (used in the codebase; the list currently shows template IDs).
Example:
export const TEMPLATES: Record<string, TemplateConfig> = {
'nestjs-scaffold': {
branch: 'main',
description: 'Basic NestJS scaffold',
repo: 'https://github.com/ivvan-grishchenko/nestjs-scaffold.git',
},
'my-new-template': {
branch: 'main',
description: 'My custom NestJS template',
repo: 'https://github.com/username/my-nest-template.git',
},
};After adding a template, rebuild and run the CLI to see it in the list.
Code quality
- ESLint — Linting (including lint-staged on commit).
- Prettier — Formatting.
- Husky — Pre-commit (lint-staged + tests) and commit-msg (Commitlint).
- Commitlint — Conventional commits (e.g.
feat:,fix:).
Commits should follow the configured conventional format so the commit-msg hook passes.
Contributing
- Open an issue or pick an existing one.
- Fork the repo, create a branch, make your changes.
- After installing dependencies, run
npm run post-installonce to apply local-only test patches. - Run
npm run lint,npm run test, andnpm run test:e2e. - Commit using conventional commits (Commitlint is enforced).
- Push and open a pull request.
Bug reports and feature ideas are welcome via GitHub Issues.
