tamim-cli
Version:
A CLI tool for generating module boilerplate code including routes, controllers, services, and more
232 lines (178 loc) ⢠5.68 kB
Markdown
# Tamim CLI
A powerful CLI tool for generating TypeScript-based module boilerplate code with MongoDB and Express.js integration. Created by Ashiqur Rahman Tamim.
## Features
- š Instantly generate complete module structure
- š Creates all necessary files (routes, controllers, services, models, etc.)
- š Automatic Postman collection generation
- š TypeScript support out of the box
- šļø MongoDB model generation
- š£ļø Express.js route setup
- ⨠Built-in validation templates
- š¦ File upload handling support
## Installation
```bash
npm install -g tamim-cli
```
## Usage
### Create a New Project
```bash
tamim create-new-app
```
It will ask about the name of the app and the package manager you want to use once you answer those it will create a folder structure like this
```
āāā node_modules
āāā src
ā āāā app
ā ā āāā middlewares
ā ā ā āāā auth.ts
ā ā ā āāā fileUploadHandler.ts
ā ā ā āāā globalErrorHandler.ts
ā ā ā āāā validateRequest.ts
ā ā āāā modules
ā ā āāā auth
ā ā āāā resetToken
ā ā āāā user
ā āāā app.ts
ā āāā config
ā ā āāā index.ts
ā āāā enums
ā ā āāā user.ts
ā āāā errors
ā ā āāā ApiError.ts
ā ā āāā handleValidationError.ts
ā ā āāā handleZodError.ts
ā āāā helpers
ā ā āāā emailHelper.ts
ā ā āāā jwtHelper.ts
ā ā āāā paginationHelper.ts
ā ā āāā socketHelper.ts
ā āāā routes
ā ā āāā index.ts
ā āāā seed
ā ā āāā seedAdmin.ts
ā āāā server.ts
ā āāā shared
ā ā āāā catchAsync.ts
ā ā āāā constrant.ts
ā ā āāā emailTemplate.ts
ā ā āāā logger.ts
ā ā āāā morgen.ts
ā ā āāā pick.ts
ā ā āāā sendResponse.ts
ā ā āāā unlinkFile.ts
ā āāā types
ā ā āāā auth.ts
ā ā āāā emailTamplate.ts
ā ā āāā email.ts
ā ā āāā errors.types.ts
ā ā āāā index.d.ts
ā ā āāā pagination.ts
ā āāā util
ā āāā cryptoToken.ts
ā āāā generateOTP.ts
āāā tsconfig.json
āāā package.json
āāā README.md
āāā yarn.lock
```
### Create a New Module
```bash
tamim create <module-name> <fields...>
```
Fields should be specified in the format: `fieldName:type`
Supported field types:
- `string`
- `number`
- `date`
- `boolean`
- `array=>string`
- `array=>number`
- `array=>date`
- `array=>boolean`
- `ref=>ModelName` (for MongoDB references)
- `array=>ref=>ModelName` (for array of references)
Example:
```bash
tamim create user name:string email:string age:number profileImage:string isActive:boolean
```
This will create:
- user.route.ts
- user.controller.ts
- user.service.ts
- user.validation.ts
- user.interface.ts
- user.model.ts
Supported file types:
- `route`
- `controller`
- `service`
- `validation`
- `interface`
- `model`
If you add --skip or -s and give the file types you want to skip then it will not create that file
Example:
```bash
tamim create user name:string email:string age:number profileImage:string isActive:boolean --skip route validation
```
This will skip route and validation and just create:
- user.controller.ts
- user.service.ts
- user.interface.ts
- user.model.ts
And there is also a twist if you use `--skip filter` or `-s filter` it will skip the filter and pagination part in the getall function
### Add Files to Existing Module
```bash
tamim add <moduleFiles...>
```
```bash
tamim add user:route
```
This will create:
- user.route.ts
in the user folder
```bash
tamim add user/auth:route
```
This will create:
- auth.route.ts
in the auth folder in the user folder
## Configuration (Optional)
Create a `tamim.config.cjs` file in your project root if you want to add api requests automatically in your postman collection:
```javascript
module.exports = {
config: {
postman_api_key: "your-postman-api-key",
postman_workspace_id: "your-workspace-id",
postman_collection_name: "your-collection-name",
postman_folder_name: "optional-folder-name", // defaults to module name
},
};
```
## Generated Structure
For each module, the following structure is created under `src/app/modules/<module-name>/`:
```
š <module-name>/
āāā <module-name>.route.ts # Express routes
āāā <module-name>.controller.ts # Request handlers
āāā <module-name>.service.ts # Business logic
āāā <module-name>.validation.ts # Request validation
āāā <module-name>.interface.ts # TypeScript interfaces
āāā <module-name>.model.ts # MongoDB model
```
## Postman Integration
If configured, automatically generates Postman collection with:
- Create endpoint (POST)
- Get One endpoint (GET)
- Get All endpoint (GET)
- Update endpoint (PATCH)
- Delete endpoint (DELETE)
## Requirements
- Node.js >= 18.0.0
- TypeScript project setup
- MongoDB for database operations
## Author
**Ashiqur Rahman Tamim**
Email: ashiqurrahmantamim369@gmail.com\
Repo: [https://github.com/Tamim-369/tamim-cli](https://github.com/Tamim-369/tamim-cli)
## License
MIT