@mikemajesty/microservice-crud 6.1.21 → 7.1.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.
Files changed (55) hide show
  1. package/.github/workflows/release.yml +92 -0
  2. package/README.md +306 -0
  3. package/bin/microservice-crud +3 -2
  4. package/package.json +10 -6
  5. package/src/{cli.js → cli.mjs} +150 -112
  6. package/src/templates/core/entity/entity.mjs +35 -0
  7. package/src/templates/core/repository/{repository.js → repository.mjs} +2 -2
  8. package/src/templates/core/use-cases/__tests__/create.spec.mjs +75 -0
  9. package/src/templates/core/use-cases/__tests__/{delete.spec.js → delete.spec.mjs} +25 -23
  10. package/src/templates/core/use-cases/__tests__/{get-by-id.spec.js → get-by-id.spec.mjs} +22 -22
  11. package/src/templates/core/use-cases/__tests__/list.spec.mjs +88 -0
  12. package/src/templates/core/use-cases/__tests__/{update.spec.js → update.spec.mjs} +31 -30
  13. package/src/templates/core/use-cases/create.mjs +35 -0
  14. package/src/templates/core/use-cases/{delete.js → delete.mjs} +12 -13
  15. package/src/templates/core/use-cases/{get-by-id.js → get-by-id.mjs} +7 -8
  16. package/src/templates/core/use-cases/{list.js → list.mjs} +5 -6
  17. package/src/templates/core/use-cases/{update.js → update.mjs} +10 -13
  18. package/src/templates/core-sigle/entity/entity.mjs +35 -0
  19. package/src/templates/core-sigle/repository/{repository.js → repository.mjs} +2 -2
  20. package/src/templates/core-sigle/use-cases/{usecase.js → usecase.mjs} +6 -7
  21. package/src/templates/infra/{adapter.js → adapter.mjs} +2 -2
  22. package/src/templates/infra/{index.js → index.mjs} +1 -2
  23. package/src/templates/infra/{module.js → module.mjs} +2 -2
  24. package/src/templates/infra/{service.js → service.mjs} +5 -5
  25. package/src/templates/libs/{adapter.js → adapter.mjs} +2 -4
  26. package/src/templates/libs/{index.js → index.mjs} +1 -1
  27. package/src/templates/libs/{module.js → module.mjs} +3 -3
  28. package/src/templates/libs/{service.js → service.mjs} +5 -5
  29. package/src/templates/module/{controller.js → controller.mjs} +3 -3
  30. package/src/templates/module/{module.js → module.mjs} +2 -2
  31. package/src/templates/mongo/modules/{adapter.js → adapter.mjs} +6 -6
  32. package/src/templates/{postgres/modules/controller.js → mongo/modules/controller.mjs} +22 -22
  33. package/src/templates/mongo/modules/{module.js → module.mjs} +20 -28
  34. package/src/templates/mongo/modules/{repository.js → repository.mjs} +15 -10
  35. package/src/templates/mongo/schemas/{schema.js → schema.mjs} +8 -6
  36. package/src/templates/postgres/modules/{adapter.js → adapter.mjs} +2 -2
  37. package/src/templates/{mongo/modules/controller.js → postgres/modules/controller.mjs} +27 -27
  38. package/src/templates/postgres/modules/{module.js → module.mjs} +12 -5
  39. package/src/templates/postgres/modules/{repository.js → repository.mjs} +4 -4
  40. package/src/templates/postgres/schemas/{schema.js → schema.mjs} +3 -3
  41. package/infra.README.md +0 -24
  42. package/lib.README.md +0 -24
  43. package/module.README.md +0 -24
  44. package/mongo.README.md +0 -30
  45. package/postgres.README.md +0 -30
  46. package/src/scafold/docs/.gitkeep +0 -0
  47. package/src/templates/core/entity/entity.js +0 -35
  48. package/src/templates/core/use-cases/__tests__/create.spec.js +0 -68
  49. package/src/templates/core/use-cases/__tests__/list.spec.js +0 -83
  50. package/src/templates/core/use-cases/create.js +0 -42
  51. package/src/templates/core-sigle/entity/entity.js +0 -35
  52. package/src/templates/docs/controller.js +0 -72
  53. package/src/templates/docs/exception.js +0 -75
  54. package/src/templates/docs/model.js +0 -79
  55. /package/src/{textUtils.js → textUtils.mjs} +0 -0
