nestjs-ddd-cli 1.0.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.
- package/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/commands/generate-all.d.ts +2 -0
- package/dist/commands/generate-all.d.ts.map +1 -0
- package/dist/commands/generate-all.js +144 -0
- package/dist/commands/generate-all.js.map +1 -0
- package/dist/commands/generate-entity.d.ts +2 -0
- package/dist/commands/generate-entity.d.ts.map +1 -0
- package/dist/commands/generate-entity.js +97 -0
- package/dist/commands/generate-entity.js.map +1 -0
- package/dist/commands/generate-module.d.ts +2 -0
- package/dist/commands/generate-module.d.ts.map +1 -0
- package/dist/commands/generate-module.js +111 -0
- package/dist/commands/generate-module.js.map +1 -0
- package/dist/commands/generate-usecase.d.ts +2 -0
- package/dist/commands/generate-usecase.d.ts.map +1 -0
- package/dist/commands/generate-usecase.js +84 -0
- package/dist/commands/generate-usecase.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/command/create-command.hbs +27 -0
- package/dist/templates/controller/controller.hbs +43 -0
- package/dist/templates/dto/create-dto.hbs +18 -0
- package/dist/templates/entity/entity.hbs +19 -0
- package/dist/templates/index/index-export.hbs +9 -0
- package/dist/templates/mapper/mapper.hbs +31 -0
- package/dist/templates/module/module.hbs +25 -0
- package/dist/templates/orm-entity/orm-entity.hbs +10 -0
- package/dist/templates/repository/repository.hbs +54 -0
- package/dist/templates/usecase/create-usecase.hbs +14 -0
- package/dist/utils/file.utils.d.ts +27 -0
- package/dist/utils/file.utils.d.ts.map +1 -0
- package/dist/utils/file.utils.js +96 -0
- package/dist/utils/file.utils.js.map +1 -0
- package/dist/utils/naming.utils.d.ts +8 -0
- package/dist/utils/naming.utils.d.ts.map +1 -0
- package/dist/utils/naming.utils.js +47 -0
- package/dist/utils/naming.utils.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ben Ouattara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# NestJS DDD CLI
|
|
2
|
+
|
|
3
|
+
A CLI tool for generating NestJS boilerplate code following pragmatic DDD/CQRS patterns.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
cd nestjs-ddd-cli
|
|
9
|
+
chmod +x install.sh
|
|
10
|
+
./install.sh
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or manually:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm run build
|
|
18
|
+
npm link
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Generate Complete Scaffolding
|
|
24
|
+
|
|
25
|
+
Generate all files for a new entity (entity, repository, mapper, use cases, controller, etc.):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
ddd scaffold Product -m inventory
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Generate Individual Components
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Generate a module
|
|
35
|
+
ddd generate module user-management
|
|
36
|
+
|
|
37
|
+
# Generate an entity
|
|
38
|
+
ddd generate entity User -m user-management
|
|
39
|
+
|
|
40
|
+
# Generate a use case
|
|
41
|
+
ddd generate usecase CreateUser -m user-management
|
|
42
|
+
|
|
43
|
+
# Generate everything for an entity within existing module
|
|
44
|
+
ddd generate all User -m user-management
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Options
|
|
48
|
+
|
|
49
|
+
- `-m, --module <name>`: Specify the module name
|
|
50
|
+
- `-p, --path <path>`: Base path for generation (defaults to current directory)
|
|
51
|
+
- `--skip-orm`: Skip ORM entity generation
|
|
52
|
+
- `--skip-mapper`: Skip mapper generation
|
|
53
|
+
- `--skip-repo`: Skip repository generation
|
|
54
|
+
- `--with-events`: Include domain events
|
|
55
|
+
- `--with-queries`: Include query handlers
|
|
56
|
+
|
|
57
|
+
## Generated Structure
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
modules/
|
|
61
|
+
└── [module-name]/
|
|
62
|
+
├── application/
|
|
63
|
+
│ ├── commands/
|
|
64
|
+
│ ├── controllers/
|
|
65
|
+
│ ├── domain/
|
|
66
|
+
│ │ ├── entities/
|
|
67
|
+
│ │ ├── events/
|
|
68
|
+
│ │ ├── services/
|
|
69
|
+
│ │ └── usecases/
|
|
70
|
+
│ ├── dto/
|
|
71
|
+
│ │ ├── requests/
|
|
72
|
+
│ │ └── responses/
|
|
73
|
+
│ └── queries/
|
|
74
|
+
├── infrastructure/
|
|
75
|
+
│ ├── mappers/
|
|
76
|
+
│ ├── orm-entities/
|
|
77
|
+
│ └── repositories/
|
|
78
|
+
└── [module-name].module.ts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Examples
|
|
82
|
+
|
|
83
|
+
### Create a new feature from scratch
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 1. Generate complete scaffolding for a Policy entity
|
|
87
|
+
ddd scaffold Policy -m policies
|
|
88
|
+
|
|
89
|
+
# 2. Update the generated files with business logic
|
|
90
|
+
# 3. Update index.ts files to export new classes
|
|
91
|
+
# 4. Run the generated migration
|
|
92
|
+
# 5. Import PoliciesModule in app.module.ts
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Add a new entity to existing module
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Generate entity with all related files
|
|
99
|
+
ddd generate all Coverage -m policies
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Add a new use case to existing entity
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Generate a new use case for an existing entity
|
|
106
|
+
ddd generate usecase ApproveCoverage -m policies
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Philosophy
|
|
110
|
+
|
|
111
|
+
This CLI follows the "code once, never touch" philosophy:
|
|
112
|
+
- Each feature is immutable once written
|
|
113
|
+
- Changes create new use cases, not modify existing ones
|
|
114
|
+
- Boilerplate is predictable and consistent
|
|
115
|
+
- Focus on business logic, not structure
|
|
116
|
+
|
|
117
|
+
## After Generation
|
|
118
|
+
|
|
119
|
+
1. **Update index.ts files**: Add new classes to the barrel exports
|
|
120
|
+
2. **Add entity properties**: Define domain properties in entities and DTOs
|
|
121
|
+
3. **Update mappers**: Add field mappings between domain and ORM entities
|
|
122
|
+
4. **Run migrations**: Execute the generated migration files
|
|
123
|
+
5. **Import module**: Add module to app.module.ts imports
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
To modify the CLI:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Make changes
|
|
131
|
+
npm run dev -- generate entity Test -m test
|
|
132
|
+
|
|
133
|
+
# Rebuild
|
|
134
|
+
npm run build
|
|
135
|
+
|
|
136
|
+
# Test globally
|
|
137
|
+
ddd generate entity Test -m test
|
|
138
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-all.d.ts","sourceRoot":"","sources":["../../src/commands/generate-all.ts"],"names":[],"mappings":"AAQA,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,iBAqDjE"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.generateAll = generateAll;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const generate_module_1 = require("./generate-module");
|
|
43
|
+
const generate_entity_1 = require("./generate-entity");
|
|
44
|
+
const generate_usecase_1 = require("./generate-usecase");
|
|
45
|
+
const file_utils_1 = require("../utils/file.utils");
|
|
46
|
+
const naming_utils_1 = require("../utils/naming.utils");
|
|
47
|
+
async function generateAll(entityName, options) {
|
|
48
|
+
console.log(chalk_1.default.blue(`🚀 Generating complete scaffolding for: ${entityName}`));
|
|
49
|
+
const moduleName = options.module || entityName;
|
|
50
|
+
const basePath = options.path || process.cwd();
|
|
51
|
+
const modulePath = (0, file_utils_1.getModulePath)(basePath, moduleName);
|
|
52
|
+
// Check if module exists, create if not
|
|
53
|
+
const moduleFilePath = path.join(modulePath, `${(0, naming_utils_1.toKebabCase)(moduleName)}.module.ts`);
|
|
54
|
+
if (!(await (0, file_utils_1.fileExists)(moduleFilePath))) {
|
|
55
|
+
console.log(chalk_1.default.yellow(`Module ${moduleName} doesn't exist. Creating...`));
|
|
56
|
+
await (0, generate_module_1.generateModule)(moduleName, options);
|
|
57
|
+
}
|
|
58
|
+
// Generate entity with all related files
|
|
59
|
+
await (0, generate_entity_1.generateEntity)(entityName, { ...options, module: moduleName });
|
|
60
|
+
// Generate CRUD use cases
|
|
61
|
+
const useCases = ['Create', 'Update', 'Delete'];
|
|
62
|
+
for (const action of useCases) {
|
|
63
|
+
const useCaseName = `${action}${entityName}`;
|
|
64
|
+
await (0, generate_usecase_1.generateUseCase)(useCaseName, { ...options, module: moduleName });
|
|
65
|
+
}
|
|
66
|
+
// Generate controller
|
|
67
|
+
const templateData = (0, file_utils_1.prepareTemplateData)(entityName, moduleName);
|
|
68
|
+
const controllerTemplatePath = path.join(__dirname, '../templates/controller/controller.hbs');
|
|
69
|
+
const controllerOutputPath = path.join(modulePath, 'application/controllers', `${(0, naming_utils_1.toKebabCase)(entityName)}.controller.ts`);
|
|
70
|
+
await (0, file_utils_1.generateFromTemplate)(controllerTemplatePath, controllerOutputPath, templateData);
|
|
71
|
+
// Generate migration file
|
|
72
|
+
await generateMigration(entityName, basePath);
|
|
73
|
+
console.log(chalk_1.default.green(`\n✅ Complete scaffolding generated successfully!`));
|
|
74
|
+
console.log(chalk_1.default.cyan(`\n📁 Generated files:`));
|
|
75
|
+
console.log(` Module: ${modulePath}`);
|
|
76
|
+
console.log(` Entity: ${entityName}`);
|
|
77
|
+
console.log(` Use Cases: Create, Update, Delete`);
|
|
78
|
+
console.log(` Controller: ${entityName}Controller`);
|
|
79
|
+
console.log(` Repository: ${entityName}Repository`);
|
|
80
|
+
console.log(` Mapper: ${entityName}Mapper`);
|
|
81
|
+
console.log(chalk_1.default.yellow(`\n⚠️ Next steps:`));
|
|
82
|
+
console.log(` 1. Update the index.ts files in each directory`);
|
|
83
|
+
console.log(` 2. Add properties to your entity and DTOs`);
|
|
84
|
+
console.log(` 3. Update the mapper with proper field mappings`);
|
|
85
|
+
console.log(` 4. Run the migration to create the database table`);
|
|
86
|
+
console.log(` 5. Import ${moduleName}Module in your app.module.ts`);
|
|
87
|
+
}
|
|
88
|
+
async function generateMigration(entityName, basePath) {
|
|
89
|
+
const timestamp = Date.now();
|
|
90
|
+
const tableName = (0, naming_utils_1.toKebabCase)(entityName).replace(/-/g, '_') + 's';
|
|
91
|
+
const migrationName = `create_${tableName}_table`;
|
|
92
|
+
const fileName = `${timestamp}-${migrationName}.ts`;
|
|
93
|
+
const content = `import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
|
94
|
+
|
|
95
|
+
export class Create${entityName}Table${timestamp} implements MigrationInterface {
|
|
96
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
97
|
+
await queryRunner.createTable(
|
|
98
|
+
new Table({
|
|
99
|
+
name: "${tableName}",
|
|
100
|
+
columns: [
|
|
101
|
+
{
|
|
102
|
+
name: "id",
|
|
103
|
+
type: "uuid",
|
|
104
|
+
isPrimary: true,
|
|
105
|
+
generationStrategy: "uuid",
|
|
106
|
+
default: "uuid_generate_v4()",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "is_active",
|
|
110
|
+
type: "boolean",
|
|
111
|
+
default: true,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "created_at",
|
|
115
|
+
type: "timestamp",
|
|
116
|
+
default: "CURRENT_TIMESTAMP",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "updated_at",
|
|
120
|
+
type: "timestamp",
|
|
121
|
+
default: "CURRENT_TIMESTAMP",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "deleted_at",
|
|
125
|
+
type: "timestamp",
|
|
126
|
+
isNullable: true,
|
|
127
|
+
},
|
|
128
|
+
// Add your custom columns here
|
|
129
|
+
],
|
|
130
|
+
}),
|
|
131
|
+
true,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
136
|
+
await queryRunner.dropTable("${tableName}");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
const migrationPath = path.join(basePath, 'src/migrations', fileName);
|
|
141
|
+
await require('../utils/file.utils').writeFile(migrationPath, content);
|
|
142
|
+
console.log(chalk_1.default.green(` Migration: ${fileName}`));
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=generate-all.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-all.js","sourceRoot":"","sources":["../../src/commands/generate-all.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,kCAqDC;AA7DD,2CAA6B;AAC7B,kDAA0B;AAC1B,uDAAmD;AACnD,uDAAmD;AACnD,yDAAqD;AACrD,oDAA2G;AAC3G,wDAAoD;AAE7C,KAAK,UAAU,WAAW,CAAC,UAAkB,EAAE,OAAY;IAChE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,2CAA2C,UAAU,EAAE,CAAC,CAAC,CAAC;IAEjF,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;IAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,0BAAa,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAEvD,wCAAwC;IACxC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAA,0BAAW,EAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACrF,IAAI,CAAC,CAAC,MAAM,IAAA,uBAAU,EAAC,cAAc,CAAC,CAAC,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,UAAU,UAAU,6BAA6B,CAAC,CAAC,CAAC;QAC7E,MAAM,IAAA,gCAAc,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,yCAAyC;IACzC,MAAM,IAAA,gCAAc,EAAC,UA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EAAE,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-entity.d.ts","sourceRoot":"","sources":["../../src/commands/generate-entity.ts"],"names":[],"mappings":"AAKA,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,iBAkEpE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.generateEntity = generateEntity;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const file_utils_1 = require("../utils/file.utils");
|
|
43
|
+
const naming_utils_1 = require("../utils/naming.utils");
|
|
44
|
+
async function generateEntity(entityName, options) {
|
|
45
|
+
if (!options.module) {
|
|
46
|
+
throw new Error('Module name is required. Use -m or --module option.');
|
|
47
|
+
}
|
|
48
|
+
console.log(chalk_1.default.blue(`Generating entity: ${entityName}`));
|
|
49
|
+
const basePath = options.path || process.cwd();
|
|
50
|
+
const modulePath = (0, file_utils_1.getModulePath)(basePath, options.module);
|
|
51
|
+
const templateData = (0, file_utils_1.prepareTemplateData)(entityName, options.module);
|
|
52
|
+
// Generate domain entity
|
|
53
|
+
const entityTemplatePath = path.join(__dirname, '../templates/entity/entity.hbs');
|
|
54
|
+
const entityOutputPath = path.join(modulePath, 'application/domain/entities', `${(0, naming_utils_1.toKebabCase)(entityName)}.entity.ts`);
|
|
55
|
+
if (await (0, file_utils_1.fileExists)(entityOutputPath)) {
|
|
56
|
+
console.log(chalk_1.default.yellow(`Entity ${entityName} already exists. Skipping...`));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
await (0, file_utils_1.generateFromTemplate)(entityTemplatePath, entityOutputPath, templateData);
|
|
60
|
+
// Generate ORM entity if not skipped
|
|
61
|
+
if (!options.skipOrm) {
|
|
62
|
+
const ormTemplatePath = path.join(__dirname, '../templates/orm-entity/orm-entity.hbs');
|
|
63
|
+
const ormOutputPath = path.join(modulePath, 'infrastructure/orm-entities', `${(0, naming_utils_1.toKebabCase)(entityName)}.orm-entity.ts`);
|
|
64
|
+
await (0, file_utils_1.generateFromTemplate)(ormTemplatePath, ormOutputPath, templateData);
|
|
65
|
+
}
|
|
66
|
+
// Generate mapper if not skipped
|
|
67
|
+
if (!options.skipMapper) {
|
|
68
|
+
const mapperTemplatePath = path.join(__dirname, '../templates/mapper/mapper.hbs');
|
|
69
|
+
const mapperOutputPath = path.join(modulePath, 'infrastructure/mappers', `${(0, naming_utils_1.toKebabCase)(entityName)}.mapper.ts`);
|
|
70
|
+
await (0, file_utils_1.generateFromTemplate)(mapperTemplatePath, mapperOutputPath, templateData);
|
|
71
|
+
}
|
|
72
|
+
// Generate repository if not skipped
|
|
73
|
+
if (!options.skipRepo) {
|
|
74
|
+
const repoTemplatePath = path.join(__dirname, '../templates/repository/repository.hbs');
|
|
75
|
+
const repoOutputPath = path.join(modulePath, 'infrastructure/repositories', `${(0, naming_utils_1.toKebabCase)(entityName)}.repository.ts`);
|
|
76
|
+
await (0, file_utils_1.generateFromTemplate)(repoTemplatePath, repoOutputPath, templateData);
|
|
77
|
+
}
|
|
78
|
+
// Update index files
|
|
79
|
+
await updateIndexFiles(modulePath, entityName, options);
|
|
80
|
+
console.log(chalk_1.default.green(`✅ Entity ${entityName} generated successfully!`));
|
|
81
|
+
}
|
|
82
|
+
async function updateIndexFiles(modulePath, entityName, options) {
|
|
83
|
+
// This would update the index.ts files to include the new exports
|
|
84
|
+
// For now, we'll just log a reminder
|
|
85
|
+
console.log(chalk_1.default.yellow(`\n⚠️ Remember to update the following index files:`));
|
|
86
|
+
console.log(` - application/domain/entities/index.ts`);
|
|
87
|
+
if (!options.skipOrm) {
|
|
88
|
+
console.log(` - infrastructure/orm-entities/index.ts`);
|
|
89
|
+
}
|
|
90
|
+
if (!options.skipMapper) {
|
|
91
|
+
console.log(` - infrastructure/mappers/index.ts`);
|
|
92
|
+
}
|
|
93
|
+
if (!options.skipRepo) {
|
|
94
|
+
console.log(` - infrastructure/repositories/index.ts`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=generate-entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-entity.js","sourceRoot":"","sources":["../../src/commands/generate-entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wCAkEC;AAvED,2CAA6B;AAC7B,kDAA0B;AAC1B,oDAA2G;AAC3G,wDAAoD;AAE7C,KAAK,UAAU,cAAc,CAAC,UAAkB,EAAE,OAAY;IACnE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,sBAAsB,UAAU,EAAE,CAAC,CAAC,CAAC;IAE5D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,0BAAa,EAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,YAAY,GAAG,IAAA,gCAAmB,EAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAErE,yBAAyB;IACzB,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gCAAgC,CAAC,CAAC;IAClF,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAChC,UAAU,EACV,6BAA6B,EAC7B,GAAG,IAAA,0BAAW,EAAC,UAAU,CAAC,YAAY,CACvC,CAAC;IAEF,IAAI,MAAM,IAAA,uBAAU,EAAC,gBAAgB,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,UAAU,UAAU,8BAA8B,CAAC,CAAC,CAAC;QAC9E,OAA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AC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAExD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,YAAY,UAAU,0BAA0B,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,UAAkB,EAAE,UAAkB,EAAE,OAAY;IAClF,kEAAkE;IAClE,qCAAqC;IACrC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,qDAAqD,CAAC,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IACzD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-module.d.ts","sourceRoot":"","sources":["../../src/commands/generate-module.ts"],"names":[],"mappings":"AAKA,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,iBAiDpE"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.generateModule = generateModule;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const file_utils_1 = require("../utils/file.utils");
|
|
43
|
+
const naming_utils_1 = require("../utils/naming.utils");
|
|
44
|
+
async function generateModule(moduleName, options) {
|
|
45
|
+
console.log(chalk_1.default.blue(`Generating module: ${moduleName}`));
|
|
46
|
+
const basePath = options.path || process.cwd();
|
|
47
|
+
const modulePath = (0, file_utils_1.getModulePath)(basePath, moduleName);
|
|
48
|
+
// Create module directory structure
|
|
49
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/commands'));
|
|
50
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/controllers'));
|
|
51
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/domain/entities'));
|
|
52
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/domain/events'));
|
|
53
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/domain/services'));
|
|
54
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/domain/usecases'));
|
|
55
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/dto/requests'));
|
|
56
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/dto/responses'));
|
|
57
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'application/queries'));
|
|
58
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'infrastructure/mappers'));
|
|
59
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'infrastructure/orm-entities'));
|
|
60
|
+
await (0, file_utils_1.ensureDir)(path.join(modulePath, 'infrastructure/repositories'));
|
|
61
|
+
// Generate module file
|
|
62
|
+
const templateData = (0, file_utils_1.prepareTemplateData)(moduleName, moduleName);
|
|
63
|
+
const templatePath = path.join(__dirname, '../templates/module/module.hbs');
|
|
64
|
+
const outputPath = path.join(modulePath, `${(0, naming_utils_1.toKebabCase)(moduleName)}.module.ts`);
|
|
65
|
+
await (0, file_utils_1.generateFromTemplate)(templatePath, outputPath, templateData);
|
|
66
|
+
// Create empty index files
|
|
67
|
+
const indexPaths = [
|
|
68
|
+
'application/commands/index.ts',
|
|
69
|
+
'application/controllers/index.ts',
|
|
70
|
+
'application/domain/entities/index.ts',
|
|
71
|
+
'application/domain/events/index.ts',
|
|
72
|
+
'application/domain/services/index.ts',
|
|
73
|
+
'application/domain/usecases/index.ts',
|
|
74
|
+
'application/dto/requests/index.ts',
|
|
75
|
+
'application/dto/responses/index.ts',
|
|
76
|
+
'application/queries/index.ts',
|
|
77
|
+
'infrastructure/mappers/index.ts',
|
|
78
|
+
'infrastructure/orm-entities/index.ts',
|
|
79
|
+
'infrastructure/repositories/index.ts',
|
|
80
|
+
];
|
|
81
|
+
for (const indexPath of indexPaths) {
|
|
82
|
+
const arrayName = getArrayNameFromPath(indexPath);
|
|
83
|
+
await generateIndexFile(path.join(modulePath, indexPath), arrayName);
|
|
84
|
+
}
|
|
85
|
+
console.log(chalk_1.default.green(`✅ Module ${moduleName} generated successfully!`));
|
|
86
|
+
}
|
|
87
|
+
function getArrayNameFromPath(indexPath) {
|
|
88
|
+
const parts = indexPath.split('/');
|
|
89
|
+
const lastPart = parts[parts.length - 2];
|
|
90
|
+
const mapping = {
|
|
91
|
+
'commands': 'CommandHandlers',
|
|
92
|
+
'controllers': 'Controllers',
|
|
93
|
+
'entities': 'Entities',
|
|
94
|
+
'events': 'Events',
|
|
95
|
+
'services': 'Services',
|
|
96
|
+
'usecases': 'UseCases',
|
|
97
|
+
'requests': 'Requests',
|
|
98
|
+
'responses': 'Responses',
|
|
99
|
+
'queries': 'Queries',
|
|
100
|
+
'mappers': 'Mappers',
|
|
101
|
+
'orm-entities': 'OrmEntities',
|
|
102
|
+
'repositories': 'Repositories',
|
|
103
|
+
};
|
|
104
|
+
return mapping[lastPart] || 'Exports';
|
|
105
|
+
}
|
|
106
|
+
async function generateIndexFile(filePath, arrayName) {
|
|
107
|
+
const content = `export const ${arrayName} = [];\n`;
|
|
108
|
+
await (0, file_utils_1.ensureDir)(path.dirname(filePath));
|
|
109
|
+
await require('../utils/file.utils').writeFile(filePath, content);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=generate-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-module.js","sourceRoot":"","sources":["../../src/commands/generate-module.ts"],"names":[],"mappings":";;;;;;;;;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AC;AAED,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEzC,MAAM,OAAO,GAA2B;QACtC,UAAU,EAAE,iBAAiB;QAC7B,aAAa,EAAE,aAAa;QAC5B,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,UAAU;QACtB,WAAW,EAAE,WAAW;QACxB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,cAAc,EAAE,aAAa;QAC7B,cAAc,EAAE,cAAc;KAC/B,CAAC;IAEF,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC;AACxC,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,QAAgB,EAAE,SAAiB;IAClE,MAAM,OAAO,GAAG,gBAAgB,SAAS,UAAU,CAAC;IACpD,MAAM,IAAA,sBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxC,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-usecase.d.ts","sourceRoot":"","sources":["../../src/commands/generate-usecase.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,iBAiDtE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.generateUseCase = generateUseCase;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const file_utils_1 = require("../utils/file.utils");
|
|
43
|
+
const naming_utils_1 = require("../utils/naming.utils");
|
|
44
|
+
async function generateUseCase(useCaseName, options) {
|
|
45
|
+
if (!options.module) {
|
|
46
|
+
throw new Error('Module name is required. Use -m or --module option.');
|
|
47
|
+
}
|
|
48
|
+
console.log(chalk_1.default.blue(`Generating use case: ${useCaseName}`));
|
|
49
|
+
const basePath = options.path || process.cwd();
|
|
50
|
+
const modulePath = (0, file_utils_1.getModulePath)(basePath, options.module);
|
|
51
|
+
// Extract entity name from use case name (e.g., CreateUser -> User)
|
|
52
|
+
const entityName = extractEntityName(useCaseName);
|
|
53
|
+
const templateData = (0, file_utils_1.prepareTemplateData)(entityName, options.module);
|
|
54
|
+
// Generate use case
|
|
55
|
+
const useCaseTemplatePath = path.join(__dirname, '../templates/usecase/create-usecase.hbs');
|
|
56
|
+
const useCaseOutputPath = path.join(modulePath, 'application/domain/usecases', `${(0, naming_utils_1.toKebabCase)(useCaseName)}.use-case.ts`);
|
|
57
|
+
await (0, file_utils_1.generateFromTemplate)(useCaseTemplatePath, useCaseOutputPath, templateData);
|
|
58
|
+
// Generate command
|
|
59
|
+
const commandTemplatePath = path.join(__dirname, '../templates/command/create-command.hbs');
|
|
60
|
+
const commandOutputPath = path.join(modulePath, 'application/commands', `${(0, naming_utils_1.toKebabCase)(useCaseName)}.command.ts`);
|
|
61
|
+
await (0, file_utils_1.generateFromTemplate)(commandTemplatePath, commandOutputPath, templateData);
|
|
62
|
+
// Generate DTO
|
|
63
|
+
const dtoTemplatePath = path.join(__dirname, '../templates/dto/create-dto.hbs');
|
|
64
|
+
const dtoOutputPath = path.join(modulePath, 'application/dto/requests', `${(0, naming_utils_1.toKebabCase)(useCaseName)}.dto.ts`);
|
|
65
|
+
await (0, file_utils_1.generateFromTemplate)(dtoTemplatePath, dtoOutputPath, templateData);
|
|
66
|
+
console.log(chalk_1.default.green(`✅ Use case ${useCaseName} generated successfully!`));
|
|
67
|
+
console.log(chalk_1.default.yellow(`\n⚠️ Remember to update the following index files:`));
|
|
68
|
+
console.log(` - application/domain/usecases/index.ts`);
|
|
69
|
+
console.log(` - application/commands/index.ts`);
|
|
70
|
+
console.log(` - application/dto/requests/index.ts`);
|
|
71
|
+
}
|
|
72
|
+
function extractEntityName(useCaseName) {
|
|
73
|
+
// Remove common prefixes
|
|
74
|
+
const prefixes = ['Create', 'Update', 'Delete', 'Get', 'Find', 'List'];
|
|
75
|
+
let entityName = useCaseName;
|
|
76
|
+
for (const prefix of prefixes) {
|
|
77
|
+
if (useCaseName.startsWith(prefix)) {
|
|
78
|
+
entityName = useCaseName.substring(prefix.length);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return entityName;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=generate-usecase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-usecase.js","sourceRoot":"","sources":["../../src/commands/generate-usecase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,0CAiDC;AAtDD,2CAA6B;AAC7B,kDAA0B;AAC1B,oDAA+F;AAC/F,wDAAkE;AAE3D,KAAK,UAAU,eAAe,CAAC,WAAmB,EAAE,OAAY;IACrE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAC,CAAC;IAE/D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,0BAAa,EAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D,oEAAoE;IACpE,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,IAAA,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