usecasecli 1.0.1 → 1.0.3
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/index.js +30 -19
- package/package.json +4 -2
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { intro, outro, text, select
|
|
3
|
+
import { intro, outro, text, select } from "@clack/prompts";
|
|
4
4
|
import fs from "fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let useCaseFileContent;
|
|
9
|
-
let indexFileContent;
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
11
|
let testFilePath;
|
|
12
12
|
let dtoFilePath;
|
|
@@ -16,22 +16,29 @@ let indexFilePath;
|
|
|
16
16
|
let modifiedDtoNamespace;
|
|
17
17
|
let modifiedUsecaseClass;
|
|
18
18
|
|
|
19
|
+
let templates;
|
|
20
|
+
|
|
19
21
|
function getFileTemplatesBasedOnUsecaseType(usecaseType) {
|
|
20
22
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const basePath = path.join(__dirname, "templates", usecaseType);
|
|
24
|
+
|
|
25
|
+
const testFileContent = fs.readFileSync(
|
|
26
|
+
path.join(basePath, "test.spec.ts"),
|
|
23
27
|
"utf-8"
|
|
24
28
|
);
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
const dtoFileContent = fs.readFileSync(
|
|
31
|
+
path.join(basePath, "dto.ts"),
|
|
27
32
|
"utf-8"
|
|
28
33
|
);
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
|
|
35
|
+
const useCaseFileContent = fs.readFileSync(
|
|
36
|
+
path.join(basePath, "useCase.ts"),
|
|
31
37
|
"utf-8"
|
|
32
38
|
);
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
|
|
40
|
+
const indexFileContent = fs.readFileSync(
|
|
41
|
+
path.join(basePath, "index.ts"),
|
|
35
42
|
"utf-8"
|
|
36
43
|
);
|
|
37
44
|
|
|
@@ -42,7 +49,8 @@ function getFileTemplatesBasedOnUsecaseType(usecaseType) {
|
|
|
42
49
|
indexFileContent,
|
|
43
50
|
};
|
|
44
51
|
} catch (err) {
|
|
45
|
-
console.error(err);
|
|
52
|
+
console.error("Erro ao carregar templates:", err);
|
|
53
|
+
process.exit(1);
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
|
|
@@ -50,7 +58,7 @@ function createUsecaseFiles(usecaseName, usecaseType) {
|
|
|
50
58
|
try {
|
|
51
59
|
fs.mkdirSync(`./${usecaseName}`, { recursive: true });
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
templates = getFileTemplatesBasedOnUsecaseType(usecaseType);
|
|
54
62
|
|
|
55
63
|
testFilePath = `./${usecaseName}/${usecaseName}.spec.ts`;
|
|
56
64
|
dtoFilePath = `./${usecaseName}/${usecaseName}DTO.ts`;
|
|
@@ -68,7 +76,10 @@ function createUsecaseFiles(usecaseName, usecaseType) {
|
|
|
68
76
|
|
|
69
77
|
function replaceDtoKeywords() {
|
|
70
78
|
try {
|
|
71
|
-
const modifiedContent = dtoFileContent.replace(
|
|
79
|
+
const modifiedContent = templates.dtoFileContent.replace(
|
|
80
|
+
"DTO",
|
|
81
|
+
modifiedDtoNamespace
|
|
82
|
+
);
|
|
72
83
|
|
|
73
84
|
fs.writeFileSync(dtoFilePath, modifiedContent);
|
|
74
85
|
} catch (err) {
|
|
@@ -78,7 +89,7 @@ function replaceDtoKeywords() {
|
|
|
78
89
|
|
|
79
90
|
function replaceUsecaseKeywords() {
|
|
80
91
|
try {
|
|
81
|
-
const modifiedContent = useCaseFileContent
|
|
92
|
+
const modifiedContent = templates.useCaseFileContent
|
|
82
93
|
.replace(/DTO/g, modifiedDtoNamespace)
|
|
83
94
|
.replace(/Usecase/g, modifiedUsecaseClass)
|
|
84
95
|
.replace(/dto/g, modifiedDtoNamespace);
|
|
@@ -91,7 +102,7 @@ function replaceUsecaseKeywords() {
|
|
|
91
102
|
|
|
92
103
|
function replaceTestKeywords() {
|
|
93
104
|
try {
|
|
94
|
-
const modifiedContent = testFileContent
|
|
105
|
+
const modifiedContent = templates.testFileContent
|
|
95
106
|
.replace(/DTO/g, modifiedDtoNamespace)
|
|
96
107
|
.replace(/dto/g, modifiedDtoNamespace)
|
|
97
108
|
.replace(/Usecase/g, modifiedUsecaseClass)
|
|
@@ -108,7 +119,7 @@ function replaceIndexKeywords() {
|
|
|
108
119
|
`${str.charAt(0).toLowerCase()}${str.slice(1)}`;
|
|
109
120
|
|
|
110
121
|
try {
|
|
111
|
-
const modifiedContent = indexFileContent
|
|
122
|
+
const modifiedContent = templates.indexFileContent
|
|
112
123
|
.replace(/Usecase/g, modifiedUsecaseClass)
|
|
113
124
|
.replace(/useCase/g, modifiedUsecaseClass)
|
|
114
125
|
.replace(/usecaseInstance/g, lowercaseFirst(modifiedUsecaseClass));
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usecasecli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
|
-
|
|
10
|
+
"bin": {
|
|
11
|
+
"usecasecli": "./index.js"
|
|
12
|
+
},
|
|
11
13
|
"keywords": [],
|
|
12
14
|
"author": "Eric Pessoa",
|
|
13
15
|
"license": "ISC",
|