@@ -0,0 +1,92 @@
1
+
2
+ name: Release and Publish
3
+
4
+ on:
5
+ workflow_dispatch:
6
+ inputs:
7
+ version-bump:
8
+ description: 'Version bump type'
9
+ required: true
10
+ default: 'patch'
11
+ type: choice
12
+ options:
13
+ - patch
14
+ - minor
15
+ - major
16
+
17
+ env:
18
+ NODE_VERSION: '18'
19
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
20
+
21
+ jobs:
22
+ release:
23
+ runs-on: ubuntu-latest
24
+ permissions:
25
+ contents: write
26
+ packages: write
27
+
28
+ steps:
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v4
31
+ with:
32
+ fetch-depth: 0
33
+ token: ${{ secrets.GITHUB_TOKEN }}
34
+
35
+ - name: Setup Node.js
36
+ uses: actions/setup-node@v4
37
+ with:
38
+ node-version: ${{ env.NODE_VERSION }}
39
+ registry-url: 'https://registry.npmjs.org/'
40
+ scope: '@mikemajesty'
41
+
42
+ - name: Configure Git
43
+ run: |
44
+ git config --global user.name 'github-actions[bot]'
45
+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
46
+
47
+ - name: Bump version
48
+ id: bump-version
49
+ run: |
50
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
51
+ echo "Current version: $CURRENT_VERSION"
52
+
53
+ # Bump version usando npm version
54
+ if [[ "${{ github.event.inputs.version-bump }}" == *pre* ]]; then
55
+ npm version ${{ github.event.inputs.version-bump }} --no-git-tag-version
56
+ else
57
+ npm version ${{ github.event.inputs.version-bump }} --no-git-tag-version
58
+ fi
59
+
60
+ NEW_VERSION=$(node -p "require('./package.json').version")
61
+ echo "New version: $NEW_VERSION"
62
+
63
+ echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
64
+ echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
65
+
66
+ - name: Install dependencies
67
+ run: npm ci
68
+
69
+ - name: Commit changes
70
+ run: |
71
+ git add package.json package-lock.json
72
+ git commit -m "chore: release v${{ steps.bump-version.outputs.new_version }}"
73
+ git push origin HEAD:${{ github.ref }}
74
+
75
+ - name: Create tag
76
+ run: |
77
+ git tag -a "v${{ steps.bump-version.outputs.new_version }}" -m "Release v${{ steps.bump-version.outputs.new_version }}"
78
+ git push origin "v${{ steps.bump-version.outputs.new_version }}"
79
+
80
+ - name: Publish to npm
81
+ run: npm publish
82
+ env:
83
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
84
+
85
+ - name: Create GitHub Release
86
+ uses: softprops/action-gh-release@v1
87
+ with:
88
+ tag_name: v${{ steps.bump-version.outputs.new_version }}
89
+ name: Release v${{ steps.bump-version.outputs.new_version }}
90
+ generate_release_notes: true
91
+ env:
92
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/README.md ADDED
@@ -0,0 +1,306 @@
1
+ # NestJS Microservice CRUD CLI
2
+
3
+ A powerful CLI tool to generate CRUD modules for NestJS microservices following Clean Architecture principles.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Fast CRUD Generation**: Create complete CRUD modules in seconds
8
+ - 🏗️ **Clean Architecture**: Follows Clean Architecture patterns with separation of concerns
9
+ - 🔄 **Multiple Database Support**: PostgreSQL (TypeORM) and MongoDB (Mongoose)
10
+ - 📦 **Auto-Import**: Automatically registers modules in the appropriate files
11
+ - 🧪 **Test Ready**: Generates complete test suites with Jest
12
+ - 🔒 **Type Safe**: Full TypeScript support with proper validation
13
+ - 🎯 **Multiple Templates**: Core, Module, Library, Infrastructure, and CRUD generators
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install -g @mikemajesty/microservice-crud
19
+ ```
20
+
21
+ Or use directly with npx:
22
+
23
+ ```bash
24
+ npx @mikemajesty/microservice-crud
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Navigate to your NestJS microservice project root directory and run:
30
+
31
+ ```bash
32
+ microservice-crud
33
+ ```
34
+
35
+ Or using npm script:
36
+
37
+ ```bash
38
+ npm run crud
39
+ ```
40
+
41
+ ### Available Templates
42
+
43
+ The CLI will prompt you to select a template:
44
+
45
+ 1. **POSTGRES:CRUD** - Complete CRUD with PostgreSQL/TypeORM
46
+ 2. **MONGO:CRUD** - Complete CRUD with MongoDB/Mongoose
47
+ 3. **LIB** - Library module (shared services)
48
+ 4. **INFRA** - Infrastructure module (adapters, external services)
49
+ 5. **MODULE** - Simple module (controller + module only)
50
+ 6. **CORE** - Core use case (single domain logic)
51
+
52
+ ## What Gets Generated
53
+
54
+ ### POSTGRES:CRUD / MONGO:CRUD
55
+
56
+ Creates a complete CRUD module with:
57
+
58
+ ```
59
+ src/
60
+ ├── core/
61
+ │ └── [name]/
62
+ │ ├── entity/
63
+ │ │ └── [name].ts # Domain entity with validation
64
+ │ ├── repository/
65
+ │ │ └── [name].ts # Repository interface
66
+ │ └── use-cases/
67
+ │ ├── [name]-create.ts # Create use case
68
+ │ ├── [name]-update.ts # Update use case
69
+ │ ├── [name]-delete.ts # Delete use case
70
+ │ ├── [name]-list.ts # List with pagination
71
+ │ ├── [name]-get-by-id.ts # Get by ID use case
72
+ │ └── __tests__/ # Complete test suite
73
+ │ ├── [name]-create.spec.ts
74
+ │ ├── [name]-update.spec.ts
75
+ │ ├── [name]-delete.spec.ts
76
+ │ ├── [name]-list.spec.ts
77
+ │ └── [name]-get-by-id.spec.ts
78
+ ├── modules/
79
+ │ └── [name]/
80
+ │ ├── adapter.ts # Adapter interfaces
81
+ │ ├── controller.ts # REST controller with decorators
82
+ │ ├── module.ts # NestJS module
83
+ │ └── repository.ts # Repository implementation
84
+ └── infra/
85
+ └── database/
86
+ └── [postgres|mongo]/
87
+ └── schemas/
88
+ └── [name].ts # Database schema
89
+ ```
90
+
91
+ **Features:**
92
+ - ✅ Complete CRUD operations (Create, Read, Update, Delete, List)
93
+ - ✅ Input validation with Zod schemas
94
+ - ✅ Pagination support
95
+ - ✅ Search and filters
96
+ - ✅ Soft delete support
97
+ - ✅ Permission-based access control
98
+ - ✅ Swagger documentation ready
99
+ - ✅ Full test coverage
100
+
101
+ ### LIB (Library Module)
102
+
103
+ Creates a shared library module:
104
+
105
+ ```
106
+ src/libs/[name]/
107
+ ├── adapter.ts # Service adapter interface
108
+ ├── index.ts # Public exports
109
+ ├── module.ts # Library module
110
+ └── service.ts # Service implementation
111
+ ```
112
+
113
+ **Use cases:** Event handlers, i18n, metrics, tokens, shared utilities
114
+
115
+ ### INFRA (Infrastructure Module)
116
+
117
+ Creates an infrastructure module:
118
+
119
+ ```
120
+ src/infra/[name]/
121
+ ├── adapter.ts # Infrastructure adapter interface
122
+ ├── index.ts # Public exports
123
+ ├── module.ts # Infrastructure module
124
+ └── service.ts # Service implementation
125
+ ```
126
+
127
+ **Use cases:** Cache, database connections, email, HTTP clients, loggers, secrets
128
+
129
+ ### MODULE (Simple Module)
130
+
131
+ Creates a basic module:
132
+
133
+ ```
134
+ src/modules/[name]/
135
+ ├── controller.ts # Basic controller
136
+ └── module.ts # Module definition
137
+ ```
138
+
139
+ **Use cases:** Health checks, status endpoints, simple routes
140
+
141
+ ### CORE (Single Use Case)
142
+
143
+ Creates a single domain use case:
144
+
145
+ ```
146
+ src/core/[name]/
147
+ ├── entity/
148
+ │ └── [name].ts
149
+ ├── repository/
150
+ │ └── [name].ts
151
+ └── use-cases/
152
+ └── [name]-rename.ts
153
+ ```
154
+
155
+ **Use cases:** Custom business logic, specific operations
156
+
157
+ ## Auto-Import Behavior
158
+
159
+ The CLI automatically registers generated modules:
160
+
161
+ - **CRUD/MODULE**: Registered in `src/app.module.ts`
162
+ - **LIB**: Registered in `src/libs/module.ts` with `LibModule` suffix
163
+ - **INFRA**: Registered in `src/infra/module.ts`
164
+
165
+ No manual imports needed! 🎉
166
+
167
+ ## Name Validation
168
+
169
+ Module names are automatically sanitized:
170
+
171
+ - ✅ Converts to kebab-case
172
+ - ✅ Removes special characters
173
+ - ✅ Prevents numeric prefixes
174
+ - ✅ Handles spaces and underscores
175
+
176
+ Examples:
177
+ - `User Profile` → `user-profile`
178
+ - `my_module` → `my-module`
179
+ - `Product@123` → `product-123`
180
+
181
+ ## Generated Code Patterns
182
+
183
+ ### Entity
184
+ ```typescript
185
+ export class ProductEntity extends BaseEntity {
186
+ name: string;
187
+
188
+ constructor(input: ProductEntityInput) {
189
+ super();
190
+ this.name = input.name;
191
+ this.validate();
192
+ this.ensureID();
193
+ }
194
+
195
+ validate() {
196
+ const validation = ProductEntitySchema.safeParse(this);
197
+ if (!validation.success) return validation.error;
198
+ }
199
+ }
200
+ ```
201
+
202
+ ### Use Case
203
+ ```typescript
204
+ export class ProductCreateUsecase {
205
+ constructor(private readonly repository: IProductRepository) {}
206
+
207
+ async execute(input: ProductCreateInput): Promise<ProductEntity> {
208
+ const entity = new ProductEntity(input);
209
+ await this.repository.create(entity);
210
+ return entity.toObject();
211
+ }
212
+ }
213
+ ```
214
+
215
+ ### Controller
216
+ ```typescript
217
+ @Controller('products')
218
+ export class ProductController {
219
+ @Post()
220
+ @Permission('product:create')
221
+ @ApiBody({ type: ProductCreateInput })
222
+ async create(@Body() input: ProductCreateInput) {
223
+ return await this.createUsecase.execute(input);
224
+ }
225
+ }
226
+ ```
227
+
228
+ ## Requirements
229
+
230
+ Your NestJS project must have:
231
+
232
+ - `src/core/` directory
233
+ - `src/modules/` directory
234
+ - `src/app.module.ts` file
235
+
236
+ For library modules: `src/libs/module.ts`
237
+
238
+ For infrastructure modules: `src/infra/module.ts`
239
+
240
+ ## Best Practices
241
+
242
+ 1. **Run from project root**: Always execute the CLI from your NestJS project root
243
+ 2. **Descriptive names**: Use clear, descriptive module names
244
+ 3. **Follow conventions**: Stick to kebab-case naming
245
+ 4. **Review generated code**: Always review and customize generated code for your needs
246
+ 5. **Run tests**: Execute `npm test` after generation to ensure everything works
247
+
248
+ ## Testing Generated Code
249
+
250
+ After generating a module, verify it works:
251
+
252
+ ```bash
253
+ # Build the project
254
+ npm run build
255
+
256
+ # Run linter
257
+ npm run lint
258
+
259
+ # Run tests
260
+ npm test
261
+ ```
262
+
263
+ ## Customization
264
+
265
+ All generated templates are in `src/templates/`:
266
+
267
+ - `core/` - Core domain templates
268
+ - `mongo/` - MongoDB templates
269
+ - `postgres/` - PostgreSQL templates
270
+ - `libs/` - Library templates
271
+ - `infra/` - Infrastructure templates
272
+ - `module/` - Simple module templates
273
+
274
+ Modify these to match your project's patterns.
275
+
276
+ ## Troubleshooting
277
+
278
+ **Error: "select nestjs microservice api root"**
279
+ - Ensure you're running from the correct directory
280
+ - Verify `src/core/` and `src/modules/` exist
281
+
282
+ **Module not imported automatically**
283
+ - Check if target module file exists
284
+ - Verify import paths are correct
285
+ - Module may already be imported
286
+
287
+ **Build errors after generation**
288
+ - Run `npm run build` to check TypeScript errors
289
+ - Verify dependencies are installed
290
+ - Check for naming conflicts
291
+
292
+ ## Contributing
293
+
294
+ Contributions are welcome! Please submit issues and pull requests on GitHub.
295
+
296
+ ## License
297
+
298
+ MIT
299
+
300
+ ## Author
301
+
302
+ Mike Majesty - [@mikemajesty](https://github.com/mikemajesty)
303
+
304
+ ## Related Projects
305
+
306
+ - [NestJS Microservice Boilerplate](https://github.com/mikemajesty/nestjs-microservice-boilerplate-api)
@@ -1,3 +1,4 @@
1
1
  #! /usr/bin/env node
2
- require = require('esm')(module /*, options */)
3
- require('../src/cli').cli(process.argv);
2
+ import { cli } from '../src/cli.mjs';
3
+
4
+ cli(process.argv);
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@mikemajesty/microservice-crud",
3
- "version": "6.1.21",
3
+ "version": "7.1.0",
4
4
  "description": "Monorepo CLI",
5
5
  "main": "src/cli.js",
6
+ "type": "module",
6
7
  "scripts": {
7
8
  "permission": "chmod -R 777 ./bin/*",
8
- "crud": "ENV=local node ./bin/microservice-crud"
9
+ "crud": "ENV=local node ./bin/microservice-crud",
10
+ "check-newest:deps": "npx npm-check-updates"
9
11
  },
10
12
  "bin": {
11
13
  "@mikemajesty/microservice-crud": "bin/microservice-crud",
@@ -25,10 +27,12 @@
25
27
  "cli-select": "^1.1.2",
26
28
  "colorette": "^2.0.20",
27
29
  "esm": "^3.2.25",
28
- "fs": "^0.0.1-security",
29
- "fs-extra": "^11.2.0",
30
+ "fs-extra": "^11.3.0",
30
31
  "pluralize": "^8.0.0",
31
32
  "prompt-sync": "^4.2.0",
32
- "rimraf": "^5.0.10"
33
+ "rimraf": "^6.0.1"
34
+ },
35
+ "devDependencies": {
36
+ "npm-check-updates": "^17.1.15"
33
37
  }
34
- }
38
+ }