@asad_dev/leo-generator 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +194 -0
- package/COMMAND_REFERENCE.md +412 -0
- package/README.md +486 -0
- package/dist/app/modules/imagemodule/imagemodule.constants.js +18 -0
- package/dist/app/modules/imagemodule/imagemodule.controller.js +98 -0
- package/dist/app/modules/imagemodule/imagemodule.interface.js +2 -0
- package/dist/app/modules/imagemodule/imagemodule.model.js +10 -0
- package/dist/app/modules/imagemodule/imagemodule.route.js +20 -0
- package/dist/app/modules/imagemodule/imagemodule.service.js +137 -0
- package/dist/app/modules/imagemodule/imagemodule.validation.js +12 -0
- package/dist/app/modules/skiptest/skiptest.controller.js +81 -0
- package/dist/app/modules/skiptest/skiptest.route.js +19 -0
- package/dist/app/modules/skiptest/skiptest.service.js +129 -0
- package/dist/app/modules/skiptest/skiptest.validation.js +12 -0
- package/dist/app/modules/testmodule/testmodule.constants.js +18 -0
- package/dist/app/modules/testmodule/testmodule.controller.js +81 -0
- package/dist/app/modules/testmodule/testmodule.interface.js +2 -0
- package/dist/app/modules/testmodule/testmodule.model.js +11 -0
- package/dist/app/modules/testmodule/testmodule.route.js +19 -0
- package/dist/app/modules/testmodule/testmodule.service.js +129 -0
- package/dist/app/modules/testmodule/testmodule.validation.js +14 -0
- package/dist/helpers/fileHelper.js +44 -0
- package/dist/index.js +586 -0
- package/dist/templates/constants.template.js +24 -0
- package/dist/templates/controller.template.js +108 -0
- package/dist/templates/route.template.js +68 -0
- package/dist/templates/service.template.js +184 -0
- package/dist/types.js +2 -0
- package/dist/utils/documentationUpdater.js +430 -0
- package/dist/utils/fieldParser.js +163 -0
- package/dist/utils/helperGenerator.js +87 -0
- package/dist/utils/interfaceGenerator.js +158 -0
- package/dist/utils/modelGenerator.js +140 -0
- package/dist/utils/postmanApi.js +113 -0
- package/dist/utils/postmanGenerator.js +283 -0
- package/dist/utils/swaggerGenerator.js +444 -0
- package/dist/utils/validationGenerator.js +170 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Leo Generate will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.6.0] - 2025-12-28
|
|
6
|
+
|
|
7
|
+
### 🌟 New: Asynchronous File Cleanup
|
|
8
|
+
- **Enhanced `removeFile` Helper**: Replaced synchronous cleanup logic with a robust asynchronous implementation using `fs/promises`.
|
|
9
|
+
- **Intelligent Path Normalization**: Automatically strips `/images/` prefixes and handles absolute/relative paths correctly.
|
|
10
|
+
- **Improved Reliability**: Added specific error handling for missing files (`ENOENT`) to prevent process crashes.
|
|
11
|
+
|
|
12
|
+
### 🛡️ Core Improvements
|
|
13
|
+
- **Async Service Templates**: Updated generated service templates to `await` file removal operations, ensuring data consistency.
|
|
14
|
+
- **Environment Detection**: Improved `.env` loading to prioritize Postman API keys and Collection IDs for automated syncing.
|
|
15
|
+
- **Enhanced `--skip` Logic**: Refined file skipping mechanism to allow bypassing any file type (interface, model, constants, etc.) during generation.
|
|
16
|
+
|
|
17
|
+
### 🔧 Fixes
|
|
18
|
+
- **Module Dependency Fix**: Resolved `MODULE_NOT_FOUND` errors by ensuring proper dependency installation and build synchronization.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## [1.5.0] - 2025-12-20
|
|
23
|
+
|
|
24
|
+
### 🚀 Major Feature: Automated Postman Cloud Sync
|
|
25
|
+
|
|
26
|
+
#### Added
|
|
27
|
+
- **Automated Postman Collection Import**: Automatically sync generated API collections to Postman Cloud
|
|
28
|
+
- Configure via `.env`, `package.json`, or CLI flags
|
|
29
|
+
- Supports `POSTMAN_API_KEY` and `POSTMAN_COLLECTION_ID`
|
|
30
|
+
- Seamlessly integrates with existing local file generation
|
|
31
|
+
- **Smart Collection Merging**: Intelligently updates or adds module folders in existing collections
|
|
32
|
+
- **Sequential Processing**: Prevents race conditions when updating multiple modules
|
|
33
|
+
- **Variable Sanitization**: Automatically fixes invalid Postman variable types
|
|
34
|
+
|
|
35
|
+
#### Enhanced
|
|
36
|
+
- **update-docs Command**: Now supports automated Postman Cloud sync
|
|
37
|
+
- Properly detects TypeScript enum definitions and their values
|
|
38
|
+
- Correctly identifies changes to nested object properties
|
|
39
|
+
- Generates accurate Postman pre-request scripts with enum value arrays
|
|
40
|
+
- **Enum Detection**: Enhanced field extraction to recognize TypeScript `enum` types
|
|
41
|
+
- **Error Handling**: Graceful handling of API errors without breaking module generation
|
|
42
|
+
|
|
43
|
+
#### Fixed
|
|
44
|
+
- **Postman API Variable Type Error**: Fixed validation errors caused by invalid variable types
|
|
45
|
+
- **Race Condition**: Fixed concurrent API update conflicts in `update-docs`
|
|
46
|
+
- **Enum Value Detection**: Now properly extracts enum values from interface files
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## [1.4.0] - 2025-12-18
|
|
51
|
+
|
|
52
|
+
### 🚀 Major Enhancements
|
|
53
|
+
- **Enhanced Enum Support**: Now uses TypeScript Enums (`export enum StatusEnum {...}`) instead of string unions, with proper validation using `z.nativeEnum` and Mongoose `Object.values`.
|
|
54
|
+
- **File Removal Support**: Added `--file:true` flag. When used, automatically:
|
|
55
|
+
- Generates a `fileHelper` utility for removing uploaded files.
|
|
56
|
+
- Adds cleanup logic to the delete service to remove associated files (images/media) when a record is deleted.
|
|
57
|
+
- **Smart Postman Scripts**: Pre-request scripts now auto-generate dynamic values for request bodies (e.g., timestamps, random numbers, random enum values), making testing easier.
|
|
58
|
+
- **Nested Schema Fixes**: Improved nested schema generation order to ensure dependencies are defined before use.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## [1.3.1] - 2025-08-07
|
|
63
|
+
|
|
64
|
+
### 🔧 Bug Fixes
|
|
65
|
+
- **CLI Version**: Fixed hardcoded version display in CLI to match package.json version
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## [1.3.0] - 2025-08-06
|
|
70
|
+
|
|
71
|
+
### 🏭 Production-Ready Templates
|
|
72
|
+
|
|
73
|
+
#### Updated Templates to Match Production Patterns
|
|
74
|
+
- **Service Template**: Now includes `JwtPayload user` parameter, proper pagination with `paginationHelper`, advanced search and filtering
|
|
75
|
+
- **Controller Template**: Updated with `req.user!` authentication, file handling for `images/media`, proper request structure
|
|
76
|
+
- **Route Template**: Added comprehensive auth middleware, role-based access control, file upload middleware integration
|
|
77
|
+
- **Constants Template**: Auto-generates filterable and searchable fields based on field types
|
|
78
|
+
- **Interface Template**: Auto-generates `IModuleFilterables` interface for type-safe filtering
|
|
79
|
+
|
|
80
|
+
#### Enhanced Features
|
|
81
|
+
- **Role-Based Access Control**: Routes now include proper auth middleware with USER_ROLES
|
|
82
|
+
- **Advanced Pagination**: Integrated with `paginationHelper.calculatePagination()`
|
|
83
|
+
- **Search & Filter**: Automatic generation of searchable and filterable fields
|
|
84
|
+
- **File Upload Support**: Proper handling of `images` and `media` fields with middleware
|
|
85
|
+
- **Type Safety**: Enhanced interfaces with filter types for better TypeScript support
|
|
86
|
+
|
|
87
|
+
#### Production Patterns
|
|
88
|
+
- **Authentication**: All routes protected with role-based auth middleware
|
|
89
|
+
- **Error Handling**: Enhanced error handling with proper status codes
|
|
90
|
+
- **Validation**: Integrated request validation with Zod schemas
|
|
91
|
+
- **Response Structure**: Consistent API response patterns
|
|
92
|
+
- **Code Organization**: Follows production-grade folder and file structure
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## [1.2.0] - 2025-08-06
|
|
97
|
+
|
|
98
|
+
### 🧠 Enhanced Documentation Intelligence
|
|
99
|
+
|
|
100
|
+
#### Added
|
|
101
|
+
- **Code-Aware Documentation Updates**: System now reads both interface and model files for complete accuracy
|
|
102
|
+
- **Smart Field Extraction**: Enhanced parsing that handles complex nested structures and type mappings
|
|
103
|
+
- **Enum Value Detection**: Automatically extracts actual enum values from Mongoose schemas
|
|
104
|
+
- **Array Type Intelligence**: Generates proper sample data for all array types (string[], number[], boolean[], etc.)
|
|
105
|
+
- **100% Syntax Support**: Now handles every field type the generator can create
|
|
106
|
+
- **Robust Interface Parsing**: Correctly identifies main interfaces vs nested interfaces
|
|
107
|
+
|
|
108
|
+
#### Improved
|
|
109
|
+
- **Postman Collection Generation**: Now generates type-appropriate sample data
|
|
110
|
+
- `scores:array:number` → `"scores": [123]` (was `["sample_scores_item"]`)
|
|
111
|
+
- `flags:array:boolean` → `"flags": [true]` (was `["sample_flags_item"]`)
|
|
112
|
+
- `status:enum[active,inactive]` → `"status": "active"` (was `"status": "sample_status"`)
|
|
113
|
+
- **Swagger Documentation**: Enhanced schema generation with proper type definitions
|
|
114
|
+
- **Field Type Detection**: More accurate mapping of TypeScript types to field definitions
|
|
115
|
+
- **Nested Object Support**: Better handling of complex array-of-object structures
|
|
116
|
+
|
|
117
|
+
#### Fixed
|
|
118
|
+
- **Documentation Sync Issues**: Updates now accurately reflect code changes
|
|
119
|
+
- **Array Type Parsing**: Fixed incorrect sample data generation for typed arrays
|
|
120
|
+
- **Enum Value Extraction**: Now properly extracts enum values from model files
|
|
121
|
+
- **Interface Detection**: Improved logic to find main interface vs helper interfaces
|
|
122
|
+
|
|
123
|
+
### 📊 Technical Improvements
|
|
124
|
+
|
|
125
|
+
#### Enhanced Parsing Logic
|
|
126
|
+
- Improved regex patterns for interface and model file parsing
|
|
127
|
+
- Better handling of multiline field definitions
|
|
128
|
+
- Enhanced type mapping for complex structures
|
|
129
|
+
- Robust error handling and fallback mechanisms
|
|
130
|
+
|
|
131
|
+
#### Sample Data Generation
|
|
132
|
+
- Type-aware sample data for all field types
|
|
133
|
+
- Proper ObjectId string generation for references
|
|
134
|
+
- Realistic enum value selection from actual schema definitions
|
|
135
|
+
- Correct nested object structure preservation
|
|
136
|
+
|
|
137
|
+
### 🔧 Developer Experience
|
|
138
|
+
|
|
139
|
+
#### Better Feedback
|
|
140
|
+
- Detailed logging showing exactly which fields are extracted
|
|
141
|
+
- Clear indication of interface and model file processing
|
|
142
|
+
- Progress reporting during bulk documentation updates
|
|
143
|
+
|
|
144
|
+
#### Reliability
|
|
145
|
+
- More robust parsing that handles edge cases
|
|
146
|
+
- Better error messages for troubleshooting
|
|
147
|
+
- Fallback mechanisms for incomplete type information
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## [1.1.0] - 2025-08-05
|
|
152
|
+
|
|
153
|
+
### 🚀 Major Feature Release
|
|
154
|
+
|
|
155
|
+
#### Added
|
|
156
|
+
- **Complex/Nested Fields Support**: Arrays of objects, nested structures, references
|
|
157
|
+
- **Production-Ready CRUD Operations**: Enhanced controllers and services with pagination
|
|
158
|
+
- **Postman Integration**: Automatic API collection generation
|
|
159
|
+
- **Swagger Integration**: OpenAPI 3.0 documentation generation
|
|
160
|
+
- **Bulk Documentation Updates**: Update docs for all existing modules
|
|
161
|
+
|
|
162
|
+
#### Enhanced
|
|
163
|
+
- **Field Type Support**: Comprehensive support for all data types
|
|
164
|
+
- **CLI Interface**: New command structure with aliases
|
|
165
|
+
- **Error Handling**: Improved error messages and validation
|
|
166
|
+
- **Code Generation**: More robust and production-ready templates
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## [1.0.0] - 2025-08-04
|
|
171
|
+
|
|
172
|
+
### 🎉 Initial Release
|
|
173
|
+
|
|
174
|
+
#### Core Features
|
|
175
|
+
- Basic module generation with TypeScript support
|
|
176
|
+
- Mongoose model creation
|
|
177
|
+
- Express controller and service generation
|
|
178
|
+
- RESTful route setup
|
|
179
|
+
- Zod validation schemas
|
|
180
|
+
- Basic field type support
|
|
181
|
+
|
|
182
|
+
#### Supported Field Types
|
|
183
|
+
- Basic types: string, number, boolean, date
|
|
184
|
+
- ObjectId references
|
|
185
|
+
- Simple arrays
|
|
186
|
+
- Basic enum support
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Version Numbering
|
|
191
|
+
|
|
192
|
+
- **Major** (x.0.0): Breaking changes or major new features
|
|
193
|
+
- **Minor** (1.x.0): New features, backward compatible
|
|
194
|
+
- **Patch** (1.1.x): Bug fixes, backward compatible
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
# 📚 Leo Generate - Complete Command Reference
|
|
2
|
+
|
|
3
|
+
## 🚀 **Package Information**
|
|
4
|
+
- **Package Name**: `@asad_dev/leo-generator`
|
|
5
|
+
- **Version**: `1.6.0`
|
|
6
|
+
- **Binary**: `leo-generate`
|
|
7
|
+
|
|
8
|
+
## 📋 **All Available Commands**
|
|
9
|
+
|
|
10
|
+
### **1. Module Generation Commands**
|
|
11
|
+
|
|
12
|
+
#### **Primary Command: `generate` (Recommended)**
|
|
13
|
+
```bash
|
|
14
|
+
leo-generate generate <ModuleName> [field1:type] [field2:type] [...options]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Alias**: `g`
|
|
18
|
+
```bash
|
|
19
|
+
leo-generate g <ModuleName> [field1:type] [field2:type] [...options]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Examples**:
|
|
23
|
+
```bash
|
|
24
|
+
# Basic module
|
|
25
|
+
leo-generate generate User name:string email:string age:number
|
|
26
|
+
|
|
27
|
+
# With alias
|
|
28
|
+
leo-generate g Product name:string price:number
|
|
29
|
+
|
|
30
|
+
# Complex nested structures
|
|
31
|
+
leo-generate generate Order \
|
|
32
|
+
customer:objectid:User \
|
|
33
|
+
items:array:object:name:string:price:number:quantity:number \
|
|
34
|
+
status:enum[pending,processing,shipped,delivered] \
|
|
35
|
+
shippingAddress:object:street:string:city:string:zipCode:string \
|
|
36
|
+
totalAmount:number
|
|
37
|
+
|
|
38
|
+
# With required fields
|
|
39
|
+
leo-generate generate User name!:string email!:string age:number
|
|
40
|
+
|
|
41
|
+
# With optional fields
|
|
42
|
+
leo-generate generate Post title:string content:string author?:string
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### **Legacy Command (Backward Compatibility)**
|
|
46
|
+
```bash
|
|
47
|
+
leo-generate <ModuleName> [field1:type] [field2:type] [...options]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Examples**:
|
|
51
|
+
```bash
|
|
52
|
+
# Legacy syntax (still works)
|
|
53
|
+
leo-generate User name:string email:string age:number
|
|
54
|
+
leo-generate Product name:string price:number category:enum[Electronics,Clothing]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### **2. Smart Documentation Update Commands**
|
|
58
|
+
|
|
59
|
+
#### **Intelligent Documentation Updates**
|
|
60
|
+
```bash
|
|
61
|
+
leo-generate update-docs [options]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Alias**: `docs`
|
|
65
|
+
```bash
|
|
66
|
+
leo-generate docs [options]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Enhanced Features (v1.2.0)**:
|
|
70
|
+
- 🧠 **Code-Aware Analysis**: Reads both interface and model files
|
|
71
|
+
- 🔍 **Smart Field Extraction**: Handles complex nested structures
|
|
72
|
+
- 📊 **Accurate Sample Data**: Type-appropriate values for all field types
|
|
73
|
+
- 🎯 **Enum Value Detection**: Uses actual enum values from schemas
|
|
74
|
+
- ✅ **100% Syntax Support**: Handles every field type the generator creates
|
|
75
|
+
|
|
76
|
+
**Examples**:
|
|
77
|
+
```bash
|
|
78
|
+
# Update both Postman and Swagger for all modules
|
|
79
|
+
leo-generate update-docs
|
|
80
|
+
|
|
81
|
+
# Using alias
|
|
82
|
+
leo-generate docs
|
|
83
|
+
|
|
84
|
+
# Update only Postman collections
|
|
85
|
+
leo-generate update-docs --no-swagger
|
|
86
|
+
|
|
87
|
+
# Update only Swagger documentation
|
|
88
|
+
leo-generate update-docs --no-postman
|
|
89
|
+
|
|
90
|
+
# Custom directories
|
|
91
|
+
leo-generate update-docs \
|
|
92
|
+
--modules-dir src/modules \
|
|
93
|
+
--postman-dir api-collections \
|
|
94
|
+
--swagger-file docs/api-spec.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### **3. Help and Version Commands**
|
|
98
|
+
|
|
99
|
+
#### **Help**
|
|
100
|
+
```bash
|
|
101
|
+
leo-generate --help
|
|
102
|
+
leo-generate generate --help
|
|
103
|
+
leo-generate update-docs --help
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### **Version**
|
|
107
|
+
```bash
|
|
108
|
+
leo-generate --version
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## ⚙️ **Command Options**
|
|
112
|
+
|
|
113
|
+
### **Generate Command Options**
|
|
114
|
+
|
|
115
|
+
| Option | Description | Default | Example |
|
|
116
|
+
|--------|-------------|---------|---------|
|
|
117
|
+
| `-c, --config <path>` | Path to custom config file | - | `--config ./custom-config.json` |
|
|
118
|
+
| `--modules-dir <path>` | Path to modules directory | `src/app/modules` | `--modules-dir src/modules` |
|
|
119
|
+
| `--routes-file <path>` | Path to routes file | `src/routes/index.ts` | `--routes-file src/routes.ts` |
|
|
120
|
+
| `--no-postman` | Skip Postman collection generation | false | `--no-postman` |
|
|
121
|
+
| `--no-swagger` | Skip Swagger documentation generation | false | `--no-swagger` |
|
|
122
|
+
| `--postman-dir <path>` | Custom Postman output directory | `postman` | `--postman-dir collections` |
|
|
123
|
+
| `--swagger-file <path>` | Custom Swagger file path | `swagger.json` | `--swagger-file api-docs.json` |
|
|
124
|
+
| `--file:true` | Enable file upload support (async cleanup) | false | `--file:true` |
|
|
125
|
+
| `--skip <files...>` | Skip specific file types | - | `--skip interface model constants` |
|
|
126
|
+
|
|
127
|
+
### **Update-Docs Command Options**
|
|
128
|
+
|
|
129
|
+
| Option | Description | Default | Example |
|
|
130
|
+
|--------|-------------|---------|---------|
|
|
131
|
+
| `--modules-dir <path>` | Path to modules directory | `src/app/modules` | `--modules-dir src/modules` |
|
|
132
|
+
| `--no-postman` | Skip Postman collection generation | false | `--no-postman` |
|
|
133
|
+
| `--no-swagger` | Skip Swagger documentation generation | false | `--no-swagger` |
|
|
134
|
+
| `--postman-dir <path>` | Custom Postman output directory | `postman` | `--postman-dir collections` |
|
|
135
|
+
| `--swagger-file <path>` | Custom Swagger file path | `swagger.json` | `--swagger-file api-spec.json` |
|
|
136
|
+
|
|
137
|
+
## 🏗️ **Field Type Syntax**
|
|
138
|
+
|
|
139
|
+
### **Basic Types**
|
|
140
|
+
```bash
|
|
141
|
+
name:string # String field
|
|
142
|
+
age:number # Number field
|
|
143
|
+
isActive:boolean # Boolean field
|
|
144
|
+
createdAt:date # Date field
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### **Field Modifiers**
|
|
148
|
+
```bash
|
|
149
|
+
name!:string # Required field (!)
|
|
150
|
+
email?:string # Optional field (?)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### **Enum Fields**
|
|
154
|
+
```bash
|
|
155
|
+
status:enum[active,inactive,pending]
|
|
156
|
+
role:enum[admin,user,moderator]
|
|
157
|
+
category:enum[Electronics,Clothing,Books,Home]
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### **Reference Fields**
|
|
161
|
+
```bash
|
|
162
|
+
author:objectid:User # Single ObjectId reference
|
|
163
|
+
categories:array:objectid:Category # Array of ObjectId references
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### **Complex Nested Structures**
|
|
167
|
+
|
|
168
|
+
#### **Array of Objects**
|
|
169
|
+
```bash
|
|
170
|
+
items:array:object:name:string:price:number:quantity:number
|
|
171
|
+
variants:array:object:size:string:color:string:stock:number
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### **Nested Objects**
|
|
175
|
+
```bash
|
|
176
|
+
address:object:street:string:city:string:country:string:zipCode:string
|
|
177
|
+
profile:object:firstName:string:lastName:string:bio:string
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### **Mixed Arrays**
|
|
181
|
+
```bash
|
|
182
|
+
tags:array:string # Array of strings
|
|
183
|
+
scores:array:number # Array of numbers
|
|
184
|
+
flags:array:boolean # Array of booleans
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## 📁 **Generated File Structure**
|
|
188
|
+
|
|
189
|
+
### **Module Files Created**
|
|
190
|
+
```
|
|
191
|
+
src/app/modules/{modulename}/
|
|
192
|
+
├── {modulename}.interface.ts # TypeScript interfaces
|
|
193
|
+
├── {modulename}.model.ts # Mongoose schema
|
|
194
|
+
├── {modulename}.controller.ts # Express controllers
|
|
195
|
+
├── {modulename}.service.ts # Business logic
|
|
196
|
+
├── {modulename}.route.ts # Express routes
|
|
197
|
+
├── {modulename}.validation.ts # Zod validation
|
|
198
|
+
└── {modulename}.constants.ts # Constants
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### **Documentation Files Created**
|
|
202
|
+
```
|
|
203
|
+
postman/
|
|
204
|
+
└── {modulename}.postman_collection.json # Postman collection
|
|
205
|
+
|
|
206
|
+
swagger.json # OpenAPI 3.0 specification
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### **Updated Files**
|
|
210
|
+
```
|
|
211
|
+
src/routes/index.ts # Auto-updated with new routes
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## 🎯 **Complete Usage Examples**
|
|
215
|
+
|
|
216
|
+
### **E-commerce System**
|
|
217
|
+
|
|
218
|
+
#### **User Module**
|
|
219
|
+
```bash
|
|
220
|
+
leo-generate generate User \
|
|
221
|
+
name!:string \
|
|
222
|
+
email!:string \
|
|
223
|
+
password!:string \
|
|
224
|
+
role:enum[admin,user,customer] \
|
|
225
|
+
profile:object:firstName:string:lastName:string:phone:string \
|
|
226
|
+
isActive:boolean \
|
|
227
|
+
lastLogin?:date
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### **Product Module**
|
|
231
|
+
```bash
|
|
232
|
+
leo-generate generate Product \
|
|
233
|
+
name!:string \
|
|
234
|
+
description:string \
|
|
235
|
+
price!:number \
|
|
236
|
+
category:enum[Electronics,Clothing,Books,Home] \
|
|
237
|
+
variants:array:object:size:string:color:string:price:number:stock:number \
|
|
238
|
+
images:array:string \
|
|
239
|
+
tags:array:string \
|
|
240
|
+
isActive:boolean \
|
|
241
|
+
vendor:objectid:User
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
#### **Order Module**
|
|
245
|
+
```bash
|
|
246
|
+
leo-generate generate Order \
|
|
247
|
+
customer:objectid:User \
|
|
248
|
+
items:array:object:productId:objectid:Product:quantity:number:price:number \
|
|
249
|
+
status:enum[pending,processing,shipped,delivered,cancelled] \
|
|
250
|
+
shippingAddress:object:street:string:city:string:state:string:zipCode:string:country:string \
|
|
251
|
+
billingAddress:object:street:string:city:string:state:string:zipCode:string:country:string \
|
|
252
|
+
totalAmount!:number \
|
|
253
|
+
paymentStatus:enum[pending,paid,failed,refunded] \
|
|
254
|
+
orderDate:date \
|
|
255
|
+
deliveryDate?:date
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### **Blog System**
|
|
259
|
+
|
|
260
|
+
#### **Post Module**
|
|
261
|
+
```bash
|
|
262
|
+
leo-generate generate Post \
|
|
263
|
+
title!:string \
|
|
264
|
+
content!:string \
|
|
265
|
+
excerpt:string \
|
|
266
|
+
author:objectid:User \
|
|
267
|
+
category:objectid:Category \
|
|
268
|
+
tags:array:string \
|
|
269
|
+
status:enum[draft,published,archived] \
|
|
270
|
+
publishedAt?:date \
|
|
271
|
+
viewCount:number \
|
|
272
|
+
likes:array:objectid:User \
|
|
273
|
+
comments:array:object:author:objectid:User:content:string:createdAt:date
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### **Category Module**
|
|
277
|
+
```bash
|
|
278
|
+
leo-generate generate Category \
|
|
279
|
+
name!:string \
|
|
280
|
+
slug!:string \
|
|
281
|
+
description:string \
|
|
282
|
+
parent?:objectid:Category \
|
|
283
|
+
isActive:boolean
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### **File Upload Module**
|
|
287
|
+
```bash
|
|
288
|
+
leo-generate generate Media \
|
|
289
|
+
title:string \
|
|
290
|
+
description:string \
|
|
291
|
+
filename!:string \
|
|
292
|
+
originalName:string \
|
|
293
|
+
mimeType:string \
|
|
294
|
+
size:number \
|
|
295
|
+
path:string \
|
|
296
|
+
uploadedBy:objectid:User \
|
|
297
|
+
isPublic:boolean
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## 🔄 **Workflow Commands**
|
|
301
|
+
|
|
302
|
+
### **Development Workflow**
|
|
303
|
+
```bash
|
|
304
|
+
# 1. Generate new module
|
|
305
|
+
leo-generate generate User name:string email:string
|
|
306
|
+
|
|
307
|
+
# 2. Update documentation after code changes
|
|
308
|
+
leo-generate update-docs
|
|
309
|
+
|
|
310
|
+
# 3. Generate another module
|
|
311
|
+
leo-generate generate Product name:string price:number
|
|
312
|
+
|
|
313
|
+
# 4. Update all documentation
|
|
314
|
+
leo-generate docs
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### **Team Workflow**
|
|
318
|
+
```bash
|
|
319
|
+
# Team member 1: Creates user module
|
|
320
|
+
leo-generate generate User name:string email:string role:enum[admin,user]
|
|
321
|
+
|
|
322
|
+
# Team member 2: Creates product module
|
|
323
|
+
leo-generate generate Product name:string price:number category:string
|
|
324
|
+
|
|
325
|
+
# Team lead: Updates all documentation
|
|
326
|
+
leo-generate update-docs --postman-dir team-collections
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### **CI/CD Integration**
|
|
330
|
+
```bash
|
|
331
|
+
# In CI/CD pipeline
|
|
332
|
+
leo-generate update-docs --no-postman # Only update Swagger for API docs
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## 🛠️ **Configuration Options**
|
|
336
|
+
|
|
337
|
+
### **Via package.json**
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"moduleGenerator": {
|
|
341
|
+
"modulesDir": "src/app/modules",
|
|
342
|
+
"routesFile": "src/routes/index.ts"
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### **Via CLI Options**
|
|
348
|
+
```bash
|
|
349
|
+
leo-generate generate User name:string \
|
|
350
|
+
--modules-dir src/modules \
|
|
351
|
+
--routes-file src/routes.ts \
|
|
352
|
+
--postman-dir collections \
|
|
353
|
+
--swagger-file docs/api.json
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## 🚨 **Skip File Generation**
|
|
357
|
+
|
|
358
|
+
### **Skip Specific Files**
|
|
359
|
+
```bash
|
|
360
|
+
# Skip specific file types during generation
|
|
361
|
+
leo-generate generate User name:string email:string --skip controller service
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### **Skip Documentation**
|
|
365
|
+
```bash
|
|
366
|
+
# Skip Postman collection generation
|
|
367
|
+
leo-generate generate User name:string --no-postman
|
|
368
|
+
|
|
369
|
+
# Skip Swagger documentation generation
|
|
370
|
+
leo-generate generate User name:string --no-swagger
|
|
371
|
+
|
|
372
|
+
# Skip both
|
|
373
|
+
leo-generate generate User name:string --no-postman --no-swagger
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## 📊 **Command Summary**
|
|
377
|
+
|
|
378
|
+
| Command | Purpose | Output |
|
|
379
|
+
|---------|---------|--------|
|
|
380
|
+
| `generate <name> [fields...]` | Create new module with documentation | Module files + Postman + Swagger |
|
|
381
|
+
| `g <name> [fields...]` | Alias for generate | Same as generate |
|
|
382
|
+
| `<name> [fields...]` | Legacy syntax | Same as generate |
|
|
383
|
+
| `update-docs` | Update all module documentation | Updated Postman + Swagger |
|
|
384
|
+
| `docs` | Alias for update-docs | Same as update-docs |
|
|
385
|
+
| `--help` | Show help information | Help text |
|
|
386
|
+
| `--version` | Show version information | Version number |
|
|
387
|
+
|
|
388
|
+
## 🎉 **Quick Start Commands**
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
# Install globally
|
|
392
|
+
npm install -g @asad_dev/leo-generator
|
|
393
|
+
|
|
394
|
+
# Generate your first module
|
|
395
|
+
leo-generate generate User name:string email:string age:number
|
|
396
|
+
|
|
397
|
+
# Check what was created
|
|
398
|
+
ls src/app/modules/user/
|
|
399
|
+
ls postman/
|
|
400
|
+
cat swagger.json
|
|
401
|
+
|
|
402
|
+
# Update documentation
|
|
403
|
+
leo-generate update-docs
|
|
404
|
+
|
|
405
|
+
# Generate complex module
|
|
406
|
+
leo-generate generate Order \
|
|
407
|
+
customer:objectid:User \
|
|
408
|
+
items:array:object:name:string:price:number \
|
|
409
|
+
status:enum[pending,shipped]
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
This comprehensive command reference covers all the functionality available in your enhanced Leo Generate package! 🚀
|