@hazeljs/cli 0.2.0-beta.1

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 (76) hide show
  1. package/@template/README.md +61 -0
  2. package/@template/package.json +48 -0
  3. package/@template/src/app.module.ts +7 -0
  4. package/@template/src/hello.controller.ts +9 -0
  5. package/@template/src/index.ts +10 -0
  6. package/README.md +675 -0
  7. package/dist/commands/add.d.ts +2 -0
  8. package/dist/commands/add.js +90 -0
  9. package/dist/commands/build.d.ts +2 -0
  10. package/dist/commands/build.js +52 -0
  11. package/dist/commands/generate-agent.d.ts +2 -0
  12. package/dist/commands/generate-agent.js +56 -0
  13. package/dist/commands/generate-ai-service.d.ts +2 -0
  14. package/dist/commands/generate-ai-service.js +49 -0
  15. package/dist/commands/generate-app.d.ts +2 -0
  16. package/dist/commands/generate-app.js +246 -0
  17. package/dist/commands/generate-controller.d.ts +2 -0
  18. package/dist/commands/generate-controller.js +59 -0
  19. package/dist/commands/generate-crud.d.ts +2 -0
  20. package/dist/commands/generate-crud.js +203 -0
  21. package/dist/commands/generate-dto.d.ts +2 -0
  22. package/dist/commands/generate-dto.js +56 -0
  23. package/dist/commands/generate-exception-filter.d.ts +2 -0
  24. package/dist/commands/generate-exception-filter.js +50 -0
  25. package/dist/commands/generate-guard.d.ts +2 -0
  26. package/dist/commands/generate-guard.js +35 -0
  27. package/dist/commands/generate-interceptor.d.ts +2 -0
  28. package/dist/commands/generate-interceptor.js +37 -0
  29. package/dist/commands/generate-middleware.d.ts +2 -0
  30. package/dist/commands/generate-middleware.js +79 -0
  31. package/dist/commands/generate-module.d.ts +2 -0
  32. package/dist/commands/generate-module.js +96 -0
  33. package/dist/commands/generate-pipe.d.ts +2 -0
  34. package/dist/commands/generate-pipe.js +33 -0
  35. package/dist/commands/generate-repository.d.ts +2 -0
  36. package/dist/commands/generate-repository.js +38 -0
  37. package/dist/commands/generate-serverless-handler.d.ts +2 -0
  38. package/dist/commands/generate-serverless-handler.js +46 -0
  39. package/dist/commands/generate-service.d.ts +2 -0
  40. package/dist/commands/generate-service.js +51 -0
  41. package/dist/commands/generate-websocket-gateway.d.ts +2 -0
  42. package/dist/commands/generate-websocket-gateway.js +47 -0
  43. package/dist/commands/info.d.ts +2 -0
  44. package/dist/commands/info.js +91 -0
  45. package/dist/commands/start.d.ts +2 -0
  46. package/dist/commands/start.js +61 -0
  47. package/dist/commands/test.d.ts +2 -0
  48. package/dist/commands/test.js +63 -0
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +61 -0
  51. package/dist/utils/generator.d.ts +14 -0
  52. package/dist/utils/generator.js +79 -0
  53. package/package.json +67 -0
  54. package/src/commands/add.ts +101 -0
  55. package/src/commands/build.ts +56 -0
  56. package/src/commands/generate-agent.ts +58 -0
  57. package/src/commands/generate-ai-service.ts +52 -0
  58. package/src/commands/generate-app.ts +270 -0
  59. package/src/commands/generate-controller.ts +61 -0
  60. package/src/commands/generate-crud.ts +214 -0
  61. package/src/commands/generate-dto.ts +61 -0
  62. package/src/commands/generate-exception-filter.ts +53 -0
  63. package/src/commands/generate-guard.ts +37 -0
  64. package/src/commands/generate-interceptor.ts +39 -0
  65. package/src/commands/generate-middleware.ts +86 -0
  66. package/src/commands/generate-module.ts +102 -0
  67. package/src/commands/generate-pipe.ts +36 -0
  68. package/src/commands/generate-repository.ts +41 -0
  69. package/src/commands/generate-serverless-handler.ts +53 -0
  70. package/src/commands/generate-service.ts +53 -0
  71. package/src/commands/generate-websocket-gateway.ts +50 -0
  72. package/src/commands/info.ts +106 -0
  73. package/src/commands/start.ts +61 -0
  74. package/src/commands/test.ts +70 -0
  75. package/src/index.ts +68 -0
  76. package/src/utils/generator.ts +93 -0
