Generators
Generators allow you to quickly scaffold boilerplate code for your application.
Instead of manually creating files, you can use the CLI:
npx servercn-cli g <type> <name> [options]Aliases
Options
--force: Overwrite existing files--flat: Generate files in a flat structure-h,--help: display help for command
Available Generators
Controller
npx servercn-cli g co authCreates:
- MVC:
src/controllers/auth.controller.ts - Feature:
src/modules/auth/auth.controller.ts
Examples:
Service
npx servercn-cli g se authCreates:
- MVC:
src/services/auth.controller.ts - Feature:
src/modules/auth/auth.service.ts
Route
npx servercn-cli g ro authCreates:
- MVC:
src/routes/auth.route.ts - Feature:
src/modules/auth/auth.route.ts
Model
npx servercn-cli g mo userCreates:
- MVC:
src/models/user.model.ts - Feature:
src/modules/auth/user.model.ts
DTO
Generate Data Transfer Objects (DTOs) using zod for validation and type inference.
DTOs are used to validate incoming data (e.g. request body, params, query).
npx servercn-cli g dto <name> [fields...] [options]fields:
Define fields using: key:type
npx servercn-cli g dto authnpx servercn-cli g dt user --flatnpx servercn-cli g dt user name:string email:email age:numberCreates:
- MVC:
src/dtos/auth.dto.ts - Feature:
src/modules/auth/auth.dto.ts
Validator
Generate Validators using zod for validation and type inference.
npx servercn-cli g va <name> [fields...] [options]fields:
Define fields using: key:type
npx servercn-cli g va authnpx servercn-cli g va auth --flatnpx servercn-cli g va user name:string email:email age:numberCreates:
- MVC:
src/validators/auth.validator.ts - Feature:
src/modules/auth/auth.validator.ts
Resource
npx servercn-cli g re postCreates:
1. MVC:
-
src/controllers/post.controller.ts -
src/services/post.service.ts -
src/routes/post.route.ts -
src/models/post.model.ts -
src/dtos/post.dto.ts
Example:
2. Feature:
-
src\modules\post\post.controller.ts -
src\modules\post\post.service.ts -
src\modules\post\post.route.ts -
src\modules\post\post.model.ts -
src\modules\post\post.dto.ts
Example:
Help
npx servercn-cli g --helpSummary
npx servercn-cli g co authnpx servercn-cli g se usernpx servercn-cli g mo usernpx servercn-cli g ro authnpx servercn-cli g re postnpx servercn-cli g dt authnpx servercn-cli g va authnpx servercn-cli g --help