@saulpaulus17/node-module-generator 3.0.0 โ 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 +11 -11
- package/generator/dto.generator.js +4 -4
- package/generator/module.generator.js +11 -12
- package/generator/repository.generator.js +4 -5
- package/generator/resource.generator.js +11 -12
- package/generator/usecase.generator.js +5 -6
- package/package.json +1 -1
- package/templates/module/controller.test.ejs +1 -1
- package/templates/module/di.ejs +3 -10
- package/templates/module/usecase.test.ejs +1 -1
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
|
-
- ๐ **Full ESM Support**: Native support for **ECMAScript Modules (ESM)** with consistent **
|
|
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,24 +127,24 @@ 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
|
-
โ โโโ
|
|
147
|
+
โ โโโ productRoutes.js
|
|
148
148
|
โโโ product.module.js # Central Awilix Module Registration
|
|
149
149
|
```
|
|
150
150
|
|
|
@@ -157,7 +157,7 @@ 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
|
-
import productRoutes from './modules/Product/interfaces/routes/
|
|
160
|
+
import productRoutes from './modules/Product/interfaces/routes/productRoutes.js';
|
|
161
161
|
app.use('/api/v1/product', productRoutes);
|
|
162
162
|
```
|
|
163
163
|
3. **Detailed Implementation**: Build out the specific logic in the generated templates (which are already integrated via Awilix).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { pascalCase, camelCase
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
3
|
import FileUtil from "../utils/file.util.js";
|
|
4
4
|
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
@@ -14,14 +14,14 @@ export default async function (schemaName, moduleName) {
|
|
|
14
14
|
const templateData = {
|
|
15
15
|
name: moduleName,
|
|
16
16
|
className: pascalCase(schemaName),
|
|
17
|
-
camelName: camelCase(
|
|
18
|
-
|
|
17
|
+
camelName: camelCase(schemaName),
|
|
18
|
+
moduleCamelName: camelCase(moduleName),
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
await FileUtil.renderAndWrite(
|
|
22
22
|
"module/dto.ejs",
|
|
23
23
|
templateData,
|
|
24
|
-
path.join(basePath, dtoDir, `${
|
|
24
|
+
path.join(basePath, dtoDir, `${camelCase(schemaName)}Dto.js`)
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
Logger.success(`DTO ${schemaName} generated inside module ${moduleName} at application/dtos.`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { pascalCase, camelCase
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
3
|
import FileUtil from "../utils/file.util.js";
|
|
4
4
|
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
@@ -25,20 +25,19 @@ export default async function (name) {
|
|
|
25
25
|
name,
|
|
26
26
|
className: pascalCase(name),
|
|
27
27
|
camelName: camelCase(name),
|
|
28
|
-
kebabName: kebabCase(name),
|
|
29
28
|
};
|
|
30
29
|
|
|
31
30
|
const filesToGenerate = [
|
|
32
|
-
{ tpl: "module/controller.ejs", out: `interfaces/controllers/${
|
|
33
|
-
{ tpl: "module/controller.test.ejs", out: `interfaces/controllers/${
|
|
34
|
-
{ tpl: "module/route.ejs", out: `interfaces/routes/${
|
|
35
|
-
{ tpl: "module/usecase.ejs", out: `application/usecases/${
|
|
36
|
-
{ tpl: "module/usecase.test.ejs", out: `application/usecases/${
|
|
37
|
-
{ tpl: "module/entity.ejs", out: `domain/entities/${
|
|
38
|
-
{ tpl: "module/repository.interface.ejs", out: `domain/repositories/${
|
|
39
|
-
{ tpl: "module/repository.impl.ejs", out: `infrastructure/repositories/prisma
|
|
40
|
-
{ tpl: "module/dto.ejs", out: `application/dtos/${
|
|
41
|
-
{ tpl: "module/di.ejs", out: `${
|
|
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` }
|
|
42
41
|
];
|
|
43
42
|
|
|
44
43
|
for (const file of filesToGenerate) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { pascalCase, camelCase
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
3
|
import FileUtil from "../utils/file.util.js";
|
|
4
4
|
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
@@ -20,13 +20,12 @@ export default async function (moduleName) {
|
|
|
20
20
|
name: moduleName,
|
|
21
21
|
className: pascalCase(moduleName),
|
|
22
22
|
camelName: camelCase(moduleName),
|
|
23
|
-
kebabName: kebabCase(moduleName),
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
const filesToGenerate = [
|
|
27
|
-
{ tpl: "module/entity.ejs", out: `domain/entities/${
|
|
28
|
-
{ tpl: "module/repository.interface.ejs", out: `domain/repositories/${
|
|
29
|
-
{ tpl: "module/repository.impl.ejs", out: `infrastructure/repositories/prisma
|
|
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` }
|
|
30
29
|
];
|
|
31
30
|
|
|
32
31
|
for (const file of filesToGenerate) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { pascalCase, camelCase
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
3
|
import FileUtil from "../utils/file.util.js";
|
|
4
4
|
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
@@ -24,20 +24,19 @@ export default async function (name) {
|
|
|
24
24
|
name,
|
|
25
25
|
className: pascalCase(name),
|
|
26
26
|
camelName: camelCase(name),
|
|
27
|
-
kebabName: kebabCase(name),
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
const filesToGenerate = [
|
|
31
|
-
{ tpl: "module/controller.ejs", out: `interfaces/controllers/${
|
|
32
|
-
{ tpl: "module/controller.test.ejs", out: `interfaces/controllers/${
|
|
33
|
-
{ tpl: "module/route.ejs", out: `interfaces/routes/${
|
|
34
|
-
{ tpl: "module/usecase.ejs", out: `application/usecases/${
|
|
35
|
-
{ tpl: "module/usecase.test.ejs", out: `application/usecases/${
|
|
36
|
-
{ tpl: "module/entity.ejs", out: `domain/entities/${
|
|
37
|
-
{ tpl: "module/repository.interface.ejs", out: `domain/repositories/${
|
|
38
|
-
{ tpl: "module/repository.impl.ejs", out: `infrastructure/repositories/prisma
|
|
39
|
-
{ tpl: "module/dto.ejs", out: `application/dtos/${
|
|
40
|
-
{ tpl: "module/di.ejs", out: `${
|
|
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` }
|
|
41
40
|
];
|
|
42
41
|
|
|
43
42
|
for (const file of filesToGenerate) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { pascalCase, camelCase
|
|
2
|
+
import { pascalCase, camelCase } from "../utils/case.util.js";
|
|
3
3
|
import FileUtil from "../utils/file.util.js";
|
|
4
4
|
import Logger from "../utils/logger.util.js";
|
|
5
5
|
|
|
@@ -14,21 +14,20 @@ export default async function (useCaseName, moduleName) {
|
|
|
14
14
|
const templateData = {
|
|
15
15
|
name: moduleName,
|
|
16
16
|
className: pascalCase(useCaseName),
|
|
17
|
-
camelName: camelCase(moduleName),
|
|
18
|
-
|
|
19
|
-
moduleKebabName: kebabCase(moduleName),
|
|
17
|
+
camelName: camelCase(moduleName), // This is used for the repository name
|
|
18
|
+
useCaseCamelName: camelCase(useCaseName),
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
await FileUtil.renderAndWrite(
|
|
23
22
|
"module/usecase.ejs",
|
|
24
23
|
templateData,
|
|
25
|
-
path.join(basePath, ucDir, `${
|
|
24
|
+
path.join(basePath, ucDir, `${camelCase(useCaseName)}UseCase.js`)
|
|
26
25
|
);
|
|
27
26
|
|
|
28
27
|
await FileUtil.renderAndWrite(
|
|
29
28
|
"module/usecase.test.ejs",
|
|
30
29
|
templateData,
|
|
31
|
-
path.join(basePath, ucDir, `${
|
|
30
|
+
path.join(basePath, ucDir, `${camelCase(useCaseName)}UseCase.test.js`)
|
|
32
31
|
);
|
|
33
32
|
|
|
34
33
|
Logger.success(`Usecase ${useCaseName} generated inside module ${moduleName}.`);
|
package/package.json
CHANGED
|
@@ -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/<%= kebabName %>-controller.js';
|
|
4
|
-
import create<%= className %>Routes from './interfaces/routes/<%= kebabName %>-routes.js';
|
|
5
|
-
import <%= className %>UseCase from './application/usecases/<%= kebabName %>-use-case.js';
|
|
6
|
-
import Prisma<%= className %>Repository from './infrastructure/repositories/prisma-<%= kebabName %>-repository.js';
|
|
1
|
+
import { asFunction } from 'awilix';
|
|
7
2
|
|
|
8
3
|
export default function register<%= className %>Module(container) {
|
|
9
4
|
container.register({
|
|
10
|
-
<%= camelName %>
|
|
11
|
-
<%= camelName %>Routes: asFunction(create<%= className %>Routes).singleton(),
|
|
12
|
-
<%= camelName %>UseCase: asClass(<%= className %>UseCase).singleton(),
|
|
13
|
-
<%= camelName %>Repository: asClass(Prisma<%= className %>Repository).singleton(),
|
|
5
|
+
<%= camelName %>Repository: asFunction(({ prisma<%= className %>Repository }) => prisma<%= className %>Repository).scoped(),
|
|
14
6
|
});
|
|
15
7
|
}
|
|
8
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jest, describe, it, expect, beforeEach } from '@jest/globals';
|
|
2
|
-
import <%= className %>UseCase from './<%=
|
|
2
|
+
import <%= className %>UseCase from './<%= camelName %>UseCase.js';
|
|
3
3
|
|
|
4
4
|
describe('<%= className %>UseCase', () => {
|
|
5
5
|
let useCase;
|