go-gin-cli 1.0.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 +287 -0
- package/git-manager.sh +495 -0
- package/package.json +36 -0
- package/prompt.md +6 -0
- package/src/bin/index.js +410 -0
- package/src/lib/constants/index.js +24 -0
- package/src/lib/shares/createDir.js +22 -0
- package/src/lib/shares/createFile.js +23 -0
- package/src/lib/utils/add-auth-to-resource.js +225 -0
- package/src/lib/utils/create-auth.js +937 -0
- package/src/lib/utils/create-resource.js +1426 -0
- package/src/lib/utils/create-service.js +456 -0
- package/src/lib/utils/display.js +19 -0
- package/src/lib/utils/help.js +93 -0
- package/src/lib/utils/remove-module.js +146 -0
- package/src/lib/utils/setup.js +1626 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs").promises;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { COLORS } = require("../constants/index");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Remove module following NestJS Clean Architecture structure
|
|
9
|
+
*/
|
|
10
|
+
async function removeModule(moduleNameLower, moduleNamePascal, moduleNameCamel, moduleNameSnake) {
|
|
11
|
+
const srcDir = "src";
|
|
12
|
+
const domainDir = path.join(srcDir, "domain");
|
|
13
|
+
const infrastructureDir = path.join(srcDir, "infrastructure");
|
|
14
|
+
const usecasesDir = path.join(srcDir, "usecases");
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
console.log(`${COLORS.YELLOW}Starting module removal...${COLORS.NC}`);
|
|
18
|
+
|
|
19
|
+
const dirsToRemove = [
|
|
20
|
+
path.join(infrastructureDir, "controllers", moduleNameLower),
|
|
21
|
+
path.join(infrastructureDir, "repositories", moduleNameLower),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const filesToRemove = [
|
|
25
|
+
path.join(domainDir, "dtos", `${moduleNameLower}.go`),
|
|
26
|
+
path.join(domainDir, "models", `${moduleNameLower}.go`),
|
|
27
|
+
path.join(domainDir, "repositories", `${moduleNameLower}.go`),
|
|
28
|
+
path.join(infrastructureDir, "entities", `${moduleNameLower}.go`),
|
|
29
|
+
path.join(usecasesDir, `${moduleNameLower}.go`),
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// Remove directories
|
|
33
|
+
for (const dir of dirsToRemove) {
|
|
34
|
+
try {
|
|
35
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
36
|
+
console.log(`${COLORS.GREEN}✔ Removed ${dir}${COLORS.NC}`);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.code !== "ENOENT") {
|
|
39
|
+
console.error(`${COLORS.RED}❌ Failed to remove ${dir}: ${error.message}${COLORS.NC}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Remove files
|
|
45
|
+
for (const file of filesToRemove) {
|
|
46
|
+
try {
|
|
47
|
+
await fs.unlink(file);
|
|
48
|
+
console.log(`${COLORS.GREEN}✔ Removed ${file}${COLORS.NC}`);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error.code !== "ENOENT") {
|
|
51
|
+
console.error(`${COLORS.RED}❌ Failed to remove ${file}: ${error.message}${COLORS.NC}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Update module files
|
|
57
|
+
await updateRepositoriesModule(infrastructureDir, moduleNamePascal, moduleNameCamel, moduleNameLower);
|
|
58
|
+
await updateUsecasesProxy(infrastructureDir, moduleNamePascal, moduleNameCamel);
|
|
59
|
+
await updateControllersModule(infrastructureDir, moduleNamePascal, moduleNameCamel, moduleNameLower);
|
|
60
|
+
|
|
61
|
+
console.log(`${COLORS.GREEN}Module removal completed!${COLORS.NC}`);
|
|
62
|
+
console.log(`
|
|
63
|
+
${COLORS.YELLOW}⚠ Manual cleanup may be needed:${COLORS.NC}
|
|
64
|
+
1. Check src/infrastructure/repositories/repositories.go for any remaining references
|
|
65
|
+
2. Check src/infrastructure/usecases-proxy/usecases_proxy.go for any remaining references
|
|
66
|
+
3. Check src/infrastructure/controllers/controllers.go for any remaining references
|
|
67
|
+
4. Remove any database migrations related to ${moduleNameLower}
|
|
68
|
+
5. Run ${COLORS.CYAN}go mod tidy${COLORS.NC} to clean up dependencies
|
|
69
|
+
`);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(`${COLORS.RED}❌ Module removal failed: ${error.message}${COLORS.NC}`);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function updateRepositoriesModule(infrastructureDir, moduleNamePascal, moduleNameCamel, moduleNameLower) {
|
|
77
|
+
const filePath = path.join(infrastructureDir, "repositories", "repositories.go");
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
let content = await fs.readFile(filePath, "utf8");
|
|
81
|
+
|
|
82
|
+
// Remove import
|
|
83
|
+
const importPattern = new RegExp(`\\s*${moduleNameCamel}Repo\\s+"[^"]+/src/infrastructure/repositories/${moduleNameLower}"`, "g");
|
|
84
|
+
content = content.replace(importPattern, "");
|
|
85
|
+
|
|
86
|
+
// Remove repository field
|
|
87
|
+
const fieldPattern = new RegExp(`\\s*${moduleNamePascal}Repository\\s+\\*${moduleNameCamel}Repo\\.Repository`, "g");
|
|
88
|
+
content = content.replace(fieldPattern, "");
|
|
89
|
+
|
|
90
|
+
// Remove initialization
|
|
91
|
+
const initPattern = new RegExp(`\\s*${moduleNamePascal}Repository:\\s*${moduleNameCamel}Repo\\.NewRepository\\(db\\),?`, "g");
|
|
92
|
+
content = content.replace(initPattern, "");
|
|
93
|
+
|
|
94
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
95
|
+
console.log(`${COLORS.GREEN}✔ Updated ${filePath}${COLORS.NC}`);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(`${COLORS.YELLOW}⚠ Could not update repositories module: ${error.message}${COLORS.NC}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function updateUsecasesProxy(infrastructureDir, moduleNamePascal, moduleNameCamel) {
|
|
102
|
+
const filePath = path.join(infrastructureDir, "usecases-proxy", "usecases_proxy.go");
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
let content = await fs.readFile(filePath, "utf8");
|
|
106
|
+
|
|
107
|
+
// Remove usecase field
|
|
108
|
+
const fieldPattern = new RegExp(`\\s*${moduleNamePascal}Usecase\\s+\\*${moduleNameCamel}Usecase\\.${moduleNamePascal}Usecase`, "g");
|
|
109
|
+
content = content.replace(fieldPattern, "");
|
|
110
|
+
|
|
111
|
+
// Remove initialization
|
|
112
|
+
const initPattern = new RegExp(`\\s*${moduleNamePascal}Usecase:\\s*${moduleNameCamel}Usecase\\.New${moduleNamePascal}Usecase\\([^)]+\\),?`, "g");
|
|
113
|
+
content = content.replace(initPattern, "");
|
|
114
|
+
|
|
115
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
116
|
+
console.log(`${COLORS.GREEN}✔ Updated ${filePath}${COLORS.NC}`);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(`${COLORS.YELLOW}⚠ Could not update usecases proxy: ${error.message}${COLORS.NC}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function updateControllersModule(infrastructureDir, moduleNamePascal, moduleNameCamel, moduleNameLower) {
|
|
123
|
+
const filePath = path.join(infrastructureDir, "controllers", "controllers.go");
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
let content = await fs.readFile(filePath, "utf8");
|
|
127
|
+
|
|
128
|
+
// Remove import
|
|
129
|
+
const importPattern = new RegExp(`\\s*${moduleNameCamel}Controller\\s+"[^"]+/src/infrastructure/controllers/${moduleNameLower}"`, "g");
|
|
130
|
+
content = content.replace(importPattern, "");
|
|
131
|
+
|
|
132
|
+
// Remove route registration block
|
|
133
|
+
const routePattern = new RegExp(
|
|
134
|
+
`\\s*// ${moduleNamePascal} routes[\\s\\S]*?${moduleNameCamel}Ctrl\\.RegisterRoutes\\([^)]+\\)`,
|
|
135
|
+
"g"
|
|
136
|
+
);
|
|
137
|
+
content = content.replace(routePattern, "");
|
|
138
|
+
|
|
139
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
140
|
+
console.log(`${COLORS.GREEN}✔ Updated ${filePath}${COLORS.NC}`);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error(`${COLORS.YELLOW}⚠ Could not update controllers module: ${error.message}${COLORS.NC}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = removeModule;
|