@dawudesign/node-hexa-cli 0.2.6 → 0.2.8
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/dist/index.js +16 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -470,23 +470,16 @@ function assertKebabCase(value, label) {
|
|
|
470
470
|
}
|
|
471
471
|
function assertInsideProject() {
|
|
472
472
|
const pkgPath = import_node_path6.default.join(process.cwd(), "package.json");
|
|
473
|
+
const configPath = import_node_path6.default.join(process.cwd(), "node-hexa.config.json");
|
|
474
|
+
const contextsPath = import_node_path6.default.join(process.cwd(), "src", "contexts");
|
|
473
475
|
if (!import_node_fs5.default.existsSync(pkgPath)) {
|
|
474
476
|
throw new Error(
|
|
475
|
-
"No package.json found. Run this command from the root of your
|
|
477
|
+
"No package.json found. Run this command from the root of your project."
|
|
476
478
|
);
|
|
477
479
|
}
|
|
478
|
-
|
|
479
|
-
try {
|
|
480
|
-
pkg = JSON.parse(import_node_fs5.default.readFileSync(pkgPath, "utf8"));
|
|
481
|
-
} catch {
|
|
482
|
-
throw new Error(
|
|
483
|
-
"Could not parse package.json. Make sure it contains valid JSON."
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
487
|
-
if (!allDeps["@nestjs/core"]) {
|
|
480
|
+
if (!import_node_fs5.default.existsSync(configPath) && !import_node_fs5.default.existsSync(contextsPath)) {
|
|
488
481
|
throw new Error(
|
|
489
|
-
"
|
|
482
|
+
"No node-hexa.config.json or src/contexts/ found.\nRun this command from the root of a node-hexa project, or run 'node-hexa init <name>' first."
|
|
490
483
|
);
|
|
491
484
|
}
|
|
492
485
|
}
|
|
@@ -512,6 +505,7 @@ function generateContext(name) {
|
|
|
512
505
|
dirs.forEach((dir) => {
|
|
513
506
|
import_node_fs6.default.mkdirSync(import_node_path7.default.join(base, dir), { recursive: true });
|
|
514
507
|
});
|
|
508
|
+
import_node_fs6.default.writeFileSync(import_node_path7.default.join(base, "domain/value-objects/.gitkeep"), "");
|
|
515
509
|
const pascal = capitalize(name);
|
|
516
510
|
const token = `${name.toUpperCase().replaceAll("-", "_")}_REPOSITORY_PORT`;
|
|
517
511
|
import_node_fs6.default.writeFileSync(
|
|
@@ -543,6 +537,10 @@ import {
|
|
|
543
537
|
} from '../../domain/ports/${name}.repository.port';
|
|
544
538
|
import { randomUUID } from 'node:crypto';
|
|
545
539
|
|
|
540
|
+
export interface Create${pascal}Dto {
|
|
541
|
+
id?: string;
|
|
542
|
+
}
|
|
543
|
+
|
|
546
544
|
@Injectable()
|
|
547
545
|
export class Create${pascal}UseCase {
|
|
548
546
|
constructor(
|
|
@@ -550,8 +548,8 @@ export class Create${pascal}UseCase {
|
|
|
550
548
|
private readonly repository: ${pascal}RepositoryPort,
|
|
551
549
|
) {}
|
|
552
550
|
|
|
553
|
-
async execute(
|
|
554
|
-
const entity = new ${pascal}(id ?? randomUUID());
|
|
551
|
+
async execute(dto: Create${pascal}Dto = {}): Promise<${pascal}> {
|
|
552
|
+
const entity = new ${pascal}(dto.id ?? randomUUID());
|
|
555
553
|
await this.repository.save(entity);
|
|
556
554
|
return entity;
|
|
557
555
|
}
|
|
@@ -560,16 +558,16 @@ export class Create${pascal}UseCase {
|
|
|
560
558
|
);
|
|
561
559
|
import_node_fs6.default.writeFileSync(
|
|
562
560
|
import_node_path7.default.join(base, "infrastructure/http", `${name}.controller.ts`),
|
|
563
|
-
`import { Controller, Post } from '@nestjs/common';
|
|
564
|
-
import { Create${pascal}UseCase } from '../../application/use-cases/create-${name}.usecase';
|
|
561
|
+
`import { Body, Controller, Post } from '@nestjs/common';
|
|
562
|
+
import { Create${pascal}UseCase, Create${pascal}Dto } from '../../application/use-cases/create-${name}.usecase';
|
|
565
563
|
|
|
566
564
|
@Controller('${name}')
|
|
567
565
|
export class ${pascal}Controller {
|
|
568
566
|
constructor(private readonly create${pascal}: Create${pascal}UseCase) {}
|
|
569
567
|
|
|
570
568
|
@Post()
|
|
571
|
-
async create() {
|
|
572
|
-
return this.create${pascal}.execute();
|
|
569
|
+
async create(@Body() dto: Create${pascal}Dto) {
|
|
570
|
+
return this.create${pascal}.execute(dto);
|
|
573
571
|
}
|
|
574
572
|
}
|
|
575
573
|
`
|