@saulpaulus17/node-module-generator 2.0.8 โ 3.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.
- package/README.md +13 -12
- package/bin/cli.js +17 -6
- package/commands/dto.command.js +3 -3
- package/commands/module.command.js +2 -2
- package/commands/repository.command.js +6 -6
- package/commands/resource.command.js +3 -3
- package/commands/usecase.command.js +2 -2
- package/generator/dto.generator.js +28 -17
- package/generator/module.generator.js +56 -55
- package/generator/repository.generator.js +37 -29
- package/generator/resource.generator.js +55 -54
- package/generator/usecase.generator.js +33 -21
- package/package.json +3 -3
- package/templates/module/controller.test.ejs +1 -1
- package/templates/module/di.ejs +2 -9
- package/templates/module/route.ejs +2 -1
- package/templates/module/usecase.test.ejs +1 -1
- package/utils/case.util.js +24 -7
- package/utils/file.util.js +46 -0
- package/utils/logger.util.js +30 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/custom.md +0 -10
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/ci.yml +0 -28
- package/.github/workflows/release.yml +0 -39
- package/DOCS_STEPS.md +0 -40
- package/assets/banner.png +0 -0
- package/release.yml +0 -0
- package/src/modules/Auth/Auth.module.js +0 -15
- package/src/modules/Auth/application/dtos/auth.dto.js +0 -10
- package/src/modules/Auth/application/usecases/AuthUseCase.js +0 -12
- package/src/modules/Auth/application/usecases/AuthUseCase.test.js +0 -30
- package/src/modules/Auth/domain/entities/Auth.js +0 -5
- package/src/modules/Auth/domain/repositories/AuthRepository.js +0 -9
- package/src/modules/Auth/infrastructure/repositories/PrismaAuthRepository.js +0 -15
- package/src/modules/Auth/interfaces/controllers/AuthController.js +0 -15
- package/src/modules/Auth/interfaces/controllers/AuthController.test.js +0 -49
- package/src/modules/Auth/interfaces/routes/auth.routes.js +0 -9
- package/src/modules/Auth/package.json +0 -3
- package/src/modules/order/application/usecases/create-order.usecase.js +0 -15
- package/src/modules/order/application/usecases/create-order.usecase.test.js +0 -26
- package/src/modules/order/domain/entities/order.entity.js +0 -8
- package/src/modules/order/domain/repositories/order.repository.interface.js +0 -11
- package/src/modules/order/infrastructure/repositories/order.repository.impl.js +0 -23
- package/src/modules/order/infrastructure/validation/create-order.schema.js +0 -7
- package/src/modules/order/interfaces/controllers/order.controller.js +0 -16
- package/src/modules/order/interfaces/controllers/order.controller.test.js +0 -46
- package/src/modules/order/interfaces/routes/order.routes.js +0 -9
- package/src/modules/order/order.module.js +0 -16
- package/src/modules/product/application/usecases/getProduct.usecase.js +0 -15
- package/src/modules/product/application/usecases/getProduct.usecase.test.js +0 -26
- package/src/modules/product/domain/entities/product.entity.js +0 -8
- package/src/modules/product/domain/repositories/product.repository.interface.js +0 -11
- package/src/modules/product/infrastructure/repositories/product.repository.impl.js +0 -23
- package/src/modules/product/infrastructure/validation/getProduct.schema.js +0 -7
- package/src/modules/product/product.module.js +0 -5
- package/src/modules/user/application/usecases/create-user.usecase.js +0 -15
- package/src/modules/user/application/usecases/create-user.usecase.test.js +0 -26
- package/src/modules/user/domain/entities/user.entity.js +0 -8
- package/src/modules/user/domain/repositories/user.repository.interface.js +0 -11
- package/src/modules/user/infrastructure/repositories/user.repository.impl.js +0 -23
- package/src/modules/user/infrastructure/validation/create-user.schema.js +0 -7
- package/src/modules/user/interfaces/controllers/user.controller.js +0 -16
- package/src/modules/user/interfaces/controllers/user.controller.test.js +0 -46
- package/src/modules/user/interfaces/routes/user.routes.js +0 -9
- package/src/modules/user/user.module.js +0 -16
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ graph TD
|
|
|
49
49
|
- ๐ **Clean Architecture by Design**: Strict separation into Domain, Application, Infrastructure, and Interface layers.
|
|
50
50
|
- ๐ **Native Dependency Injection**: Fully pre-configured for **Awilix**, providing seamless DI management.
|
|
51
51
|
- ๐งช **Test-Ready Scaffolding**: Automatically generates **Jest** test suites for Controllers and Use Cases.
|
|
52
|
-
- ๐ **
|
|
52
|
+
- ๐ **Full ESM Support**: Native support for **ECMAScript Modules (ESM)** with consistent **camelCase** file naming.
|
|
53
53
|
- ๐ค **Granular Control**: Generate full modules or individual components (UseCases, Repos, DTOs) without disrupting existing code.
|
|
54
54
|
|
|
55
55
|
---
|
|
@@ -127,25 +127,25 @@ Scaffolding a module (e.g., `nmg module Product`) produces the following industr
|
|
|
127
127
|
```text
|
|
128
128
|
src/modules/Product/
|
|
129
129
|
โโโ application/
|
|
130
|
-
โ โโโ dtos/ # DTO schemas (e.g.,
|
|
130
|
+
โ โโโ dtos/ # DTO schemas (e.g., productDto.js)
|
|
131
131
|
โ โโโ usecases/ # Business orchestration
|
|
132
|
-
โ โโโ
|
|
133
|
-
โ โโโ
|
|
132
|
+
โ โโโ productUseCase.js # Logic implementation
|
|
133
|
+
โ โโโ productUseCase.test.js # Unit tests
|
|
134
134
|
โโโ domain/
|
|
135
135
|
โ โโโ entities/ # Business entity definitions
|
|
136
|
-
โ โ โโโ
|
|
136
|
+
โ โ โโโ productEntity.js
|
|
137
137
|
โ โโโ repositories/ # Repository Interface (Contracts)
|
|
138
|
-
โ โโโ
|
|
138
|
+
โ โโโ productRepository.js
|
|
139
139
|
โโโ infrastructure/
|
|
140
140
|
โ โโโ repositories/ # Implementation (default: Prisma)
|
|
141
|
-
โ โ โโโ
|
|
141
|
+
โ โ โโโ prismaProductRepository.js
|
|
142
142
|
โโโ interfaces/
|
|
143
143
|
โ โโโ controllers/ # Express handlers
|
|
144
|
-
โ โ โโโ
|
|
145
|
-
โ โ โโโ
|
|
144
|
+
โ โ โโโ productController.js
|
|
145
|
+
โ โ โโโ productController.test.js
|
|
146
146
|
โ โโโ routes/ # Express routes & method binding
|
|
147
|
-
โ โโโ
|
|
148
|
-
โโโ
|
|
147
|
+
โ โโโ productRoutes.js
|
|
148
|
+
โโโ product.module.js # Central Awilix Module Registration
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
---
|
|
@@ -157,7 +157,8 @@ To finalize your new module integration, follow these standard steps:
|
|
|
157
157
|
1. **DI Registration**: Open `src/container.js` and register any specific repository aliases or scoped usecases.
|
|
158
158
|
2. **Route Mounting**: Mount the generated router in `src/app.js`:
|
|
159
159
|
```javascript
|
|
160
|
-
|
|
160
|
+
import productRoutes from './modules/Product/interfaces/routes/productRoutes.js';
|
|
161
|
+
app.use('/api/v1/product', productRoutes);
|
|
161
162
|
```
|
|
162
163
|
3. **Detailed Implementation**: Build out the specific logic in the generated templates (which are already integrated via Awilix).
|
|
163
164
|
|
package/bin/cli.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import moduleCommand from "../commands/module.command.js";
|
|
5
|
+
import usecaseCommand from "../commands/usecase.command.js";
|
|
6
|
+
import resourceCommand from "../commands/resource.command.js";
|
|
7
|
+
import repositoryCommand from "../commands/repository.command.js";
|
|
8
|
+
import dtoCommand from "../commands/dto.command.js";
|
|
9
|
+
|
|
4
10
|
const program = new Command();
|
|
5
11
|
|
|
6
12
|
program.name("nmg").version("1.0.0").description("Clean nodejs CLI");
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
process.on("unhandledRejection", (err) => {
|
|
15
|
+
console.error("โ FATAL ERROR: ", err.stack || err);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
moduleCommand(program);
|
|
20
|
+
usecaseCommand(program);
|
|
21
|
+
resourceCommand(program);
|
|
22
|
+
repositoryCommand(program);
|
|
23
|
+
dtoCommand(program);
|
|
13
24
|
|
|
14
25
|
program.parse();
|
package/commands/dto.command.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import generateDto from "../generator/dto.generator.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default (program) => {
|
|
4
4
|
program
|
|
5
5
|
.command("dto <name>")
|
|
6
|
-
.description("Create a new DTO
|
|
6
|
+
.description("Create a new DTO inside an existing module")
|
|
7
7
|
.option("-m, --module <moduleName>", "Specify the target module")
|
|
8
8
|
.action((name, options) => {
|
|
9
9
|
if (!options.module) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import generateModule from "../generator/module.generator.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default (program) => {
|
|
4
4
|
program
|
|
5
5
|
.command("module <name>")
|
|
6
6
|
.description("Create a new module")
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import generateRepository from "../generator/repository.generator.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default (program) => {
|
|
4
4
|
program
|
|
5
|
-
.command("repository <
|
|
6
|
-
.description("Create
|
|
7
|
-
.action((
|
|
8
|
-
generateRepository(
|
|
5
|
+
.command("repository <name>")
|
|
6
|
+
.description("Create a new repository inside an existing module")
|
|
7
|
+
.action((name) => {
|
|
8
|
+
generateRepository(name);
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import generateResource from "../generator/resource.generator.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default (program) => {
|
|
4
4
|
program
|
|
5
5
|
.command("resource <name>")
|
|
6
|
-
.description("Create a
|
|
6
|
+
.description("Create a complete resource (CRUD)")
|
|
7
7
|
.action((name) => {
|
|
8
8
|
generateResource(name);
|
|
9
9
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import generateUsecase from "../generator/usecase.generator.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default (program) => {
|
|
4
4
|
program
|
|
5
5
|
.command("usecase <name>")
|
|
6
6
|
.description("Create a new usecase inside an existing module")
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
|
+
import FileUtil from "../utils/file.util.js";
|
|
4
|
+
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export default async function (schemaName, moduleName) {
|
|
7
|
+
try {
|
|
8
|
+
Logger.info(`Starting generation for DTO: ${schemaName} in module: ${moduleName}`);
|
|
9
|
+
const basePath = path.join(process.cwd(), "src/modules", moduleName);
|
|
10
|
+
const dtoDir = "application/dtos";
|
|
11
|
+
|
|
12
|
+
FileUtil.ensureDirectories(basePath, [dtoDir]);
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const templateData = {
|
|
15
|
+
name: moduleName,
|
|
16
|
+
className: pascalCase(schemaName),
|
|
17
|
+
camelName: camelCase(schemaName),
|
|
18
|
+
moduleCamelName: camelCase(moduleName),
|
|
19
|
+
};
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
await FileUtil.renderAndWrite(
|
|
22
|
+
"module/dto.ejs",
|
|
23
|
+
templateData,
|
|
24
|
+
path.join(basePath, dtoDir, `${camelCase(schemaName)}Dto.js`)
|
|
25
|
+
);
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
}
|
|
27
|
+
Logger.success(`DTO ${schemaName} generated inside module ${moduleName} at application/dtos.`);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
Logger.error(`Failed to generate DTO ${schemaName}`, error);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,55 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
|
+
import FileUtil from "../utils/file.util.js";
|
|
4
|
+
import Logger from "../utils/logger.util.js";
|
|
5
|
+
|
|
6
|
+
export default async function (name) {
|
|
7
|
+
try {
|
|
8
|
+
Logger.info(`Starting generation for module: ${name}`);
|
|
9
|
+
const basePath = path.join(process.cwd(), "src/modules", name);
|
|
10
|
+
|
|
11
|
+
const dirs = [
|
|
12
|
+
"domain/entities",
|
|
13
|
+
"domain/repositories",
|
|
14
|
+
"application/usecases",
|
|
15
|
+
"application/dtos",
|
|
16
|
+
"infrastructure/repositories",
|
|
17
|
+
"interfaces/controllers",
|
|
18
|
+
"interfaces/routes",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// Create directories
|
|
22
|
+
FileUtil.ensureDirectories(basePath, dirs);
|
|
23
|
+
|
|
24
|
+
const templateData = {
|
|
25
|
+
name,
|
|
26
|
+
className: pascalCase(name),
|
|
27
|
+
camelName: camelCase(name),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const filesToGenerate = [
|
|
31
|
+
{ tpl: "module/controller.ejs", out: `interfaces/controllers/${camelCase(name)}Controller.js` },
|
|
32
|
+
{ tpl: "module/controller.test.ejs", out: `interfaces/controllers/${camelCase(name)}Controller.test.js` },
|
|
33
|
+
{ tpl: "module/route.ejs", out: `interfaces/routes/${camelCase(name)}Routes.js` },
|
|
34
|
+
{ tpl: "module/usecase.ejs", out: `application/usecases/${camelCase(name)}UseCase.js` },
|
|
35
|
+
{ tpl: "module/usecase.test.ejs", out: `application/usecases/${camelCase(name)}UseCase.test.js` },
|
|
36
|
+
{ tpl: "module/entity.ejs", out: `domain/entities/${camelCase(name)}Entity.js` },
|
|
37
|
+
{ tpl: "module/repository.interface.ejs", out: `domain/repositories/${camelCase(name)}Repository.js` },
|
|
38
|
+
{ tpl: "module/repository.impl.ejs", out: `infrastructure/repositories/prisma${pascalCase(name)}Repository.js` },
|
|
39
|
+
{ tpl: "module/dto.ejs", out: `application/dtos/${camelCase(name)}Dto.js` },
|
|
40
|
+
{ tpl: "module/di.ejs", out: `${camelCase(name)}.module.js` }
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
for (const file of filesToGenerate) {
|
|
44
|
+
await FileUtil.renderAndWrite(
|
|
45
|
+
file.tpl,
|
|
46
|
+
templateData,
|
|
47
|
+
path.join(basePath, file.out)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Logger.success(`Module ${name} generated successfully!`);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
Logger.error(`Failed to generate module ${name}`, error);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
|
+
import FileUtil from "../utils/file.util.js";
|
|
4
|
+
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export default async function (moduleName) {
|
|
7
|
+
try {
|
|
8
|
+
Logger.info(`Starting repository pattern generation for module: ${moduleName}`);
|
|
9
|
+
const basePath = path.join(process.cwd(), "src/modules", moduleName);
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const dirs = [
|
|
12
|
+
"domain/entities",
|
|
13
|
+
"domain/repositories",
|
|
14
|
+
"infrastructure/repositories",
|
|
15
|
+
];
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
fs.ensureDirSync(repoInterfaceDir);
|
|
15
|
-
fs.ensureDirSync(repoImplDir);
|
|
17
|
+
FileUtil.ensureDirectories(basePath, dirs);
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const templateData = {
|
|
20
|
+
name: moduleName,
|
|
21
|
+
className: pascalCase(moduleName),
|
|
22
|
+
camelName: camelCase(moduleName),
|
|
23
|
+
};
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
fs.writeFileSync(path.join(basePath, outputPath), templateContent);
|
|
29
|
-
};
|
|
25
|
+
const filesToGenerate = [
|
|
26
|
+
{ tpl: "module/entity.ejs", out: `domain/entities/${camelCase(moduleName)}Entity.js` },
|
|
27
|
+
{ tpl: "module/repository.interface.ejs", out: `domain/repositories/${camelCase(moduleName)}Repository.js` },
|
|
28
|
+
{ tpl: "module/repository.impl.ejs", out: `infrastructure/repositories/prisma${pascalCase(moduleName)}Repository.js` }
|
|
29
|
+
];
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
for (const file of filesToGenerate) {
|
|
32
|
+
await FileUtil.renderAndWrite(
|
|
33
|
+
file.tpl,
|
|
34
|
+
templateData,
|
|
35
|
+
path.join(basePath, file.out)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
}
|
|
39
|
+
Logger.success(`Repository patterns for ${moduleName} generated successfully.`);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
Logger.error(`Failed to generate repository patterns for ${moduleName}`, error);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
|
+
import FileUtil from "../utils/file.util.js";
|
|
4
|
+
import Logger from "../utils/logger.util.js";
|
|
5
|
+
|
|
6
|
+
export default async function (name) {
|
|
7
|
+
try {
|
|
8
|
+
Logger.info(`Starting generation for resource: ${name}`);
|
|
9
|
+
const basePath = path.join(process.cwd(), "src/modules", name);
|
|
10
|
+
|
|
11
|
+
const dirs = [
|
|
12
|
+
"domain/entities",
|
|
13
|
+
"domain/repositories",
|
|
14
|
+
"application/usecases",
|
|
15
|
+
"application/dtos",
|
|
16
|
+
"infrastructure/repositories",
|
|
17
|
+
"interfaces/controllers",
|
|
18
|
+
"interfaces/routes",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
FileUtil.ensureDirectories(basePath, dirs);
|
|
22
|
+
|
|
23
|
+
const templateData = {
|
|
24
|
+
name,
|
|
25
|
+
className: pascalCase(name),
|
|
26
|
+
camelName: camelCase(name),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const filesToGenerate = [
|
|
30
|
+
{ tpl: "module/controller.ejs", out: `interfaces/controllers/${camelCase(name)}Controller.js` },
|
|
31
|
+
{ tpl: "module/controller.test.ejs", out: `interfaces/controllers/${camelCase(name)}Controller.test.js` },
|
|
32
|
+
{ tpl: "module/route.ejs", out: `interfaces/routes/${camelCase(name)}Routes.js` },
|
|
33
|
+
{ tpl: "module/usecase.ejs", out: `application/usecases/${camelCase(name)}UseCase.js` },
|
|
34
|
+
{ tpl: "module/usecase.test.ejs", out: `application/usecases/${camelCase(name)}UseCase.test.js` },
|
|
35
|
+
{ tpl: "module/entity.ejs", out: `domain/entities/${camelCase(name)}Entity.js` },
|
|
36
|
+
{ tpl: "module/repository.interface.ejs", out: `domain/repositories/${camelCase(name)}Repository.js` },
|
|
37
|
+
{ tpl: "module/repository.impl.ejs", out: `infrastructure/repositories/prisma${pascalCase(name)}Repository.js` },
|
|
38
|
+
{ tpl: "module/dto.ejs", out: `application/dtos/${camelCase(name)}Dto.js` },
|
|
39
|
+
{ tpl: "module/di.ejs", out: `${camelCase(name)}.module.js` }
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
for (const file of filesToGenerate) {
|
|
43
|
+
await FileUtil.renderAndWrite(
|
|
44
|
+
file.tpl,
|
|
45
|
+
templateData,
|
|
46
|
+
path.join(basePath, file.out)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Logger.success(`Resource ${name} generated successfully with Clean Architecture and Awilix DI!`);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
Logger.error(`Failed to generate resource ${name}`, error);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,26 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
|
+
import FileUtil from "../utils/file.util.js";
|
|
4
|
+
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export default async function (useCaseName, moduleName) {
|
|
7
|
+
try {
|
|
8
|
+
Logger.info(`Starting usecase generation: ${useCaseName} in module: ${moduleName}`);
|
|
9
|
+
const basePath = path.join(process.cwd(), "src/modules", moduleName);
|
|
10
|
+
const ucDir = "application/usecases";
|
|
11
|
+
|
|
12
|
+
FileUtil.ensureDirectories(basePath, [ucDir]);
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
14
|
+
const templateData = {
|
|
15
|
+
name: moduleName,
|
|
16
|
+
className: pascalCase(useCaseName),
|
|
17
|
+
camelName: camelCase(moduleName), // This is used for the repository name
|
|
18
|
+
useCaseCamelName: camelCase(useCaseName),
|
|
19
|
+
};
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
await FileUtil.renderAndWrite(
|
|
22
|
+
"module/usecase.ejs",
|
|
23
|
+
templateData,
|
|
24
|
+
path.join(basePath, ucDir, `${camelCase(useCaseName)}UseCase.js`)
|
|
25
|
+
);
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
await FileUtil.renderAndWrite(
|
|
28
|
+
"module/usecase.test.ejs",
|
|
29
|
+
templateData,
|
|
30
|
+
path.join(basePath, ucDir, `${camelCase(useCaseName)}UseCase.test.js`)
|
|
31
|
+
);
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
}
|
|
33
|
+
Logger.success(`Usecase ${useCaseName} generated inside module ${moduleName}.`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
Logger.error(`Failed to generate usecase ${useCaseName}`, error);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saulpaulus17/node-module-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "CLI tool to grenerate modular scaffolding for nodejs projects following clean arsitecture principles. ",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nodejs",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "saul-paulus (ixspx)",
|
|
13
|
-
"type": "
|
|
13
|
+
"type": "module",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "git+https://github.com/saul-paulus/node-module-generator.git"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"chalk": "^
|
|
30
|
+
"chalk": "^4.1.2",
|
|
31
31
|
"commander": "^14.0.3",
|
|
32
32
|
"ejs": "^5.0.1",
|
|
33
33
|
"fs-extra": "^11.3.4"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jest, describe, it, expect, beforeEach } from '@jest/globals';
|
|
2
|
-
import <%= className %>Controller from './<%=
|
|
2
|
+
import <%= className %>Controller from './<%= camelName %>Controller.js';
|
|
3
3
|
|
|
4
4
|
describe('<%= className %>Controller', () => {
|
|
5
5
|
let controller;
|
package/templates/module/di.ejs
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import <%= className %>Controller from './interfaces/controllers/<%= className %>Controller';
|
|
4
|
-
import create<%= className %>Routes from './interfaces/routes/<%= name.toLowerCase() %>.routes';
|
|
5
|
-
import Create<%= className %>UseCase from './application/usecases/Create<%= className %>UseCase';
|
|
6
|
-
import Prisma<%= className %>Repository from './infrastructure/repositories/Prisma<%= className %>Repository';
|
|
1
|
+
import { asFunction } from 'awilix';
|
|
7
2
|
|
|
8
3
|
export default function register<%= className %>Module(container) {
|
|
9
4
|
container.register({
|
|
10
|
-
<%= camelName %>Controller: asClass(<%= className %>Controller).singleton(),
|
|
11
|
-
<%= camelName %>Routes: asFunction(create<%= className %>Routes).singleton(),
|
|
12
|
-
Create<%= className %>UseCase: asClass(Create<%= className %>UseCase).singleton(),
|
|
13
5
|
<%= camelName %>Repository: asFunction(({ prisma<%= className %>Repository }) => prisma<%= className %>Repository).scoped(),
|
|
14
6
|
});
|
|
15
7
|
}
|
|
8
|
+
|