package/README.md ADDED
@@ -0,0 +1,675 @@
1
+ # @hazeljs/cli
2
+
3
+ **Command-Line Interface for HazelJS**
4
+
5
+ Scaffold applications and generate components with a powerful CLI tool for rapid development.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@hazeljs/cli.svg)](https://www.npmjs.com/package/@hazeljs/cli)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ## Features
11
+
12
+ - 🚀 **Project Scaffolding** - Create new HazelJS applications instantly with interactive setup
13
+ - 🎨 **Code Generation** - Generate controllers, services, modules, and more
14
+ - 🏗️ **Best Practices** - Generated code follows HazelJS conventions
15
+ - 🔧 **Customizable** - Specify paths and options for generated files
16
+ - 📦 **Multiple Templates** - Support for various component types
17
+ - ⚡ **Fast Development** - Reduce boilerplate and speed up development
18
+ - 🎯 **TypeScript First** - All generated code is fully typed
19
+ - 🛠️ **Utility Commands** - Build, start, test, and manage your project
20
+ - 📊 **Project Info** - Display comprehensive project information
21
+ - ➕ **Package Management** - Add HazelJS packages interactively
22
+ - 🎭 **CRUD Generator** - Generate complete CRUD resources in one command
23
+
24
+ ## Installation
25
+
26
+ ### Global Installation (Recommended)
27
+
28
+ ```bash
29
+ npm install -g @hazeljs/cli
30
+ ```
31
+
32
+ ### Local Installation
33
+
34
+ ```bash
35
+ npm install --save-dev @hazeljs/cli
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ The CLI provides commands to generate various HazelJS components, create new applications, and manage your project.
41
+
42
+ ## Commands
43
+
44
+ ### Project Management
45
+
46
+ #### Create New Application
47
+
48
+ ```bash
49
+ hazel new <appName> [options]
50
+ ```
51
+
52
+ Creates a new HazelJS application with optional interactive setup.
53
+
54
+ **Options:**
55
+ - `-d, --dest <path>` - Destination path (default: current directory)
56
+ - `-i, --interactive` - Interactive setup with package selection
57
+ - `--skip-install` - Skip npm install
58
+ - `--skip-git` - Skip git initialization
59
+
60
+ **Examples:**
61
+ ```bash
62
+ # Basic project creation
63
+ hazel new my-app
64
+
65
+ # Interactive setup with package selection
66
+ hazel new my-app -i
67
+
68
+ # Create without installing dependencies
69
+ hazel new my-app --skip-install
70
+ ```
71
+
72
+ #### Project Information
73
+
74
+ ```bash
75
+ hazel info
76
+ ```
77
+
78
+ Display comprehensive information about your HazelJS project including:
79
+ - Project name, version, and description
80
+ - Installed HazelJS packages
81
+ - Project structure
82
+ - Environment details
83
+ - Configuration files
84
+
85
+ #### Add Packages
86
+
87
+ ```bash
88
+ hazel add [package]
89
+ ```
90
+
91
+ Add HazelJS packages to your project interactively.
92
+
93
+ **Examples:**
94
+ ```bash
95
+ # Interactive package selection
96
+ hazel add
97
+
98
+ # Add specific package
99
+ hazel add ai
100
+ hazel add auth
101
+ hazel add prisma
102
+ ```
103
+
104
+ **Available packages:**
105
+ - `ai` - AI Integration (@hazeljs/ai)
106
+ - `auth` - Authentication (@hazeljs/auth)
107
+ - `cache` - Caching (@hazeljs/cache)
108
+ - `config` - Configuration (@hazeljs/config)
109
+ - `cron` - Cron Jobs (@hazeljs/cron)
110
+ - `prisma` - Prisma ORM (@hazeljs/prisma)
111
+ - `rag` - RAG/Vector Search (@hazeljs/rag)
112
+ - `serverless` - Serverless (@hazeljs/serverless)
113
+ - `swagger` - Swagger/OpenAPI (@hazeljs/swagger)
114
+ - `websocket` - WebSocket (@hazeljs/websocket)
115
+
116
+ #### Build Project
117
+
118
+ ```bash
119
+ hazel build [options]
120
+ ```
121
+
122
+ Build your HazelJS project.
123
+
124
+ **Options:**
125
+ - `-w, --watch` - Watch mode
126
+ - `-p, --production` - Production build
127
+
128
+ **Examples:**
129
+ ```bash
130
+ # Standard build
131
+ hazel build
132
+
133
+ # Watch mode
134
+ hazel build -w
135
+
136
+ # Production build
137
+ hazel build -p
138
+ ```
139
+
140
+ #### Start Application
141
+
142
+ ```bash
143
+ hazel start [options]
144
+ ```
145
+
146
+ Start your HazelJS application.
147
+
148
+ **Options:**
149
+ - `-d, --dev` - Start in development mode
150
+ - `-p, --port <port>` - Specify port
151
+
152
+ **Examples:**
153
+ ```bash
154
+ # Start in production mode
155
+ hazel start
156
+
157
+ # Start in development mode with hot reload
158
+ hazel start -d
159
+
160
+ # Start on specific port
161
+ hazel start -p 8080
162
+ ```
163
+
164
+ #### Run Tests
165
+
166
+ ```bash
167
+ hazel test [pattern] [options]
168
+ ```
169
+
170
+ Run tests for your HazelJS project.
171
+
172
+ **Options:**
173
+ - `-w, --watch` - Watch mode
174
+ - `-c, --coverage` - Generate coverage report
175
+ - `--ci` - Run in CI mode
176
+
177
+ **Examples:**
178
+ ```bash
179
+ # Run all tests
180
+ hazel test
181
+
182
+ # Run specific test file
183
+ hazel test user.test
184
+
185
+ # Watch mode
186
+ hazel test -w
187
+
188
+ # Generate coverage
189
+ hazel test -c
190
+ ```
191
+
192
+ ### Code Generation
193
+
194
+ ```bash
195
+ hazel generate <component> <name> [options]
196
+ ```
197
+
198
+ Or using the shorter alias:
199
+
200
+ ```bash
201
+ hazel g <component> <name> [options]
202
+ ```
203
+
204
+ ### Available Generators
205
+
206
+ #### Core Components
207
+ - `controller` / `c` - Generate a new controller
208
+ - `service` / `s` - Generate a new service
209
+ - `module` / `m` - Generate a new module
210
+ - `dto` - Generate create and update DTOs
211
+ - `guard` - Generate a new guard
212
+ - `interceptor` / `i` - Generate a new interceptor
213
+ - `middleware` / `mw` - Generate a new middleware
214
+
215
+ #### Advanced Generators
216
+ - **`crud`** - Generate complete CRUD resource (controller + service + module + DTOs)
217
+ - `gateway` / `ws` - Generate a WebSocket gateway
218
+ - `filter` / `f` - Generate an exception filter
219
+ - `pipe` / `p` - Generate a transformation pipe
220
+ - `repository` / `repo` - Generate a Prisma repository
221
+ - `ai-service` / `ai` - Generate an AI service with decorators
222
+ - `serverless` / `sls` - Generate a serverless handler (Lambda/Cloud Function)
223
+
224
+ ### Generator Options
225
+
226
+ - `-p, --path <path>` - Specify the path where the component should be generated (default: 'src')
227
+ - `-r, --route <route>` - Specify the route path (for CRUD generator)
228
+ - `--platform <platform>` - For serverless, specify platform: `lambda` or `cloud-function` (default: 'lambda')
229
+
230
+ ### Generator Examples
231
+
232
+ #### CRUD Generator (Recommended)
233
+
234
+ Generate a complete CRUD resource with controller, service, module, and DTOs:
235
+ ```bash
236
+ hazel g crud user
237
+
238
+ # With custom path
239
+ hazel g crud product -p src/products
240
+
241
+ # With custom route
242
+ hazel g crud article -r /api/articles
243
+ ```
244
+
245
+ This creates:
246
+ - `user.controller.ts` - Full CRUD controller
247
+ - `user.service.ts` - Service with all CRUD methods
248
+ - `user.module.ts` - Module configuration
249
+ - `dto/user.dto.ts` - Create and Update DTOs
250
+
251
+ #### Core Components
252
+
253
+ Generate a new user controller:
254
+ ```bash
255
+ hazel g controller user
256
+ ```
257
+
258
+ Generate a new auth service in a specific path:
259
+ ```bash
260
+ hazel g service auth -p src/auth
261
+ ```
262
+
263
+ Generate create and update DTOs for a product:
264
+ ```bash
265
+ hazel g dto product
266
+ ```
267
+
268
+ Generate a new authentication guard:
269
+ ```bash
270
+ hazel g guard auth
271
+ ```
272
+
273
+ Generate a new logging interceptor:
274
+ ```bash
275
+ hazel g interceptor logging
276
+ ```
277
+
278
+ Generate a new middleware:
279
+ ```bash
280
+ hazel g middleware logging
281
+ # or
282
+ hazel g mw cors -p src/middleware
283
+ ```
284
+
285
+ #### Advanced Generators
286
+
287
+ Generate a WebSocket gateway:
288
+ ```bash
289
+ hazel g gateway notifications
290
+ # or
291
+ hazel g ws notifications
292
+ ```
293
+
294
+ Generate an exception filter:
295
+ ```bash
296
+ hazel g filter http-exception
297
+ # or
298
+ hazel g f http-exception
299
+ ```
300
+
301
+ Generate a validation pipe:
302
+ ```bash
303
+ hazel g pipe validation
304
+ # or
305
+ hazel g p validation
306
+ ```
307
+
308
+ Generate a Prisma repository:
309
+ ```bash
310
+ hazel g repository user
311
+ # or
312
+ hazel g repo user
313
+ ```
314
+
315
+ Generate an AI service:
316
+ ```bash
317
+ hazel g ai-service chat
318
+ # or
319
+ hazel g ai chat
320
+ ```
321
+
322
+ Generate a Lambda handler:
323
+ ```bash
324
+ hazel g serverless handler --platform lambda
325
+ # or
326
+ hazel g sls handler
327
+ ```
328
+
329
+ Generate a Cloud Function handler:
330
+ ```bash
331
+ hazel g serverless handler --platform cloud-function
332
+ ```
333
+
334
+ ## Generated File Structure
335
+
336
+ ### Controller
337
+
338
+ ```typescript
339
+ import { Controller, Get, Post, Put, Delete, Body, Param } from '@hazeljs/core';
340
+ import { UserService } from './user.service';
341
+
342
+ @Controller('/users')
343
+ export class UserController {
344
+ constructor(private userService: UserService) {}
345
+
346
+ @Get()
347
+ findAll() {
348
+ return this.userService.findAll();
349
+ }
350
+
351
+ @Get('/:id')
352
+ findOne(@Param('id') id: string) {
353
+ return this.userService.findOne(id);
354
+ }
355
+
356
+ @Post()
357
+ create(@Body() createDto: any) {
358
+ return this.userService.create(createDto);
359
+ }
360
+
361
+ @Put('/:id')
362
+ update(@Param('id') id: string, @Body() updateDto: any) {
363
+ return this.userService.update(id, updateDto);
364
+ }
365
+
366
+ @Delete('/:id')
367
+ delete(@Param('id') id: string) {
368
+ return this.userService.delete(id);
369
+ }
370
+ }
371
+ ```
372
+
373
+ ### Service
374
+
375
+ ```typescript
376
+ import { Injectable } from '@hazeljs/core';
377
+
378
+ @Injectable()
379
+ export class UserService {
380
+ findAll() {
381
+ return [];
382
+ }
383
+
384
+ findOne(id: string) {
385
+ return { id };
386
+ }
387
+
388
+ create(data: any) {
389
+ return { id: '1', ...data };
390
+ }
391
+
392
+ update(id: string, data: any) {
393
+ return { id, ...data };
394
+ }
395
+
396
+ delete(id: string) {
397
+ return { id };
398
+ }
399
+ }
400
+ ```
401
+
402
+ ### Module
403
+
404
+ ```typescript
405
+ import { HazelModule } from '@hazeljs/core';
406
+ import { UserController } from './user.controller';
407
+ import { UserService } from './user.service';
408
+
409
+ @HazelModule({
410
+ controllers: [UserController],
411
+ providers: [UserService],
412
+ })
413
+ export class UserModule {}
414
+ ```
415
+
416
+ ### DTO
417
+
418
+ ```typescript
419
+ import { IsString, IsEmail, MinLength } from 'class-validator';
420
+
421
+ export class CreateUserDto {
422
+ @IsEmail()
423
+ email: string;
424
+
425
+ @IsString()
426
+ @MinLength(8)
427
+ password: string;
428
+
429
+ @IsString()
430
+ name: string;
431
+ }
432
+
433
+ export class UpdateUserDto {
434
+ @IsEmail()
435
+ email?: string;
436
+
437
+ @IsString()
438
+ name?: string;
439
+ }
440
+ ```
441
+
442
+ ## Best Practices
443
+
444
+ 1. **Organize by Feature** - Group related components in feature modules
445
+ 2. **Use DTOs** - Always generate and use DTOs for validation
446
+ 3. **Follow Naming Conventions** - Use singular names for entities (User, not Users)
447
+ 4. **Specify Paths** - Use `-p` flag to organize files properly
448
+ 5. **Generate Complete Features** - Generate controller, service, module, and DTOs together
449
+
450
+ ## Common Workflows
451
+
452
+ ### Create a Complete CRUD Feature
453
+
454
+ **Option 1: Using CRUD Generator (Recommended)**
455
+ ```bash
456
+ # Generate everything in one command
457
+ hazel g crud user -p src/user
458
+ ```
459
+
460
+ **Option 2: Manual Generation**
461
+ ```bash
462
+ # Generate all components separately
463
+ hazel g module user -p src/user
464
+ hazel g controller user -p src/user
465
+ hazel g service user -p src/user
466
+ hazel g dto user -p src/user
467
+ ```
468
+
469
+ ### Create a Microservice
470
+
471
+ ```bash
472
+ # Create new app with interactive setup
473
+ hazel new my-microservice -i
474
+
475
+ # Navigate to project
476
+ cd my-microservice
477
+
478
+ # Generate CRUD resources
479
+ hazel g crud user
480
+ hazel g crud product
481
+ hazel g crud order
482
+
483
+ # Add additional packages
484
+ hazel add swagger
485
+ hazel add auth
486
+
487
+ # Start development
488
+ hazel start -d
489
+ ```
490
+
491
+ ### Add WebSocket Support
492
+
493
+ ```bash
494
+ # Generate WebSocket gateway
495
+ hazel g gateway chat -p src/chat
496
+ hazel g service chat -p src/chat
497
+ ```
498
+
499
+ ### Add AI Integration
500
+
501
+ ```bash
502
+ # Generate AI service
503
+ hazel g ai-service assistant -p src/ai
504
+ ```
505
+
506
+ ### Prepare for Serverless
507
+
508
+ ```bash
509
+ # Generate Lambda handler
510
+ hazel g serverless handler --platform lambda
511
+ ```
512
+
513
+ ## Quick Reference
514
+
515
+ ### All Available Commands
516
+
517
+ ```bash
518
+ # Project Management
519
+ hazel new <name> [-i] # Create new project
520
+ hazel info # Show project info
521
+ hazel add [package] # Add HazelJS packages
522
+ hazel build [-w] [-p] # Build project
523
+ hazel start [-d] [-p <port>] # Start application
524
+ hazel test [pattern] [-w] [-c] # Run tests
525
+
526
+ # Code Generation (alias: g)
527
+ hazel g crud <name> # Complete CRUD resource
528
+ hazel g controller <name> # Controller
529
+ hazel g service <name> # Service
530
+ hazel g module <name> # Module
531
+ hazel g middleware <name> # Middleware
532
+ hazel g guard <name> # Guard
533
+ hazel g interceptor <name> # Interceptor
534
+ hazel g filter <name> # Exception filter
535
+ hazel g pipe <name> # Pipe
536
+ hazel g dto <name> # DTOs
537
+ hazel g repository <name> # Prisma repository
538
+ hazel g ai-service <name> # AI service
539
+ hazel g gateway <name> # WebSocket gateway
540
+ hazel g serverless <name> # Serverless handler
541
+ ```
542
+
543
+ ## Configuration
544
+
545
+ Create a `.hazelrc.json` file in your project root for custom configuration:
546
+
547
+ ```json
548
+ {
549
+ "defaultPath": "src",
550
+ "typescript": true,
551
+ "generateTests": true,
552
+ "styleGuide": "airbnb"
553
+ }
554
+ ```
555
+
556
+ ## Tips & Tricks
557
+
558
+ ### Use Aliases
559
+
560
+ ```bash
561
+ # These are equivalent
562
+ hazel generate controller user
563
+ hazel g c user
564
+
565
+ # CRUD generator is the fastest way
566
+ hazel g crud user
567
+ ```
568
+
569
+ ### Interactive Setup
570
+
571
+ ```bash
572
+ # Use interactive mode for new projects
573
+ hazel new my-app -i
574
+
575
+ # Select packages interactively
576
+ hazel add
577
+ ```
578
+
579
+ ### Batch Generation
580
+
581
+ ```bash
582
+ # Use CRUD generator instead of multiple commands
583
+ hazel g crud user # Better than:
584
+ # hazel g controller user && hazel g service user && hazel g module user && hazel g dto user
585
+ ```
586
+
587
+ ### Custom Paths
588
+
589
+ ```bash
590
+ # Organize by feature
591
+ hazel g crud user -p src/features/user
592
+ hazel g middleware logging -p src/common/middleware
593
+ ```
594
+
595
+ ### Development Workflow
596
+
597
+ ```bash
598
+ # Quick development cycle
599
+ hazel new my-app -i # Create with interactive setup
600
+ cd my-app
601
+ hazel g crud user # Generate CRUD resource
602
+ hazel add swagger # Add API documentation
603
+ hazel start -d # Start in dev mode
604
+
605
+ # In another terminal
606
+ hazel test -w # Run tests in watch mode
607
+ ```
608
+
609
+ ## Troubleshooting
610
+
611
+ ### Command Not Found
612
+
613
+ If `hazel` command is not found after global installation:
614
+
615
+ ```bash
616
+ # Check npm global bin path
617
+ npm config get prefix
618
+
619
+ # Add to PATH (macOS/Linux)
620
+ export PATH="$(npm config get prefix)/bin:$PATH"
621
+
622
+ # Or reinstall globally
623
+ npm install -g @hazeljs/cli
624
+ ```
625
+
626
+ ### Permission Errors
627
+
628
+ ```bash
629
+ # Use sudo (not recommended)
630
+ sudo npm install -g @hazeljs/cli
631
+
632
+ # Or fix npm permissions
633
+ mkdir ~/.npm-global
634
+ npm config set prefix '~/.npm-global'
635
+ export PATH=~/.npm-global/bin:$PATH
636
+ ```
637
+
638
+ ## Development
639
+
640
+ ### Building
641
+
642
+ ```bash
643
+ npm run build
644
+ ```
645
+
646
+ ### Testing
647
+
648
+ ```bash
649
+ npm test
650
+ ```
651
+
652
+ ### Linting
653
+
654
+ ```bash
655
+ npm run lint
656
+ ```
657
+
658
+ ## Examples
659
+
660
+ See the [examples](../../example) directory for complete working examples of generated code.
661
+
662
+ ## Contributing
663
+
664
+ Contributions are welcome! Please read our [Contributing Guide](../../CONTRIBUTING.md) for details.
665
+
666
+ ## License
667
+
668
+ MIT © [HazelJS](https://hazeljs.com)
669
+
670
+ ## Links
671
+
672
+ - [Documentation](https://hazeljs.com/docs/packages/cli)
673
+ - [GitHub](https://github.com/hazel-js/hazeljs)
674
+ - [Issues](https://github.com/hazel-js/hazeljs/issues)
675
+ - [Discord](https://discord.gg/hazeljs)
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function addCommand(program: Command): void;