@dawudesign/node-hexa-cli 0.2.5 → 0.2.6
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/README.md +9 -11
- package/dist/index.js +6 -119
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,20 +46,18 @@ my-app/
|
|
|
46
46
|
├── src/
|
|
47
47
|
│ ├── main.ts
|
|
48
48
|
│ ├── app.module.ts
|
|
49
|
-
│
|
|
50
|
-
│
|
|
51
|
-
│ ├── iam.module.ts
|
|
52
|
-
│ ├── domain/
|
|
53
|
-
│ │ ├── entities/user.entity.ts
|
|
54
|
-
│ │ └── ports/user.repository.port.ts
|
|
55
|
-
│ ├── application/
|
|
56
|
-
│ │ └── use-cases/create-user.usecase.ts
|
|
57
|
-
│ └── infrastructure/
|
|
58
|
-
│ ├── http/user.controller.ts
|
|
59
|
-
│ └── persistence/in-memory-user.repository.ts
|
|
49
|
+
│ ├── contexts/ ← add your bounded contexts here
|
|
50
|
+
│ └── shared/
|
|
60
51
|
└── node-hexa.config.json
|
|
61
52
|
```
|
|
62
53
|
|
|
54
|
+
Then add your first bounded context:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cd my-app
|
|
58
|
+
node-hexa generate context orders
|
|
59
|
+
```
|
|
60
|
+
|
|
63
61
|
---
|
|
64
62
|
|
|
65
63
|
### `generate`
|
package/dist/index.js
CHANGED
|
@@ -403,10 +403,7 @@ function generateProject(name) {
|
|
|
403
403
|
const src = import_node_path5.default.join(base, "src");
|
|
404
404
|
import_node_fs4.default.rmSync(src, { recursive: true, force: true });
|
|
405
405
|
const dirs = [
|
|
406
|
-
"src/contexts
|
|
407
|
-
"src/contexts/iam/application/use-cases",
|
|
408
|
-
"src/contexts/iam/infrastructure/http",
|
|
409
|
-
"src/contexts/iam/infrastructure/persistence",
|
|
406
|
+
"src/contexts",
|
|
410
407
|
"src/shared"
|
|
411
408
|
];
|
|
412
409
|
dirs.forEach((dir) => {
|
|
@@ -427,127 +424,17 @@ bootstrap();
|
|
|
427
424
|
import_node_fs4.default.writeFileSync(
|
|
428
425
|
import_node_path5.default.join(base, "src/app.module.ts"),
|
|
429
426
|
`import { Module } from '@nestjs/common';
|
|
430
|
-
import { IamModule } from './contexts/iam/iam.module';
|
|
431
427
|
|
|
432
428
|
@Module({
|
|
433
|
-
imports: [
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
`
|
|
437
|
-
);
|
|
438
|
-
import_node_fs4.default.writeFileSync(
|
|
439
|
-
import_node_path5.default.join(base, "src/contexts/iam/domain/entities/user.entity.ts"),
|
|
440
|
-
`export class User {
|
|
441
|
-
constructor(
|
|
442
|
-
public readonly id: string,
|
|
443
|
-
public readonly email: string,
|
|
444
|
-
public readonly name: string,
|
|
445
|
-
) {}
|
|
446
|
-
}
|
|
447
|
-
`
|
|
448
|
-
);
|
|
449
|
-
import_node_fs4.default.writeFileSync(
|
|
450
|
-
import_node_path5.default.join(base, "src/contexts/iam/domain/ports/user.repository.port.ts"),
|
|
451
|
-
`import { User } from '../entities/user.entity';
|
|
452
|
-
|
|
453
|
-
export const USER_REPOSITORY_PORT = Symbol('UserRepositoryPort');
|
|
454
|
-
|
|
455
|
-
export interface UserRepositoryPort {
|
|
456
|
-
save(user: User): Promise<void>;
|
|
457
|
-
findById(id: string): Promise<User | null>;
|
|
458
|
-
}
|
|
459
|
-
`
|
|
460
|
-
);
|
|
461
|
-
import_node_fs4.default.writeFileSync(
|
|
462
|
-
import_node_path5.default.join(base, "src/contexts/iam/application/use-cases/create-user.usecase.ts"),
|
|
463
|
-
`import { Inject, Injectable } from '@nestjs/common';
|
|
464
|
-
import { User } from '../../domain/entities/user.entity';
|
|
465
|
-
import {
|
|
466
|
-
USER_REPOSITORY_PORT,
|
|
467
|
-
UserRepositoryPort,
|
|
468
|
-
} from '../../domain/ports/user.repository.port';
|
|
469
|
-
import { randomUUID } from 'node:crypto';
|
|
470
|
-
|
|
471
|
-
export interface CreateUserDto {
|
|
472
|
-
email: string;
|
|
473
|
-
name: string;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
@Injectable()
|
|
477
|
-
export class CreateUserUseCase {
|
|
478
|
-
constructor(
|
|
479
|
-
@Inject(USER_REPOSITORY_PORT)
|
|
480
|
-
private readonly userRepository: UserRepositoryPort,
|
|
481
|
-
) {}
|
|
482
|
-
|
|
483
|
-
async execute(dto: CreateUserDto): Promise<User> {
|
|
484
|
-
const user = new User(randomUUID(), dto.email, dto.name);
|
|
485
|
-
await this.userRepository.save(user);
|
|
486
|
-
return user;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
`
|
|
490
|
-
);
|
|
491
|
-
import_node_fs4.default.writeFileSync(
|
|
492
|
-
import_node_path5.default.join(
|
|
493
|
-
base,
|
|
494
|
-
"src/contexts/iam/infrastructure/persistence/in-memory-user.repository.ts"
|
|
495
|
-
),
|
|
496
|
-
`import { Injectable } from '@nestjs/common';
|
|
497
|
-
import { User } from '../../domain/entities/user.entity';
|
|
498
|
-
import { UserRepositoryPort } from '../../domain/ports/user.repository.port';
|
|
499
|
-
|
|
500
|
-
@Injectable()
|
|
501
|
-
export class InMemoryUserRepository implements UserRepositoryPort {
|
|
502
|
-
private readonly store = new Map<string, User>();
|
|
503
|
-
|
|
504
|
-
async save(user: User): Promise<void> {
|
|
505
|
-
this.store.set(user.id, user);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
async findById(id: string): Promise<User | null> {
|
|
509
|
-
return this.store.get(id) ?? null;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
`
|
|
513
|
-
);
|
|
514
|
-
import_node_fs4.default.writeFileSync(
|
|
515
|
-
import_node_path5.default.join(base, "src/contexts/iam/infrastructure/http/user.controller.ts"),
|
|
516
|
-
`import { Body, Controller, Post } from '@nestjs/common';
|
|
517
|
-
import { CreateUserUseCase, CreateUserDto } from '../../application/use-cases/create-user.usecase';
|
|
518
|
-
|
|
519
|
-
@Controller('users')
|
|
520
|
-
export class UserController {
|
|
521
|
-
constructor(private readonly createUser: CreateUserUseCase) {}
|
|
522
|
-
|
|
523
|
-
@Post()
|
|
524
|
-
async create(@Body() dto: CreateUserDto) {
|
|
525
|
-
return this.createUser.execute(dto);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
`
|
|
529
|
-
);
|
|
530
|
-
import_node_fs4.default.writeFileSync(
|
|
531
|
-
import_node_path5.default.join(base, "src/contexts/iam/iam.module.ts"),
|
|
532
|
-
`import { Module } from '@nestjs/common';
|
|
533
|
-
import { USER_REPOSITORY_PORT } from './domain/ports/user.repository.port';
|
|
534
|
-
import { InMemoryUserRepository } from './infrastructure/persistence/in-memory-user.repository';
|
|
535
|
-
import { CreateUserUseCase } from './application/use-cases/create-user.usecase';
|
|
536
|
-
import { UserController } from './infrastructure/http/user.controller';
|
|
537
|
-
|
|
538
|
-
@Module({
|
|
539
|
-
controllers: [UserController],
|
|
540
|
-
providers: [
|
|
541
|
-
{
|
|
542
|
-
provide: USER_REPOSITORY_PORT,
|
|
543
|
-
useClass: InMemoryUserRepository,
|
|
544
|
-
},
|
|
545
|
-
CreateUserUseCase,
|
|
429
|
+
imports: [
|
|
430
|
+
// Import your bounded context modules here
|
|
431
|
+
// e.g. import { OrdersModule } from './contexts/orders/orders.module';
|
|
546
432
|
],
|
|
547
433
|
})
|
|
548
|
-
export class
|
|
434
|
+
export class AppModule {}
|
|
549
435
|
`
|
|
550
436
|
);
|
|
437
|
+
import_node_fs4.default.writeFileSync(import_node_path5.default.join(base, "src/contexts/.gitkeep"), "");
|
|
551
438
|
import_node_fs4.default.writeFileSync(import_node_path5.default.join(base, "src/shared/.gitkeep"), "");
|
|
552
439
|
import_node_fs4.default.writeFileSync(
|
|
553
440
|
import_node_path5.default.join(base, "node-hexa.config.json"),
|