opticore-feature-component 1.0.7 → 1.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/dist/{core-TFP6J3AE.js → chunk-X2ZHQ6T5.js} +421 -430
- package/dist/cli.cjs +3062 -0
- package/dist/cli.d.cts +13 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.js +28 -0
- package/dist/index.cjs +1452 -1788
- package/dist/index.js +4 -1
- package/package.json +13 -1
package/dist/index.cjs
CHANGED
|
@@ -6,14 +6,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __esm = (fn, res, err) => function __init() {
|
|
10
|
-
if (err) throw err[0];
|
|
11
|
-
try {
|
|
12
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
-
} catch (e) {
|
|
14
|
-
throw err = [e], e;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
9
|
var __copyProps = (to, from, except, desc) => {
|
|
18
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
11
|
for (let key of __getOwnPropNames(from))
|
|
@@ -31,14 +23,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
23
|
mod
|
|
32
24
|
));
|
|
33
25
|
|
|
34
|
-
//
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
26
|
+
// src/core/core.ts
|
|
27
|
+
var import_process2 = __toESM(require("process"), 1);
|
|
28
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
29
|
+
var import_path9 = __toESM(require("path"), 1);
|
|
30
|
+
var import_prompts9 = require("@clack/prompts");
|
|
40
31
|
|
|
41
32
|
// src/utils/welcomeMessage.utils.ts
|
|
33
|
+
var import_cfonts = __toESM(require("cfonts"), 1);
|
|
34
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
42
35
|
function UWelcomeMessage() {
|
|
43
36
|
import_cfonts.default.say("OpticoreJS", {
|
|
44
37
|
font: "block",
|
|
@@ -62,112 +55,97 @@ function UWelcomeMessage() {
|
|
|
62
55
|
console.log(subTitle);
|
|
63
56
|
console.log(FOOTER);
|
|
64
57
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
58
|
+
|
|
59
|
+
// src/utils/choiceFeatureCleanModule.ts
|
|
60
|
+
var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
|
|
61
|
+
var import_prompts2 = require("@clack/prompts");
|
|
62
|
+
|
|
63
|
+
// src/utils/prompt.utils.ts
|
|
64
|
+
var import_prompts = require("@clack/prompts");
|
|
65
|
+
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
74
66
|
|
|
75
67
|
// src/utils/fsModule.utils.ts
|
|
76
|
-
var import_fs,
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
static removeDir(directory, recursive, force) {
|
|
98
|
-
try {
|
|
99
|
-
if (import_fs.default.existsSync(directory)) {
|
|
100
|
-
import_fs.default.rmSync(directory, { recursive, force });
|
|
101
|
-
}
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.error(`Error removing folder: ${e.message}`, e);
|
|
104
|
-
process.exit(0);
|
|
105
|
-
}
|
|
68
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
69
|
+
var UFsModule = class {
|
|
70
|
+
static createDirectoryRecursively(dirPath) {
|
|
71
|
+
try {
|
|
72
|
+
import_fs.default.mkdirSync(dirPath, { recursive: true });
|
|
73
|
+
} catch (e) {
|
|
74
|
+
console.error(e.message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static createFile(filePath, fileContent) {
|
|
78
|
+
try {
|
|
79
|
+
import_fs.default.writeFileSync(filePath, fileContent);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error(e.message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
static removeDir(directory, recursive, force) {
|
|
85
|
+
try {
|
|
86
|
+
if (import_fs.default.existsSync(directory)) {
|
|
87
|
+
import_fs.default.rmSync(directory, { recursive, force });
|
|
106
88
|
}
|
|
107
|
-
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error(`Error removing folder: ${e.message}`, e);
|
|
91
|
+
process.exit(0);
|
|
92
|
+
}
|
|
108
93
|
}
|
|
109
|
-
}
|
|
94
|
+
};
|
|
110
95
|
|
|
111
96
|
// src/utils/prompt.utils.ts
|
|
112
|
-
var
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
UPrompt = class {
|
|
123
|
-
static logger = new import_opticore_logger.LoggerCore();
|
|
124
|
-
static async text(message, placeholder, validate) {
|
|
125
|
-
return await (0, import_prompts.text)(
|
|
126
|
-
{
|
|
127
|
-
message,
|
|
128
|
-
placeholder,
|
|
129
|
-
validate
|
|
130
|
-
}
|
|
131
|
-
);
|
|
97
|
+
var import_opticore_logger = require("opticore-logger");
|
|
98
|
+
var import_opticore_http_response = require("opticore-http-response");
|
|
99
|
+
var UPrompt = class {
|
|
100
|
+
static logger = new import_opticore_logger.LoggerCore();
|
|
101
|
+
static async text(message, placeholder, validate) {
|
|
102
|
+
return await (0, import_prompts.text)(
|
|
103
|
+
{
|
|
104
|
+
message,
|
|
105
|
+
placeholder,
|
|
106
|
+
validate
|
|
132
107
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
static async confirm(message, defaultValue = true) {
|
|
111
|
+
return await (0, import_prompts.confirm)({
|
|
112
|
+
message,
|
|
113
|
+
initialValue: defaultValue
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
static cancelOperation(controllerPath) {
|
|
117
|
+
console.log(`${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white("Operation cancelled.")}`)}`);
|
|
118
|
+
if (controllerPath) {
|
|
119
|
+
try {
|
|
120
|
+
UFsModule.removeDir(controllerPath, true, true);
|
|
121
|
+
this.logger.info({
|
|
122
|
+
title: "DIR_REMOVED",
|
|
123
|
+
message: `Removed controller directory: ${controllerPath}`
|
|
137
124
|
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
title: "DIR_REMOVED",
|
|
146
|
-
message: `Removed controller directory: ${controllerPath}`
|
|
147
|
-
});
|
|
148
|
-
} catch (error) {
|
|
149
|
-
this.logger.error({
|
|
150
|
-
errorType: error.name,
|
|
151
|
-
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
152
|
-
message: error.message,
|
|
153
|
-
stackTrace: error.stack,
|
|
154
|
-
title: "FAILED_TO_REMOVE_CONTROLLER_DIR"
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
process.exit(0);
|
|
159
|
-
}
|
|
160
|
-
static async select(message, defaultValue, options) {
|
|
161
|
-
let optSelected = await (0, import_prompts.select)({
|
|
162
|
-
message,
|
|
163
|
-
initialValue: defaultValue,
|
|
164
|
-
options
|
|
125
|
+
} catch (error) {
|
|
126
|
+
this.logger.error({
|
|
127
|
+
errorType: error.name,
|
|
128
|
+
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
129
|
+
message: error.message,
|
|
130
|
+
stackTrace: error.stack,
|
|
131
|
+
title: "FAILED_TO_REMOVE_CONTROLLER_DIR"
|
|
165
132
|
});
|
|
166
|
-
return optSelected[0];
|
|
167
133
|
}
|
|
168
|
-
}
|
|
134
|
+
}
|
|
135
|
+
process.exit(0);
|
|
169
136
|
}
|
|
170
|
-
|
|
137
|
+
static async select(message, defaultValue, options) {
|
|
138
|
+
const optSelected = await (0, import_prompts.select)({
|
|
139
|
+
message,
|
|
140
|
+
initialValue: defaultValue,
|
|
141
|
+
options
|
|
142
|
+
});
|
|
143
|
+
if ((0, import_prompts.isCancel)(optSelected)) {
|
|
144
|
+
return optSelected;
|
|
145
|
+
}
|
|
146
|
+
return optSelected[0];
|
|
147
|
+
}
|
|
148
|
+
};
|
|
171
149
|
|
|
172
150
|
// src/utils/choiceFeatureCleanModule.ts
|
|
173
151
|
async function choiceFeatureCleanModule() {
|
|
@@ -188,18 +166,9 @@ async function choiceFeatureCleanModule() {
|
|
|
188
166
|
return featureSelected;
|
|
189
167
|
}
|
|
190
168
|
}
|
|
191
|
-
var import_ansi_colors2, import_prompts2;
|
|
192
|
-
var init_choiceFeatureCleanModule = __esm({
|
|
193
|
-
"src/utils/choiceFeatureCleanModule.ts"() {
|
|
194
|
-
"use strict";
|
|
195
|
-
init_cjs_shims();
|
|
196
|
-
import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
|
|
197
|
-
import_prompts2 = require("@clack/prompts");
|
|
198
|
-
init_prompt_utils();
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
169
|
|
|
202
170
|
// src/utils/customFeatureInfo.utils.ts
|
|
171
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
|
|
203
172
|
function UCustomFeatureInfo(choice) {
|
|
204
173
|
console.log(
|
|
205
174
|
`
|
|
@@ -214,7 +183,7 @@ You have chosen : ${choice === "opticore_clean_module" ? import_ansi_colors3.def
|
|
|
214
183
|
const diagram = [
|
|
215
184
|
` ` + I(`INFRASTRUCTURE`),
|
|
216
185
|
` ` + I(`controllers \xB7 repositories \xB7 routes`),
|
|
217
|
-
`
|
|
186
|
+
` ` + I(`presenters \xB7 routes`),
|
|
218
187
|
``,
|
|
219
188
|
` ` + A(`APPLICATION`),
|
|
220
189
|
` ` + A(`ports \xB7 interfaces \xB7 dtos \xB7 use-cases`),
|
|
@@ -231,114 +200,90 @@ You have chosen : ${choice === "opticore_clean_module" ? import_ansi_colors3.def
|
|
|
231
200
|
console.log(diagram.join(`
|
|
232
201
|
`));
|
|
233
202
|
}
|
|
234
|
-
var import_ansi_colors3;
|
|
235
|
-
var init_customFeatureInfo_utils = __esm({
|
|
236
|
-
"src/utils/customFeatureInfo.utils.ts"() {
|
|
237
|
-
"use strict";
|
|
238
|
-
init_cjs_shims();
|
|
239
|
-
import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
203
|
|
|
243
204
|
// src/services/featureName.service.ts
|
|
244
|
-
var _featureName
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
"
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
"Enter feature's name :",
|
|
253
|
-
"login",
|
|
254
|
-
(value) => {
|
|
255
|
-
let pattern = new RegExp("^[a-z][A-Za-z]+$");
|
|
256
|
-
if (!value) {
|
|
257
|
-
return "Please enter a feature's name.";
|
|
258
|
-
}
|
|
259
|
-
if (!pattern.test(value)) {
|
|
260
|
-
return "Please enter a valide feature's name.";
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
);
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// src/services/base.service.ts
|
|
269
|
-
var import_path, import_node_fs, import_ansi_colors4, import_process, BaseService;
|
|
270
|
-
var init_base_service = __esm({
|
|
271
|
-
"src/services/base.service.ts"() {
|
|
272
|
-
"use strict";
|
|
273
|
-
init_cjs_shims();
|
|
274
|
-
import_path = __toESM(require("path"), 1);
|
|
275
|
-
import_node_fs = __toESM(require("fs"), 1);
|
|
276
|
-
import_ansi_colors4 = __toESM(require("ansi-colors"), 1);
|
|
277
|
-
import_process = __toESM(require("process"), 1);
|
|
278
|
-
init_fsModule_utils();
|
|
279
|
-
BaseService = class {
|
|
280
|
-
static _isSubdirectoryExists(subdirectory) {
|
|
281
|
-
const subdirectoryString = typeof subdirectory === "symbol" ? subdirectory.toString() : String(subdirectory);
|
|
282
|
-
const subdirectoryPath = import_path.default.join(import_process.default.cwd(), "src", "features", subdirectoryString);
|
|
283
|
-
try {
|
|
284
|
-
const stats = import_node_fs.default.statSync(subdirectoryPath);
|
|
285
|
-
return stats.isDirectory();
|
|
286
|
-
} catch (error) {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
205
|
+
var _featureName = async () => {
|
|
206
|
+
return await UPrompt.text(
|
|
207
|
+
"Enter feature's name :",
|
|
208
|
+
"login",
|
|
209
|
+
(value) => {
|
|
210
|
+
let pattern = new RegExp("^[a-z][A-Za-z_-]+$");
|
|
211
|
+
if (!value) {
|
|
212
|
+
return "Please enter a feature's name.";
|
|
289
213
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
import_process.default.exit(0);
|
|
293
|
-
}
|
|
294
|
-
static _checkFeatureDir() {
|
|
295
|
-
console.error(`${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white("Check if directory src/features exists, and try again.")}`)}`);
|
|
296
|
-
import_process.default.exit();
|
|
297
|
-
}
|
|
298
|
-
static _dirFounded(feature) {
|
|
299
|
-
console.error(`${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(`The ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.bold(`feature ${feature} is already exists.`)}`)}`)}`)}`);
|
|
300
|
-
import_process.default.exit();
|
|
301
|
-
}
|
|
302
|
-
static _cancelOperation(controllerPath) {
|
|
303
|
-
console.log(`${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white("Operation cancelled.")}`)}`);
|
|
304
|
-
UFsModule.removeDir(controllerPath, true, true);
|
|
305
|
-
import_process.default.exit(0);
|
|
214
|
+
if (!pattern.test(value)) {
|
|
215
|
+
return "Please enter a valide feature's name.";
|
|
306
216
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// src/services/base.service.ts
|
|
222
|
+
var import_path = __toESM(require("path"), 1);
|
|
223
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
224
|
+
var import_ansi_colors4 = __toESM(require("ansi-colors"), 1);
|
|
225
|
+
var import_process = __toESM(require("process"), 1);
|
|
226
|
+
var BaseService = class {
|
|
227
|
+
static _isSubdirectoryExists(subdirectory) {
|
|
228
|
+
const subdirectoryString = typeof subdirectory === "symbol" ? subdirectory.toString() : String(subdirectory);
|
|
229
|
+
const subdirectoryPath = import_path.default.join(import_process.default.cwd(), "src", "features", subdirectoryString);
|
|
230
|
+
try {
|
|
231
|
+
const stats = import_node_fs.default.statSync(subdirectoryPath);
|
|
232
|
+
return stats.isDirectory();
|
|
233
|
+
} catch (error) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
static _featureFounded(feature) {
|
|
238
|
+
console.log(`${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(`${import_ansi_colors4.default.bold(`feature ${feature} is already exists.`)}`)}`)}`);
|
|
239
|
+
import_process.default.exit(0);
|
|
240
|
+
}
|
|
241
|
+
static _checkFeatureDir() {
|
|
242
|
+
console.error(`${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white("Check if directory src/features exists, and try again.")}`)}`);
|
|
243
|
+
import_process.default.exit();
|
|
244
|
+
}
|
|
245
|
+
static _dirFounded(feature) {
|
|
246
|
+
console.error(`${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(`The ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.bold(`feature ${feature} is already exists.`)}`)}`)}`)}`);
|
|
247
|
+
import_process.default.exit();
|
|
248
|
+
}
|
|
249
|
+
static _cancelOperation(controllerPath) {
|
|
250
|
+
console.log(`${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white("Operation cancelled.")}`)}`);
|
|
251
|
+
UFsModule.removeDir(controllerPath, true, true);
|
|
252
|
+
import_process.default.exit(0);
|
|
253
|
+
}
|
|
254
|
+
static async _createFeatureModuleDir(featureDir, feature) {
|
|
255
|
+
let ora = (await import("ora")).default;
|
|
256
|
+
const spinner = ora("Feature's name creation...").start();
|
|
257
|
+
UFsModule.createDirectoryRecursively(featureDir);
|
|
258
|
+
spinner.succeed(`Your feature"s name ${import_ansi_colors4.default.bgCyan(import_ansi_colors4.default.white(`${feature}`))} has been created successfully.
|
|
312
259
|
`);
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
static async _createApplicationDirComponent(feature) {
|
|
316
|
-
let application = "";
|
|
317
|
-
application = `${feature}/application`;
|
|
318
|
-
UFsModule.createDirectoryRecursively(application);
|
|
319
|
-
return application;
|
|
320
|
-
}
|
|
321
|
-
static async _createDomainDirComponent(feature) {
|
|
322
|
-
let domain = "";
|
|
323
|
-
domain = `${feature}/domain`;
|
|
324
|
-
UFsModule.createDirectoryRecursively(domain);
|
|
325
|
-
return domain;
|
|
326
|
-
}
|
|
327
|
-
static async _createInfraDirComponent(feature) {
|
|
328
|
-
let infrastructure = "";
|
|
329
|
-
infrastructure = `${feature}/infrastructure`;
|
|
330
|
-
UFsModule.createDirectoryRecursively(infrastructure);
|
|
331
|
-
return infrastructure;
|
|
332
|
-
}
|
|
333
|
-
static async _createPersistenceDirComponent(feature) {
|
|
334
|
-
let persistence = "";
|
|
335
|
-
persistence = `${feature}/persistence`;
|
|
336
|
-
UFsModule.createDirectoryRecursively(persistence);
|
|
337
|
-
return persistence;
|
|
338
|
-
}
|
|
339
|
-
};
|
|
260
|
+
return { featureDir, feature };
|
|
340
261
|
}
|
|
341
|
-
|
|
262
|
+
static async _createApplicationDirComponent(feature) {
|
|
263
|
+
let application = "";
|
|
264
|
+
application = `${feature}/application`;
|
|
265
|
+
UFsModule.createDirectoryRecursively(application);
|
|
266
|
+
return application;
|
|
267
|
+
}
|
|
268
|
+
static async _createDomainDirComponent(feature) {
|
|
269
|
+
let domain = "";
|
|
270
|
+
domain = `${feature}/domain`;
|
|
271
|
+
UFsModule.createDirectoryRecursively(domain);
|
|
272
|
+
return domain;
|
|
273
|
+
}
|
|
274
|
+
static async _createInfraDirComponent(feature) {
|
|
275
|
+
let infrastructure = "";
|
|
276
|
+
infrastructure = `${feature}/infrastructure`;
|
|
277
|
+
UFsModule.createDirectoryRecursively(infrastructure);
|
|
278
|
+
return infrastructure;
|
|
279
|
+
}
|
|
280
|
+
static async _createPersistenceDirComponent(feature) {
|
|
281
|
+
let persistence = "";
|
|
282
|
+
persistence = `${feature}/persistence`;
|
|
283
|
+
UFsModule.createDirectoryRecursively(persistence);
|
|
284
|
+
return persistence;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
342
287
|
|
|
343
288
|
// src/services/controllerType.service.ts
|
|
344
289
|
async function _controllerType(messageText, defaultValue, options) {
|
|
@@ -348,41 +293,36 @@ async function _controllerType(messageText, defaultValue, options) {
|
|
|
348
293
|
options
|
|
349
294
|
);
|
|
350
295
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
init_cjs_shims();
|
|
355
|
-
init_prompt_utils();
|
|
356
|
-
}
|
|
357
|
-
});
|
|
296
|
+
|
|
297
|
+
// src/core/components/application/createController.application.ts
|
|
298
|
+
var import_prompts5 = require("@clack/prompts");
|
|
358
299
|
|
|
359
300
|
// src/core/domains/constants/cleanType.constant.ts
|
|
360
|
-
var CCleanType
|
|
361
|
-
|
|
362
|
-
"
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
301
|
+
var CCleanType = {
|
|
302
|
+
"clean_component_by_step": "clean_component_by_step",
|
|
303
|
+
"full_clean_component": "full_clean_component",
|
|
304
|
+
"simple_component": "simple_component"
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// src/templates/simpleComponent/simpleComponent.template.ts
|
|
308
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
309
|
+
var import_ansi_colors6 = __toESM(require("ansi-colors"), 1);
|
|
310
|
+
|
|
311
|
+
// src/utils/featureComponentGenerator.utils.ts
|
|
312
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
313
|
+
var import_ansi_colors5 = __toESM(require("ansi-colors"), 1);
|
|
314
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
315
|
+
var import_prompts3 = require("@clack/prompts");
|
|
316
|
+
var import_opticore_logger2 = require("opticore-logger");
|
|
372
317
|
|
|
373
318
|
// src/templates/cleanComponents/controller.template.ts
|
|
374
|
-
var generateControllerTemplate
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const useCaseName = `${capitalized}UseCase`;
|
|
382
|
-
const presenterName = `${capitalized}Presenter`;
|
|
383
|
-
const methodsCode = methods.map((method) => generateMethod(method, featureName, capitalized)).join("\n");
|
|
384
|
-
const errorHandler = errorHandlerAppend(capitalized);
|
|
385
|
-
return `import { Request, Response } from "express";
|
|
319
|
+
var generateControllerTemplate = (controllerName, featureName, methods) => {
|
|
320
|
+
const capitalized = capitalize(featureName);
|
|
321
|
+
const useCaseName = `${capitalized}UseCase`;
|
|
322
|
+
const presenterName = `${capitalized}Presenter`;
|
|
323
|
+
const methodsCode = methods.map((method) => generateMethod(method, featureName, capitalized)).join("\n");
|
|
324
|
+
const errorHandler = errorHandlerAppend(capitalized);
|
|
325
|
+
return `import { Request, Response } from "express";
|
|
386
326
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
387
327
|
import { ${useCaseName} } from "../../../application/use-cases/${featureName}.usecase";
|
|
388
328
|
import { ${presenterName} } from "../presenters/${featureName}.presenter";
|
|
@@ -405,25 +345,25 @@ ${methodsCode}
|
|
|
405
345
|
${errorHandler}
|
|
406
346
|
}
|
|
407
347
|
`;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
348
|
+
};
|
|
349
|
+
var generateMethod = (method, featureName, capitalized) => {
|
|
350
|
+
const lower = method.toLowerCase();
|
|
351
|
+
if (lower.includes("findall") || lower.includes("getall")) {
|
|
352
|
+
return generateFindAllMethod(method, featureName, capitalized);
|
|
353
|
+
}
|
|
354
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) {
|
|
355
|
+
return generateFindByIdMethod(method, featureName, capitalized);
|
|
356
|
+
}
|
|
357
|
+
if (lower.includes("create") || lower.includes("add")) {
|
|
358
|
+
return generateCreateMethod(method, featureName, capitalized);
|
|
359
|
+
}
|
|
360
|
+
if (lower.includes("update") || lower.includes("edit")) {
|
|
361
|
+
return generateUpdateMethod(method, featureName, capitalized);
|
|
362
|
+
}
|
|
363
|
+
if (lower.includes("delete") || lower.includes("remove")) {
|
|
364
|
+
return generateDeleteMethod(method, featureName, capitalized);
|
|
365
|
+
}
|
|
366
|
+
return `
|
|
427
367
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
428
368
|
try {
|
|
429
369
|
const useCase = ${capitalized}Controller.buildUseCase();
|
|
@@ -436,8 +376,8 @@ ${errorHandler}
|
|
|
436
376
|
}
|
|
437
377
|
}
|
|
438
378
|
`;
|
|
439
|
-
|
|
440
|
-
|
|
379
|
+
};
|
|
380
|
+
var generateFindAllMethod = (method, featureName, capitalized) => `
|
|
441
381
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
442
382
|
try {
|
|
443
383
|
const useCase = ${capitalized}Controller.buildUseCase();
|
|
@@ -450,7 +390,7 @@ ${errorHandler}
|
|
|
450
390
|
}
|
|
451
391
|
}
|
|
452
392
|
`;
|
|
453
|
-
|
|
393
|
+
var generateFindByIdMethod = (method, featureName, capitalized) => `
|
|
454
394
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
455
395
|
try {
|
|
456
396
|
const { id } = req.params;
|
|
@@ -467,7 +407,7 @@ ${errorHandler}
|
|
|
467
407
|
}
|
|
468
408
|
}
|
|
469
409
|
`;
|
|
470
|
-
|
|
410
|
+
var generateCreateMethod = (method, featureName, capitalized) => `
|
|
471
411
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
472
412
|
try {
|
|
473
413
|
const dto = req.body; // TODO: Validate with your validation layer
|
|
@@ -481,7 +421,7 @@ ${errorHandler}
|
|
|
481
421
|
}
|
|
482
422
|
}
|
|
483
423
|
`;
|
|
484
|
-
|
|
424
|
+
var generateUpdateMethod = (method, featureName, capitalized) => `
|
|
485
425
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
486
426
|
try {
|
|
487
427
|
const { id } = req.params;
|
|
@@ -499,7 +439,7 @@ ${errorHandler}
|
|
|
499
439
|
}
|
|
500
440
|
}
|
|
501
441
|
`;
|
|
502
|
-
|
|
442
|
+
var generateDeleteMethod = (method, featureName, capitalized) => `
|
|
503
443
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
504
444
|
try {
|
|
505
445
|
const { id } = req.params;
|
|
@@ -515,7 +455,7 @@ ${errorHandler}
|
|
|
515
455
|
}
|
|
516
456
|
}
|
|
517
457
|
`;
|
|
518
|
-
|
|
458
|
+
var errorHandlerAppend = (capitalized) => `
|
|
519
459
|
private static handleError(error: unknown) {
|
|
520
460
|
const message = error instanceof Error
|
|
521
461
|
? error.message
|
|
@@ -523,19 +463,12 @@ ${errorHandler}
|
|
|
523
463
|
return ResponseHandler.error(message, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
524
464
|
}
|
|
525
465
|
`;
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
});
|
|
466
|
+
var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
529
467
|
|
|
530
468
|
// src/templates/cleanComponents/entity.template.ts
|
|
531
|
-
var generateEntityTemplate,
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
"use strict";
|
|
535
|
-
init_cjs_shims();
|
|
536
|
-
generateEntityTemplate = (entityName, featureName) => {
|
|
537
|
-
const capitalized = capitalize2(featureName);
|
|
538
|
-
return `/**
|
|
469
|
+
var generateEntityTemplate = (entityName, featureName) => {
|
|
470
|
+
const capitalized = capitalize2(featureName);
|
|
471
|
+
return `/**
|
|
539
472
|
* ${entityName} \u2014 Domain Entity
|
|
540
473
|
* Represents the core business object for the "${featureName}" feature.
|
|
541
474
|
* No framework dependency, pure business logic only.
|
|
@@ -598,21 +531,14 @@ export class ${entityName} {
|
|
|
598
531
|
}
|
|
599
532
|
}
|
|
600
533
|
`;
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
});
|
|
534
|
+
};
|
|
535
|
+
var capitalize2 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
605
536
|
|
|
606
537
|
// src/templates/cleanComponents/repositoryInterface.template.ts
|
|
607
|
-
var generateRepositoryInterfaceTemplate,
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
init_cjs_shims();
|
|
612
|
-
generateRepositoryInterfaceTemplate = (interfaceName, featureName) => {
|
|
613
|
-
const entityName = `${capitalize3(featureName)}Entity`;
|
|
614
|
-
const entityImport = `../../../domain/entities/${featureName}.entity`;
|
|
615
|
-
return `import { ${entityName} } from "${entityImport}";
|
|
538
|
+
var generateRepositoryInterfaceTemplate = (interfaceName, featureName) => {
|
|
539
|
+
const entityName = `${capitalize3(featureName)}Entity`;
|
|
540
|
+
const entityImport = `../../../domain/entities/${featureName}.entity`;
|
|
541
|
+
return `import { ${entityName} } from "${entityImport}";
|
|
616
542
|
|
|
617
543
|
/**
|
|
618
544
|
* ${interfaceName} \u2014 Repository Port (Application Layer)
|
|
@@ -652,24 +578,17 @@ export interface ${interfaceName} {
|
|
|
652
578
|
delete(id: string): Promise<boolean>;
|
|
653
579
|
}
|
|
654
580
|
`;
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
});
|
|
581
|
+
};
|
|
582
|
+
var capitalize3 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
659
583
|
|
|
660
584
|
// src/templates/cleanComponents/repositoryImpl.template.ts
|
|
661
|
-
var generateRepositoryImplTemplate,
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
const implName = `${capitalized}Repository`;
|
|
669
|
-
const interfaceName = `I${capitalized}Repository`;
|
|
670
|
-
const entityName = `${capitalized}Entity`;
|
|
671
|
-
const entityImport = `../../../domain/entities/${featureName}.entity`;
|
|
672
|
-
return `import { ${interfaceName} } from "${interfaceImportPath}";
|
|
585
|
+
var generateRepositoryImplTemplate = (featureName, interfaceImportPath) => {
|
|
586
|
+
const capitalized = capitalize4(featureName);
|
|
587
|
+
const implName = `${capitalized}Repository`;
|
|
588
|
+
const interfaceName = `I${capitalized}Repository`;
|
|
589
|
+
const entityName = `${capitalized}Entity`;
|
|
590
|
+
const entityImport = `../../../domain/entities/${featureName}.entity`;
|
|
591
|
+
return `import { ${interfaceName} } from "${interfaceImportPath}";
|
|
673
592
|
import { ${entityName} } from "${entityImport}";
|
|
674
593
|
|
|
675
594
|
/**
|
|
@@ -761,22 +680,15 @@ export class ${implName} implements ${interfaceName} {
|
|
|
761
680
|
}
|
|
762
681
|
}
|
|
763
682
|
`;
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
767
|
-
});
|
|
683
|
+
};
|
|
684
|
+
var capitalize4 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
768
685
|
|
|
769
686
|
// src/templates/cleanComponents/useCase.template.ts
|
|
770
|
-
var generateUseCaseTemplate,
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
generateUseCaseTemplate = (useCaseName, featureName) => {
|
|
776
|
-
const capitalized = capitalize5(featureName);
|
|
777
|
-
const interfaceName = `I${capitalized}Repository`;
|
|
778
|
-
const entityName = `${capitalized}Entity`;
|
|
779
|
-
return `import { ${interfaceName} } from "../ports/repositories/${featureName}.repository.interface";
|
|
687
|
+
var generateUseCaseTemplate = (useCaseName, featureName) => {
|
|
688
|
+
const capitalized = capitalize5(featureName);
|
|
689
|
+
const interfaceName = `I${capitalized}Repository`;
|
|
690
|
+
const entityName = `${capitalized}Entity`;
|
|
691
|
+
return `import { ${interfaceName} } from "../ports/repositories/${featureName}.repository.interface";
|
|
780
692
|
import { ${entityName} } from "../../domain/entities/${featureName}.entity";
|
|
781
693
|
import {
|
|
782
694
|
Create${capitalized}Dto,
|
|
@@ -843,20 +755,13 @@ export class ${useCaseName} {
|
|
|
843
755
|
}
|
|
844
756
|
}
|
|
845
757
|
`;
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}
|
|
849
|
-
});
|
|
758
|
+
};
|
|
759
|
+
var capitalize5 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
850
760
|
|
|
851
761
|
// src/templates/cleanComponents/dto.template.ts
|
|
852
|
-
var generateDtoTemplate
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
"use strict";
|
|
856
|
-
init_cjs_shims();
|
|
857
|
-
generateDtoTemplate = (featureName) => {
|
|
858
|
-
const capitalized = capitalize6(featureName);
|
|
859
|
-
return `/**
|
|
762
|
+
var generateDtoTemplate = (featureName) => {
|
|
763
|
+
const capitalized = capitalize6(featureName);
|
|
764
|
+
return `/**
|
|
860
765
|
* ${capitalized}Dto \u2014 Data Transfer Objects (Application Layer)
|
|
861
766
|
*
|
|
862
767
|
* DTOs define the shape of data entering and leaving use cases.
|
|
@@ -910,21 +815,14 @@ export class ${capitalized}DtoMapper {
|
|
|
910
815
|
}
|
|
911
816
|
}
|
|
912
817
|
`;
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
916
|
-
});
|
|
818
|
+
};
|
|
819
|
+
var capitalize6 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
917
820
|
|
|
918
821
|
// src/templates/cleanComponents/presenter.template.ts
|
|
919
|
-
var generatePresenterInterfaceTemplate
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
init_cjs_shims();
|
|
924
|
-
generatePresenterInterfaceTemplate = (featureName) => {
|
|
925
|
-
const capitalized = capitalize7(featureName);
|
|
926
|
-
const interfaceName = `I${capitalized}Presenter`;
|
|
927
|
-
return `import { ${capitalized}ResponseDto } from "../../dtos/${featureName}.dto";
|
|
822
|
+
var generatePresenterInterfaceTemplate = (featureName) => {
|
|
823
|
+
const capitalized = capitalize7(featureName);
|
|
824
|
+
const interfaceName = `I${capitalized}Presenter`;
|
|
825
|
+
return `import { ${capitalized}ResponseDto } from "../../dtos/${featureName}.dto";
|
|
928
826
|
|
|
929
827
|
/**
|
|
930
828
|
* ${interfaceName} \u2014 Presenter Port (Application Layer)
|
|
@@ -951,12 +849,12 @@ export interface ${interfaceName} {
|
|
|
951
849
|
presentNotFound(id?: string): unknown;
|
|
952
850
|
}
|
|
953
851
|
`;
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
852
|
+
};
|
|
853
|
+
var generatePresenterImplTemplate = (featureName) => {
|
|
854
|
+
const capitalized = capitalize7(featureName);
|
|
855
|
+
const implName = `${capitalized}Presenter`;
|
|
856
|
+
const interfaceName = `I${capitalized}Presenter`;
|
|
857
|
+
return `import { ${interfaceName} } from "../../../application/ports/presenters/${featureName}.presenter.interface";
|
|
960
858
|
import { ${capitalized}ResponseDto } from "../../../application/dtos/${featureName}.dto";
|
|
961
859
|
|
|
962
860
|
/**
|
|
@@ -992,40 +890,33 @@ export class ${implName} implements ${interfaceName} {
|
|
|
992
890
|
}
|
|
993
891
|
}
|
|
994
892
|
`;
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
});
|
|
893
|
+
};
|
|
894
|
+
var capitalize7 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
999
895
|
|
|
1000
896
|
// src/templates/cleanComponents/router.template.ts
|
|
1001
|
-
var resolveRoute
|
|
1002
|
-
|
|
1003
|
-
"
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
const handlerName = `${capitalized}HandlerRouter`;
|
|
1018
|
-
const controllerName = `${capitalized}Controller`;
|
|
1019
|
-
const routesCode = (controllerMethods || []).map((method) => {
|
|
1020
|
-
const { httpMethod, path: path10 } = resolveRoute(method, featureName);
|
|
1021
|
-
return `{
|
|
897
|
+
var resolveRoute = (methodName, featureName) => {
|
|
898
|
+
const lower = methodName.toLowerCase();
|
|
899
|
+
if (lower.includes("findall") || lower.includes("getall")) return { httpMethod: "get", path: `/${featureName}` };
|
|
900
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) return { httpMethod: "get", path: `/${featureName}/:id` };
|
|
901
|
+
if (lower.includes("create") || lower.includes("add")) return { httpMethod: "post", path: `/${featureName}` };
|
|
902
|
+
if (lower.includes("update") || lower.includes("edit")) return { httpMethod: "put", path: `/${featureName}/:id` };
|
|
903
|
+
if (lower.includes("delete") || lower.includes("remove")) return { httpMethod: "delete", path: `/${featureName}/:id` };
|
|
904
|
+
return { httpMethod: "get", path: `/${featureName}/${lower}` };
|
|
905
|
+
};
|
|
906
|
+
var generateRouterHandlerTemplate = (featureName, controllerMethods) => {
|
|
907
|
+
const capitalized = capitalize8(featureName);
|
|
908
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
909
|
+
const controllerName = `${capitalized}Controller`;
|
|
910
|
+
const routesCode = (controllerMethods || []).map((method) => {
|
|
911
|
+
const { httpMethod, path: path10 } = resolveRoute(method, featureName);
|
|
912
|
+
return `{
|
|
1022
913
|
path: \`${path10}\`,
|
|
1023
914
|
method: "${httpMethod}",
|
|
1024
915
|
middlewares: [],
|
|
1025
916
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
1026
917
|
}`;
|
|
1027
|
-
|
|
1028
|
-
|
|
918
|
+
}).join(",\n");
|
|
919
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
1029
920
|
import { ${controllerName} } from "../adapters/controllers/${featureName}.controller";
|
|
1030
921
|
|
|
1031
922
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -1037,12 +928,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
1037
928
|
);
|
|
1038
929
|
};
|
|
1039
930
|
`;
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
931
|
+
};
|
|
932
|
+
var generateRouterTemplate = (featureName) => {
|
|
933
|
+
const capitalized = capitalize8(featureName);
|
|
934
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
935
|
+
const routerName = `${capitalized}Router`;
|
|
936
|
+
return `import { ${handlerName} } from "./${featureName}.router.handler";
|
|
1046
937
|
import { TFeatureRoutes } from "opticore-router";
|
|
1047
938
|
|
|
1048
939
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -1054,20 +945,13 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
1054
945
|
]
|
|
1055
946
|
};
|
|
1056
947
|
`;
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
});
|
|
948
|
+
};
|
|
949
|
+
var capitalize8 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1061
950
|
|
|
1062
951
|
// src/templates/cleanComponents/event.template.ts
|
|
1063
|
-
var generateEventTemplate
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
"use strict";
|
|
1067
|
-
init_cjs_shims();
|
|
1068
|
-
generateEventTemplate = (featureName) => {
|
|
1069
|
-
const capitalized = capitalize9(featureName);
|
|
1070
|
-
return `/**
|
|
952
|
+
var generateEventTemplate = (featureName) => {
|
|
953
|
+
const capitalized = capitalize9(featureName);
|
|
954
|
+
return `/**
|
|
1071
955
|
* ${capitalized}Event \u2014 Domain Events
|
|
1072
956
|
*
|
|
1073
957
|
* Domain events capture facts that happened in the domain.
|
|
@@ -1137,20 +1021,13 @@ export class ${capitalized}DeletedEvent implements IDomainEvent {
|
|
|
1137
1021
|
}
|
|
1138
1022
|
}
|
|
1139
1023
|
`;
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1024
|
+
};
|
|
1025
|
+
var capitalize9 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1144
1026
|
|
|
1145
1027
|
// src/templates/cleanComponents/exception.template.ts
|
|
1146
|
-
var generateExceptionTemplate
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
"use strict";
|
|
1150
|
-
init_cjs_shims();
|
|
1151
|
-
generateExceptionTemplate = (featureName) => {
|
|
1152
|
-
const capitalized = capitalize10(featureName);
|
|
1153
|
-
return `/**
|
|
1028
|
+
var generateExceptionTemplate = (featureName) => {
|
|
1029
|
+
const capitalized = capitalize10(featureName);
|
|
1030
|
+
return `/**
|
|
1154
1031
|
* ${capitalized}Exception \u2014 Domain Exceptions
|
|
1155
1032
|
*
|
|
1156
1033
|
* Domain exceptions represent violations of business rules specific to "${featureName}".
|
|
@@ -1239,20 +1116,13 @@ export class ${capitalized}InvalidDataException extends ${capitalized}DomainExce
|
|
|
1239
1116
|
export const is${capitalized}DomainException = (error: unknown): error is ${capitalized}DomainException =>
|
|
1240
1117
|
error instanceof ${capitalized}DomainException;
|
|
1241
1118
|
`;
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1119
|
+
};
|
|
1120
|
+
var capitalize10 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1246
1121
|
|
|
1247
1122
|
// src/templates/cleanComponents/service.template.ts
|
|
1248
|
-
var generateServiceTemplate
|
|
1249
|
-
|
|
1250
|
-
"
|
|
1251
|
-
"use strict";
|
|
1252
|
-
init_cjs_shims();
|
|
1253
|
-
generateServiceTemplate = (featureName) => {
|
|
1254
|
-
const capitalized = capitalize11(featureName);
|
|
1255
|
-
return `import { ${capitalized}ResponseDto } from "../../dtos/${featureName}.dto";
|
|
1123
|
+
var generateServiceTemplate = (featureName) => {
|
|
1124
|
+
const capitalized = capitalize11(featureName);
|
|
1125
|
+
return `import { ${capitalized}ResponseDto } from "../../dtos/${featureName}.dto";
|
|
1256
1126
|
|
|
1257
1127
|
/**
|
|
1258
1128
|
* I${capitalized}Service \u2014 Application Service Port
|
|
@@ -1303,21 +1173,14 @@ export interface I${capitalized}Service {
|
|
|
1303
1173
|
// exportToCsv(filters: Record<string, unknown>): Promise<Buffer>;
|
|
1304
1174
|
}
|
|
1305
1175
|
`;
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
});
|
|
1176
|
+
};
|
|
1177
|
+
var capitalize11 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1310
1178
|
|
|
1311
1179
|
// src/templates/simpleComponent/model.template.ts
|
|
1312
|
-
var generateModelTemplate
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
init_cjs_shims();
|
|
1317
|
-
generateModelTemplate = (featureName) => {
|
|
1318
|
-
const capitalized = capitalize12(featureName);
|
|
1319
|
-
const modelName = `${capitalized}Model`;
|
|
1320
|
-
return `/**
|
|
1180
|
+
var generateModelTemplate = (featureName) => {
|
|
1181
|
+
const capitalized = capitalize12(featureName);
|
|
1182
|
+
const modelName = `${capitalized}Model`;
|
|
1183
|
+
return `/**
|
|
1321
1184
|
* ${modelName} \u2014 Data Model
|
|
1322
1185
|
* Plain data structure for the "${featureName}" feature.
|
|
1323
1186
|
*/
|
|
@@ -1338,22 +1201,15 @@ export class ${modelName} {
|
|
|
1338
1201
|
}
|
|
1339
1202
|
}
|
|
1340
1203
|
`;
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
}
|
|
1344
|
-
});
|
|
1204
|
+
};
|
|
1205
|
+
var capitalize12 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1345
1206
|
|
|
1346
1207
|
// src/templates/simpleComponent/simpleRepository.template.ts
|
|
1347
|
-
var generateSimpleRepositoryTemplate
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
generateSimpleRepositoryTemplate = (featureName) => {
|
|
1353
|
-
const capitalized = capitalize13(featureName);
|
|
1354
|
-
const repoName = `${capitalized}Repository`;
|
|
1355
|
-
const modelName = `${capitalized}Model`;
|
|
1356
|
-
return `import { ${modelName} } from "../models/${featureName}.model";
|
|
1208
|
+
var generateSimpleRepositoryTemplate = (featureName) => {
|
|
1209
|
+
const capitalized = capitalize13(featureName);
|
|
1210
|
+
const repoName = `${capitalized}Repository`;
|
|
1211
|
+
const modelName = `${capitalized}Model`;
|
|
1212
|
+
return `import { ${modelName} } from "../models/${featureName}.model";
|
|
1357
1213
|
|
|
1358
1214
|
export class ${repoName} {
|
|
1359
1215
|
private store: Map<string, ${modelName}> = new Map();
|
|
@@ -1387,23 +1243,16 @@ export class ${repoName} {
|
|
|
1387
1243
|
}
|
|
1388
1244
|
}
|
|
1389
1245
|
`;
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1246
|
+
};
|
|
1247
|
+
var capitalize13 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1394
1248
|
|
|
1395
1249
|
// src/templates/simpleComponent/simpleService.template.ts
|
|
1396
|
-
var generateSimpleServiceTemplate
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
const capitalized = capitalize14(featureName);
|
|
1403
|
-
const serviceName = `${capitalized}Service`;
|
|
1404
|
-
const repoName = `${capitalized}Repository`;
|
|
1405
|
-
const modelName = `${capitalized}Model`;
|
|
1406
|
-
return `import { ${repoName} } from "../repositories/${featureName}.repository";
|
|
1250
|
+
var generateSimpleServiceTemplate = (featureName) => {
|
|
1251
|
+
const capitalized = capitalize14(featureName);
|
|
1252
|
+
const serviceName = `${capitalized}Service`;
|
|
1253
|
+
const repoName = `${capitalized}Repository`;
|
|
1254
|
+
const modelName = `${capitalized}Model`;
|
|
1255
|
+
return `import { ${repoName} } from "../repositories/${featureName}.repository";
|
|
1407
1256
|
import { ${modelName} } from "../models/${featureName}.model";
|
|
1408
1257
|
|
|
1409
1258
|
export class ${serviceName} {
|
|
@@ -1441,22 +1290,15 @@ export class ${serviceName} {
|
|
|
1441
1290
|
}
|
|
1442
1291
|
}
|
|
1443
1292
|
`;
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
}
|
|
1447
|
-
});
|
|
1293
|
+
};
|
|
1294
|
+
var capitalize14 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1448
1295
|
|
|
1449
1296
|
// src/templates/simpleComponent/simpleController.template.ts
|
|
1450
|
-
var generateSimpleControllerTemplate
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
generateSimpleControllerTemplate = (controllerName, featureName, methods) => {
|
|
1456
|
-
const capitalized = capitalize15(featureName);
|
|
1457
|
-
const serviceName = `${capitalized}Service`;
|
|
1458
|
-
const methodsCode = methods.map((method) => generateMethod2(method, capitalized, serviceName)).join("\n");
|
|
1459
|
-
return `import { Request, Response } from "express";
|
|
1297
|
+
var generateSimpleControllerTemplate = (controllerName, featureName, methods) => {
|
|
1298
|
+
const capitalized = capitalize15(featureName);
|
|
1299
|
+
const serviceName = `${capitalized}Service`;
|
|
1300
|
+
const methodsCode = methods.map((method) => generateMethod2(method, capitalized, serviceName)).join("\n");
|
|
1301
|
+
return `import { Request, Response } from "express";
|
|
1460
1302
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
1461
1303
|
import { ${serviceName} } from "../services/${featureName}.service";
|
|
1462
1304
|
|
|
@@ -1472,25 +1314,25 @@ ${methodsCode}
|
|
|
1472
1314
|
}
|
|
1473
1315
|
}
|
|
1474
1316
|
`;
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1317
|
+
};
|
|
1318
|
+
var generateMethod2 = (method, capitalized, serviceName) => {
|
|
1319
|
+
const lower = method.toLowerCase();
|
|
1320
|
+
if (lower.includes("findall") || lower.includes("getall")) {
|
|
1321
|
+
return generateFindAllMethod2(method, capitalized);
|
|
1322
|
+
}
|
|
1323
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) {
|
|
1324
|
+
return generateFindByIdMethod2(method, capitalized);
|
|
1325
|
+
}
|
|
1326
|
+
if (lower.includes("create") || lower.includes("add")) {
|
|
1327
|
+
return generateCreateMethod2(method, capitalized);
|
|
1328
|
+
}
|
|
1329
|
+
if (lower.includes("update") || lower.includes("edit")) {
|
|
1330
|
+
return generateUpdateMethod2(method, capitalized);
|
|
1331
|
+
}
|
|
1332
|
+
if (lower.includes("delete") || lower.includes("remove")) {
|
|
1333
|
+
return generateDeleteMethod2(method, capitalized);
|
|
1334
|
+
}
|
|
1335
|
+
return `
|
|
1494
1336
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1495
1337
|
try {
|
|
1496
1338
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -1501,8 +1343,8 @@ ${methodsCode}
|
|
|
1501
1343
|
}
|
|
1502
1344
|
}
|
|
1503
1345
|
`;
|
|
1504
|
-
|
|
1505
|
-
|
|
1346
|
+
};
|
|
1347
|
+
var generateFindAllMethod2 = (method, capitalized) => `
|
|
1506
1348
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1507
1349
|
try {
|
|
1508
1350
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -1513,7 +1355,7 @@ ${methodsCode}
|
|
|
1513
1355
|
}
|
|
1514
1356
|
}
|
|
1515
1357
|
`;
|
|
1516
|
-
|
|
1358
|
+
var generateFindByIdMethod2 = (method, capitalized) => `
|
|
1517
1359
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1518
1360
|
try {
|
|
1519
1361
|
const { id } = req.params;
|
|
@@ -1528,7 +1370,7 @@ ${methodsCode}
|
|
|
1528
1370
|
}
|
|
1529
1371
|
}
|
|
1530
1372
|
`;
|
|
1531
|
-
|
|
1373
|
+
var generateCreateMethod2 = (method, capitalized) => `
|
|
1532
1374
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1533
1375
|
try {
|
|
1534
1376
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -1539,7 +1381,7 @@ ${methodsCode}
|
|
|
1539
1381
|
}
|
|
1540
1382
|
}
|
|
1541
1383
|
`;
|
|
1542
|
-
|
|
1384
|
+
var generateUpdateMethod2 = (method, capitalized) => `
|
|
1543
1385
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1544
1386
|
try {
|
|
1545
1387
|
const { id } = req.params;
|
|
@@ -1554,7 +1396,7 @@ ${methodsCode}
|
|
|
1554
1396
|
}
|
|
1555
1397
|
}
|
|
1556
1398
|
`;
|
|
1557
|
-
|
|
1399
|
+
var generateDeleteMethod2 = (method, capitalized) => `
|
|
1558
1400
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1559
1401
|
try {
|
|
1560
1402
|
const { id } = req.params;
|
|
@@ -1569,39 +1411,42 @@ ${methodsCode}
|
|
|
1569
1411
|
}
|
|
1570
1412
|
}
|
|
1571
1413
|
`;
|
|
1572
|
-
|
|
1573
|
-
}
|
|
1574
|
-
});
|
|
1414
|
+
var capitalize15 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1575
1415
|
|
|
1576
1416
|
// src/templates/simpleComponent/simpleRouter.template.ts
|
|
1577
|
-
var resolveRoute2
|
|
1578
|
-
|
|
1579
|
-
"
|
|
1580
|
-
"
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1417
|
+
var resolveRoute2 = (methodName, featureName) => {
|
|
1418
|
+
const lower = methodName.toLowerCase();
|
|
1419
|
+
if (lower.includes("findall") || lower.includes("getall")) {
|
|
1420
|
+
return { httpMethod: "get", path: `/${featureName}` };
|
|
1421
|
+
}
|
|
1422
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) {
|
|
1423
|
+
return { httpMethod: "get", path: `/${featureName}/:id` };
|
|
1424
|
+
}
|
|
1425
|
+
if (lower.includes("create") || lower.includes("add")) {
|
|
1426
|
+
return { httpMethod: "post", path: `/${featureName}` };
|
|
1427
|
+
}
|
|
1428
|
+
if (lower.includes("update") || lower.includes("edit")) {
|
|
1429
|
+
return { httpMethod: "put", path: `/${featureName}/:id` };
|
|
1430
|
+
}
|
|
1431
|
+
if (lower.includes("delete") || lower.includes("remove")) {
|
|
1432
|
+
return { httpMethod: "delete", path: `/${featureName}/:id` };
|
|
1433
|
+
}
|
|
1434
|
+
return { httpMethod: "get", path: `/${featureName}/${lower}` };
|
|
1435
|
+
};
|
|
1436
|
+
var generateSimpleRouterHandlerTemplate = (featureName, controllerMethods) => {
|
|
1437
|
+
const capitalized = capitalize16(featureName);
|
|
1438
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
1439
|
+
const controllerName = `${capitalized}Controller`;
|
|
1440
|
+
const routesCode = (controllerMethods || []).map((method) => {
|
|
1441
|
+
const { httpMethod, path: path10 } = resolveRoute2(method, featureName);
|
|
1442
|
+
return `{
|
|
1598
1443
|
path: \`${path10}\`,
|
|
1599
1444
|
method: "${httpMethod}",
|
|
1600
1445
|
middlewares: [],
|
|
1601
1446
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
1602
1447
|
}`;
|
|
1603
|
-
|
|
1604
|
-
|
|
1448
|
+
}).join(",\n");
|
|
1449
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
1605
1450
|
import { ${controllerName} } from "../controllers/${featureName}.controller";
|
|
1606
1451
|
|
|
1607
1452
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -1613,12 +1458,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
1613
1458
|
);
|
|
1614
1459
|
};
|
|
1615
1460
|
`;
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1461
|
+
};
|
|
1462
|
+
var generateSimpleRouterTemplate = (featureName) => {
|
|
1463
|
+
const capitalized = capitalize16(featureName);
|
|
1464
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
1465
|
+
const routerName = `${capitalized}Router`;
|
|
1466
|
+
return `import { ${handlerName} } from "./${featureName}.router.handler";
|
|
1622
1467
|
import { TFeatureRoutes } from "opticore-router";
|
|
1623
1468
|
|
|
1624
1469
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -1630,973 +1475,822 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
1630
1475
|
]
|
|
1631
1476
|
};
|
|
1632
1477
|
`;
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1636
|
-
});
|
|
1478
|
+
};
|
|
1479
|
+
var capitalize16 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1637
1480
|
|
|
1638
1481
|
// src/utils/featureComponentGenerator.utils.ts
|
|
1639
|
-
var
|
|
1640
|
-
|
|
1641
|
-
"src/
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
* Creates the concrete presenter implementation.
|
|
1759
|
-
*/
|
|
1760
|
-
static async createPresenterImpl(featureName, presenterImplDir) {
|
|
1761
|
-
const filePath = import_path2.default.join(presenterImplDir, `${featureName}.presenter.ts`);
|
|
1762
|
-
UFsModule.createFile(filePath, generatePresenterImplTemplate(featureName));
|
|
1763
|
-
console.log(import_ansi_colors5.default.green(`\u2705 Presenter implementation created: ${filePath}`));
|
|
1482
|
+
var FeatureComponentGeneratorUtils = class {
|
|
1483
|
+
static logger = new import_opticore_logger2.LoggerCore();
|
|
1484
|
+
static REGISTER_ROUTER_PATH = import_path2.default.join(process.cwd(), "src/app/router/register.router.ts");
|
|
1485
|
+
static structure = "clean";
|
|
1486
|
+
static setStructure(s) {
|
|
1487
|
+
this.structure = s;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Registers a custom module router in register.router.ts.
|
|
1491
|
+
* Must be preceded by setStructure("custom").
|
|
1492
|
+
*/
|
|
1493
|
+
static async registerModuleRouter(moduleName) {
|
|
1494
|
+
await this.updateRegisterRouter(moduleName);
|
|
1495
|
+
this.structure = "clean";
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Creates the domain entity file.
|
|
1499
|
+
*/
|
|
1500
|
+
static async createEntity(featureName, entityDir) {
|
|
1501
|
+
const entityName = `${this.capitalize(featureName)}Entity`;
|
|
1502
|
+
const filePath = import_path2.default.join(entityDir, `${featureName}.entity.ts`);
|
|
1503
|
+
UFsModule.createFile(filePath, generateEntityTemplate(entityName, featureName));
|
|
1504
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Entity created: ${filePath}`));
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Creates the domain event file.
|
|
1508
|
+
*/
|
|
1509
|
+
static async createEvent(featureName, eventDir) {
|
|
1510
|
+
const filePath = import_path2.default.join(eventDir, `${featureName}.event.ts`);
|
|
1511
|
+
UFsModule.createFile(filePath, generateEventTemplate(featureName));
|
|
1512
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Event created: ${filePath}`));
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Creates the domain exception file.
|
|
1516
|
+
*/
|
|
1517
|
+
static async createException(featureName, exceptionDir) {
|
|
1518
|
+
const filePath = import_path2.default.join(exceptionDir, `${featureName}.exception.ts`);
|
|
1519
|
+
UFsModule.createFile(filePath, generateExceptionTemplate(featureName));
|
|
1520
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Exception created: ${filePath}`));
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Creates the repository port interface.
|
|
1524
|
+
*/
|
|
1525
|
+
static async createRepositoryInterface(featureName, interfaceDir) {
|
|
1526
|
+
const interfaceName = `I${this.capitalize(featureName)}Repository`;
|
|
1527
|
+
const filePath = import_path2.default.join(interfaceDir, `${featureName}.repository.interface.ts`);
|
|
1528
|
+
UFsModule.createFile(filePath, generateRepositoryInterfaceTemplate(interfaceName, featureName));
|
|
1529
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Repository interface created: ${filePath}`));
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
* Creates the presenter port interface.
|
|
1533
|
+
*/
|
|
1534
|
+
static async createPresenterInterface(featureName, presenterInterfaceDir) {
|
|
1535
|
+
const filePath = import_path2.default.join(presenterInterfaceDir, `${featureName}.presenter.interface.ts`);
|
|
1536
|
+
UFsModule.createFile(filePath, generatePresenterInterfaceTemplate(featureName));
|
|
1537
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Presenter interface created: ${filePath}`));
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Creates the application service port interface.
|
|
1541
|
+
*/
|
|
1542
|
+
static async createService(featureName, serviceDir) {
|
|
1543
|
+
const filePath = import_path2.default.join(serviceDir, `${featureName}.service.ts`);
|
|
1544
|
+
UFsModule.createFile(filePath, generateServiceTemplate(featureName));
|
|
1545
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Service interface created: ${filePath}`));
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Creates the DTO file (input + output shapes + mapper).
|
|
1549
|
+
*/
|
|
1550
|
+
static async createDto(featureName, dtoDir) {
|
|
1551
|
+
const filePath = import_path2.default.join(dtoDir, `${featureName}.dto.ts`);
|
|
1552
|
+
UFsModule.createFile(filePath, generateDtoTemplate(featureName));
|
|
1553
|
+
console.log(import_ansi_colors5.default.green(`\u2714 DTO created: ${filePath}`));
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Creates the use case file.
|
|
1557
|
+
*/
|
|
1558
|
+
static async createUseCase(featureName, useCaseDir) {
|
|
1559
|
+
const useCaseName = `${this.capitalize(featureName)}UseCase`;
|
|
1560
|
+
const filePath = import_path2.default.join(useCaseDir, `${featureName}.usecase.ts`);
|
|
1561
|
+
UFsModule.createFile(filePath, generateUseCaseTemplate(useCaseName, featureName));
|
|
1562
|
+
console.log(import_ansi_colors5.default.green(`\u2714 UseCase created: ${filePath}`));
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Creates the concrete repository implementation.
|
|
1566
|
+
*/
|
|
1567
|
+
static async createRepositoryImpl(featureName, repositoryImplDir) {
|
|
1568
|
+
const interfaceImportPath = `../../../application/ports/repositories/${featureName}.repository.interface`;
|
|
1569
|
+
const filePath = import_path2.default.join(repositoryImplDir, `${featureName}.repository.ts`);
|
|
1570
|
+
UFsModule.createFile(filePath, generateRepositoryImplTemplate(featureName, interfaceImportPath));
|
|
1571
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Repository implementation created: ${filePath}`));
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Creates the concrete presenter implementation.
|
|
1575
|
+
*/
|
|
1576
|
+
static async createPresenterImpl(featureName, presenterImplDir) {
|
|
1577
|
+
const filePath = import_path2.default.join(presenterImplDir, `${featureName}.presenter.ts`);
|
|
1578
|
+
UFsModule.createFile(filePath, generatePresenterImplTemplate(featureName));
|
|
1579
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Presenter implementation created: ${filePath}`));
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Creates the HTTP controller.
|
|
1583
|
+
* Prompts the user for method names, then generates the file.
|
|
1584
|
+
*
|
|
1585
|
+
* @returns The controller class name and the list of chosen methods.
|
|
1586
|
+
*/
|
|
1587
|
+
static async createController(featureName, controllerDir) {
|
|
1588
|
+
const controllerName = `${this.capitalize(featureName)}Controller`;
|
|
1589
|
+
const filePath = import_path2.default.join(controllerDir, `${featureName}.controller.ts`);
|
|
1590
|
+
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
1591
|
+
let methods = [];
|
|
1592
|
+
let content;
|
|
1593
|
+
if (wantsMethods && !(0, import_prompts3.isCancel)(wantsMethods)) {
|
|
1594
|
+
const methodsText = await UPrompt.text(
|
|
1595
|
+
"Enter the method names (comma separated):",
|
|
1596
|
+
"create, findAll, findById, update, delete",
|
|
1597
|
+
(v) => v ? void 0 : "You must enter at least one method."
|
|
1598
|
+
);
|
|
1599
|
+
if (!(0, import_prompts3.isCancel)(methodsText)) {
|
|
1600
|
+
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
1764
1601
|
}
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
*
|
|
1769
|
-
* @returns The controller class name and the list of chosen methods.
|
|
1770
|
-
*/
|
|
1771
|
-
static async createController(featureName, controllerDir) {
|
|
1772
|
-
const controllerName = `${this.capitalize(featureName)}Controller`;
|
|
1773
|
-
const filePath = import_path2.default.join(controllerDir, `${featureName}.controller.ts`);
|
|
1774
|
-
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
1775
|
-
let methods = [];
|
|
1776
|
-
let content;
|
|
1777
|
-
if (wantsMethods) {
|
|
1778
|
-
const methodsText = await UPrompt.text(
|
|
1779
|
-
"Enter the method names (comma separated):",
|
|
1780
|
-
"create, findAll, findById, update, delete",
|
|
1781
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
1782
|
-
);
|
|
1783
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
1784
|
-
content = generateControllerTemplate(controllerName, featureName, methods);
|
|
1785
|
-
} else {
|
|
1786
|
-
content = `import { Request, Response } from "express";
|
|
1602
|
+
content = generateControllerTemplate(controllerName, featureName, methods);
|
|
1603
|
+
} else {
|
|
1604
|
+
content = `import { Request, Response } from "express";
|
|
1787
1605
|
|
|
1788
1606
|
export class ${controllerName} {}
|
|
1789
1607
|
`;
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1608
|
+
}
|
|
1609
|
+
UFsModule.createFile(filePath, content);
|
|
1610
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Controller created: ${filePath}`));
|
|
1611
|
+
return { controllerName, methods };
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Creates the data model file (simple component).
|
|
1615
|
+
*/
|
|
1616
|
+
static async createModel(featureName, modelDir) {
|
|
1617
|
+
const filePath = import_path2.default.join(modelDir, `${featureName}.model.ts`);
|
|
1618
|
+
UFsModule.createFile(filePath, generateModelTemplate(featureName));
|
|
1619
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Model created: ${filePath}`));
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Creates the simple repository (no interface, uses the model directly).
|
|
1623
|
+
*/
|
|
1624
|
+
static async createSimpleRepository(featureName, repositoryDir) {
|
|
1625
|
+
const filePath = import_path2.default.join(repositoryDir, `${featureName}.repository.ts`);
|
|
1626
|
+
UFsModule.createFile(filePath, generateSimpleRepositoryTemplate(featureName));
|
|
1627
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Repository created: ${filePath}`));
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Creates the simple concrete service (no interface, wires the repository).
|
|
1631
|
+
*/
|
|
1632
|
+
static async createSimpleService(featureName, serviceDir) {
|
|
1633
|
+
const filePath = import_path2.default.join(serviceDir, `${featureName}.service.ts`);
|
|
1634
|
+
UFsModule.createFile(filePath, generateSimpleServiceTemplate(featureName));
|
|
1635
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Service created: ${filePath}`));
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Creates the simple controller (delegates to service, no use-case/presenter).
|
|
1639
|
+
*/
|
|
1640
|
+
static async createSimpleController(featureName, controllerDir) {
|
|
1641
|
+
const controllerName = `${this.capitalize(featureName)}Controller`;
|
|
1642
|
+
const filePath = import_path2.default.join(controllerDir, `${featureName}.controller.ts`);
|
|
1643
|
+
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
1644
|
+
let methods = [];
|
|
1645
|
+
let content;
|
|
1646
|
+
if (wantsMethods && !(0, import_prompts3.isCancel)(wantsMethods)) {
|
|
1647
|
+
const methodsText = await UPrompt.text(
|
|
1648
|
+
"Enter the method names (comma separated):",
|
|
1649
|
+
"create, findAll, findById, update, delete",
|
|
1650
|
+
(v) => v ? void 0 : "You must enter at least one method."
|
|
1651
|
+
);
|
|
1652
|
+
if (!(0, import_prompts3.isCancel)(methodsText)) {
|
|
1653
|
+
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
1818
1654
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
static async createSimpleController(featureName, controllerDir) {
|
|
1823
|
-
const controllerName = `${this.capitalize(featureName)}Controller`;
|
|
1824
|
-
const filePath = import_path2.default.join(controllerDir, `${featureName}.controller.ts`);
|
|
1825
|
-
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
1826
|
-
let methods = [];
|
|
1827
|
-
let content;
|
|
1828
|
-
if (wantsMethods) {
|
|
1829
|
-
const methodsText = await UPrompt.text(
|
|
1830
|
-
"Enter the method names (comma separated):",
|
|
1831
|
-
"create, findAll, findById, update, delete",
|
|
1832
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
1833
|
-
);
|
|
1834
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
1835
|
-
content = generateSimpleControllerTemplate(controllerName, featureName, methods);
|
|
1836
|
-
} else {
|
|
1837
|
-
content = `import { Request, Response } from "express";
|
|
1655
|
+
content = generateSimpleControllerTemplate(controllerName, featureName, methods);
|
|
1656
|
+
} else {
|
|
1657
|
+
content = `import { Request, Response } from "express";
|
|
1838
1658
|
|
|
1839
1659
|
export class ${controllerName} {}
|
|
1840
1660
|
`;
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1661
|
+
}
|
|
1662
|
+
UFsModule.createFile(filePath, content);
|
|
1663
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Controller created: ${filePath}`));
|
|
1664
|
+
return { controllerName, methods };
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Creates the route handler (HTTP verb + path → controller method bindings).
|
|
1668
|
+
*
|
|
1669
|
+
*/
|
|
1670
|
+
static async createRouterHandler(featureName, routerHandlerDir, controllerMethods) {
|
|
1671
|
+
const filePath = import_path2.default.join(routerHandlerDir, `${featureName}.router.handler.ts`);
|
|
1672
|
+
const content = this.structure === "simple" ? generateSimpleRouterHandlerTemplate(featureName, controllerMethods) : generateRouterHandlerTemplate(featureName, controllerMethods);
|
|
1673
|
+
UFsModule.createFile(filePath, content);
|
|
1674
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Router Handler created: ${filePath}`));
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Creates the feature router and registers it in register.router.ts.
|
|
1678
|
+
*
|
|
1679
|
+
*/
|
|
1680
|
+
static async createRouter(featureName, routerDir) {
|
|
1681
|
+
const filePath = import_path2.default.join(routerDir, `${featureName}.router.ts`);
|
|
1682
|
+
const content = this.structure === "simple" ? generateSimpleRouterTemplate(featureName) : generateRouterTemplate(featureName);
|
|
1683
|
+
UFsModule.createFile(filePath, content);
|
|
1684
|
+
await this.updateRegisterRouter(featureName);
|
|
1685
|
+
console.log(import_ansi_colors5.default.green(`\u2714 Router created: ${filePath}`));
|
|
1686
|
+
}
|
|
1687
|
+
static capitalize(str) {
|
|
1688
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Appends an import and registers the new router in register.router.ts.
|
|
1692
|
+
*/
|
|
1693
|
+
static async updateRegisterRouter(featureName) {
|
|
1694
|
+
const routerName = `${this.capitalize(featureName)}Router`;
|
|
1695
|
+
const routerPath = this.structure === "simple" || this.structure === "mvc" || this.structure === "layered" ? `../../features/${featureName}/routes/${featureName}.router` : this.structure === "custom" ? `../../features/${featureName}/${featureName}.router` : `../../features/${featureName}/infrastructure/routes/${featureName}.router`;
|
|
1696
|
+
const importStatement = `import { ${routerName} } from "${routerPath}"`;
|
|
1697
|
+
try {
|
|
1698
|
+
if (!import_fs2.default.existsSync(this.REGISTER_ROUTER_PATH)) {
|
|
1699
|
+
console.log(
|
|
1700
|
+
import_ansi_colors5.default.yellow(`\u26A0 register.router.ts not found at ${this.REGISTER_ROUTER_PATH}, skipping auto-registration.`)
|
|
1701
|
+
);
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
let content = import_fs2.default.readFileSync(this.REGISTER_ROUTER_PATH, "utf-8");
|
|
1705
|
+
if (content.includes(`import { ${routerName} } from`)) {
|
|
1706
|
+
console.log(import_ansi_colors5.default.cyan(`\u2139 ${routerName} is already registered.`));
|
|
1707
|
+
return;
|
|
1845
1708
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
static async createRouterHandler(featureName, routerHandlerDir, controllerMethods) {
|
|
1851
|
-
const filePath = import_path2.default.join(routerHandlerDir, `${featureName}.router.handler.ts`);
|
|
1852
|
-
const content = this.structure === "simple" ? generateSimpleRouterHandlerTemplate(featureName, controllerMethods) : generateRouterHandlerTemplate(featureName, controllerMethods);
|
|
1853
|
-
UFsModule.createFile(filePath, content);
|
|
1854
|
-
console.log(import_ansi_colors5.default.green(`\u2705 Router Handler created: ${filePath}`));
|
|
1709
|
+
const lines = content.split("\n");
|
|
1710
|
+
let lastImportIndex = -1;
|
|
1711
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1712
|
+
if (lines[i].trim().startsWith("import ")) lastImportIndex = i;
|
|
1855
1713
|
}
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
const filePath = import_path2.default.join(routerDir, `${featureName}.router.ts`);
|
|
1862
|
-
const content = this.structure === "simple" ? generateSimpleRouterTemplate(featureName) : generateRouterTemplate(featureName);
|
|
1863
|
-
UFsModule.createFile(filePath, content);
|
|
1864
|
-
await this.updateRegisterRouter(featureName);
|
|
1865
|
-
console.log(import_ansi_colors5.default.green(`\u2705 Router created: ${filePath}`));
|
|
1714
|
+
if (lastImportIndex !== -1) {
|
|
1715
|
+
lines.splice(lastImportIndex + 1, 0, importStatement);
|
|
1716
|
+
content = lines.join("\n");
|
|
1717
|
+
} else {
|
|
1718
|
+
content = importStatement + "\n" + content;
|
|
1866
1719
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1720
|
+
const ARRAY_OPEN = "registered([";
|
|
1721
|
+
const ARRAY_CLOSE = "]);";
|
|
1722
|
+
const startIdx = content.indexOf(ARRAY_OPEN);
|
|
1723
|
+
if (startIdx === -1) {
|
|
1724
|
+
console.log(import_ansi_colors5.default.yellow(`\u26A0 Could not find 'registered([' in register.router.ts.`));
|
|
1725
|
+
return;
|
|
1869
1726
|
}
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
return;
|
|
1883
|
-
}
|
|
1884
|
-
let content = import_fs2.default.readFileSync(this.REGISTER_ROUTER_PATH, "utf-8");
|
|
1885
|
-
if (content.includes(`import { ${routerName} } from`)) {
|
|
1886
|
-
console.log(import_ansi_colors5.default.cyan(`\u2139\uFE0F ${routerName} is already registered.`));
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
const lines = content.split("\n");
|
|
1890
|
-
let lastImportIndex = -1;
|
|
1891
|
-
for (let i = 0; i < lines.length; i++) {
|
|
1892
|
-
if (lines[i].trim().startsWith("import ")) lastImportIndex = i;
|
|
1893
|
-
}
|
|
1894
|
-
if (lastImportIndex !== -1) {
|
|
1895
|
-
lines.splice(lastImportIndex + 1, 0, importStatement);
|
|
1896
|
-
content = lines.join("\n");
|
|
1897
|
-
} else {
|
|
1898
|
-
content = importStatement + "\n" + content;
|
|
1899
|
-
}
|
|
1900
|
-
const ARRAY_OPEN = "registered([";
|
|
1901
|
-
const ARRAY_CLOSE = "]);";
|
|
1902
|
-
const startIdx = content.indexOf(ARRAY_OPEN);
|
|
1903
|
-
if (startIdx === -1) {
|
|
1904
|
-
console.log(import_ansi_colors5.default.yellow(`\u26A0\uFE0F Could not find 'registered([' in register.router.ts.`));
|
|
1905
|
-
return;
|
|
1906
|
-
}
|
|
1907
|
-
const endIdx = content.indexOf(ARRAY_CLOSE, startIdx + ARRAY_OPEN.length);
|
|
1908
|
-
if (endIdx === -1) {
|
|
1909
|
-
console.log(import_ansi_colors5.default.yellow(`\u26A0\uFE0F Could not find matching ']);' in register.router.ts.`));
|
|
1910
|
-
return;
|
|
1911
|
-
}
|
|
1912
|
-
const arrayContent = content.substring(startIdx + ARRAY_OPEN.length, endIdx);
|
|
1913
|
-
const existingRoutes = arrayContent.split("\n").map((l) => l.trim().replace(/,+$/, "")).filter(Boolean);
|
|
1914
|
-
if (!existingRoutes.includes(routerName)) {
|
|
1915
|
-
existingRoutes.push(routerName);
|
|
1916
|
-
}
|
|
1917
|
-
const indentedRoutes = existingRoutes.map((r) => ` ${r},`).join("\n");
|
|
1918
|
-
const newContent = content.substring(0, startIdx + ARRAY_OPEN.length) + `
|
|
1727
|
+
const endIdx = content.indexOf(ARRAY_CLOSE, startIdx + ARRAY_OPEN.length);
|
|
1728
|
+
if (endIdx === -1) {
|
|
1729
|
+
console.log(import_ansi_colors5.default.yellow(`\u26A0 Could not find matching ']);' in register.router.ts.`));
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
const arrayContent = content.substring(startIdx + ARRAY_OPEN.length, endIdx);
|
|
1733
|
+
const existingRoutes = arrayContent.split("\n").map((l) => l.trim().replace(/,+$/, "")).filter(Boolean);
|
|
1734
|
+
if (!existingRoutes.includes(routerName)) {
|
|
1735
|
+
existingRoutes.push(routerName);
|
|
1736
|
+
}
|
|
1737
|
+
const indentedRoutes = existingRoutes.map((r) => ` ${r},`).join("\n");
|
|
1738
|
+
const newContent = content.substring(0, startIdx + ARRAY_OPEN.length) + `
|
|
1919
1739
|
${indentedRoutes}
|
|
1920
1740
|
` + content.substring(endIdx);
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
}
|
|
1927
|
-
};
|
|
1741
|
+
import_fs2.default.writeFileSync(this.REGISTER_ROUTER_PATH, newContent, "utf-8");
|
|
1742
|
+
console.log(import_ansi_colors5.default.green(`\u2714 register.router.ts updated with ${routerName}.`));
|
|
1743
|
+
} catch (error) {
|
|
1744
|
+
console.error(import_ansi_colors5.default.red(`\u2718 Failed to update register.router.ts: ${error.message}`));
|
|
1745
|
+
}
|
|
1928
1746
|
}
|
|
1929
|
-
}
|
|
1747
|
+
};
|
|
1930
1748
|
|
|
1931
1749
|
// src/templates/simpleComponent/simpleComponent.template.ts
|
|
1932
|
-
var
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
import_path3
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
const controller = await FeatureComponentGeneratorUtils.createSimpleController(
|
|
1963
|
-
featureName,
|
|
1964
|
-
paths.controllersDir
|
|
1965
|
-
);
|
|
1966
|
-
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, paths.routesDir, controller.methods);
|
|
1967
|
-
await FeatureComponentGeneratorUtils.createRouter(featureName, paths.routesDir);
|
|
1968
|
-
console.log(
|
|
1969
|
-
import_ansi_colors6.default.bgGreen(
|
|
1970
|
-
import_ansi_colors6.default.white(`
|
|
1750
|
+
var simpleComponentTemplate = async (featureName) => {
|
|
1751
|
+
FeatureComponentGeneratorUtils.setStructure("simple");
|
|
1752
|
+
const basePath = import_path3.default.join("src", "features", featureName);
|
|
1753
|
+
const dirs = [
|
|
1754
|
+
import_path3.default.join(basePath, "routes"),
|
|
1755
|
+
import_path3.default.join(basePath, "controllers"),
|
|
1756
|
+
import_path3.default.join(basePath, "services"),
|
|
1757
|
+
import_path3.default.join(basePath, "repositories"),
|
|
1758
|
+
import_path3.default.join(basePath, "models")
|
|
1759
|
+
];
|
|
1760
|
+
dirs.forEach((dir) => UFsModule.createDirectoryRecursively(dir));
|
|
1761
|
+
const paths = {
|
|
1762
|
+
modelsDir: import_path3.default.join(basePath, "models"),
|
|
1763
|
+
repositoriesDir: import_path3.default.join(basePath, "repositories"),
|
|
1764
|
+
servicesDir: import_path3.default.join(basePath, "services"),
|
|
1765
|
+
controllersDir: import_path3.default.join(basePath, "controllers"),
|
|
1766
|
+
routesDir: import_path3.default.join(basePath, "routes")
|
|
1767
|
+
};
|
|
1768
|
+
await FeatureComponentGeneratorUtils.createModel(featureName, paths.modelsDir);
|
|
1769
|
+
await FeatureComponentGeneratorUtils.createSimpleRepository(featureName, paths.repositoriesDir);
|
|
1770
|
+
await FeatureComponentGeneratorUtils.createSimpleService(featureName, paths.servicesDir);
|
|
1771
|
+
const controller = await FeatureComponentGeneratorUtils.createSimpleController(
|
|
1772
|
+
featureName,
|
|
1773
|
+
paths.controllersDir
|
|
1774
|
+
);
|
|
1775
|
+
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, paths.routesDir, controller.methods);
|
|
1776
|
+
await FeatureComponentGeneratorUtils.createRouter(featureName, paths.routesDir);
|
|
1777
|
+
console.log(
|
|
1778
|
+
import_ansi_colors6.default.bgGreen(
|
|
1779
|
+
import_ansi_colors6.default.white(`
|
|
1971
1780
|
\u{1F389} Feature "${featureName}" scaffolded with Simple Component!
|
|
1972
1781
|
`)
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1782
|
+
)
|
|
1783
|
+
);
|
|
1784
|
+
};
|
|
1978
1785
|
|
|
1979
1786
|
// src/templates/fullCleanComponent/fullCleanComponent.template.ts
|
|
1980
|
-
var import_path4
|
|
1981
|
-
var
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
import_path4
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
paths.controllerDir
|
|
2033
|
-
);
|
|
2034
|
-
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, paths.routerDir, controller.methods);
|
|
2035
|
-
await FeatureComponentGeneratorUtils.createRouter(featureName, paths.routerDir);
|
|
2036
|
-
console.log(
|
|
2037
|
-
import_ansi_colors7.default.bgGreen(
|
|
2038
|
-
import_ansi_colors7.default.white(`
|
|
1787
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
1788
|
+
var import_ansi_colors7 = __toESM(require("ansi-colors"), 1);
|
|
1789
|
+
var fullCleanComponentTemplate = async (featureName) => {
|
|
1790
|
+
const basePath = import_path4.default.join("src", "features", featureName);
|
|
1791
|
+
const dirs = [
|
|
1792
|
+
import_path4.default.join(basePath, "domain", "entities"),
|
|
1793
|
+
import_path4.default.join(basePath, "domain", "events"),
|
|
1794
|
+
import_path4.default.join(basePath, "domain", "exceptions"),
|
|
1795
|
+
import_path4.default.join(basePath, "application", "use-cases"),
|
|
1796
|
+
import_path4.default.join(basePath, "application", "dtos"),
|
|
1797
|
+
import_path4.default.join(basePath, "application", "ports", "repositories"),
|
|
1798
|
+
import_path4.default.join(basePath, "application", "ports", "presenters"),
|
|
1799
|
+
import_path4.default.join(basePath, "application", "ports", "services"),
|
|
1800
|
+
import_path4.default.join(basePath, "infrastructure", "adapters", "controllers"),
|
|
1801
|
+
import_path4.default.join(basePath, "infrastructure", "adapters", "repositories"),
|
|
1802
|
+
import_path4.default.join(basePath, "infrastructure", "adapters", "presenters"),
|
|
1803
|
+
import_path4.default.join(basePath, "infrastructure", "routes")
|
|
1804
|
+
];
|
|
1805
|
+
dirs.forEach((dir) => UFsModule.createDirectoryRecursively(dir));
|
|
1806
|
+
const paths = {
|
|
1807
|
+
entityDir: import_path4.default.join(basePath, "domain", "entities"),
|
|
1808
|
+
eventDir: import_path4.default.join(basePath, "domain", "events"),
|
|
1809
|
+
exceptionDir: import_path4.default.join(basePath, "domain", "exceptions"),
|
|
1810
|
+
repositoryInterfaceDir: import_path4.default.join(basePath, "application", "ports", "repositories"),
|
|
1811
|
+
presenterInterfaceDir: import_path4.default.join(basePath, "application", "ports", "presenters"),
|
|
1812
|
+
serviceDir: import_path4.default.join(basePath, "application", "ports", "services"),
|
|
1813
|
+
dtoDir: import_path4.default.join(basePath, "application", "dtos"),
|
|
1814
|
+
useCaseDir: import_path4.default.join(basePath, "application", "use-cases"),
|
|
1815
|
+
repositoryImplDir: import_path4.default.join(basePath, "infrastructure", "adapters", "repositories"),
|
|
1816
|
+
presenterImplDir: import_path4.default.join(basePath, "infrastructure", "adapters", "presenters"),
|
|
1817
|
+
controllerDir: import_path4.default.join(basePath, "infrastructure", "adapters", "controllers"),
|
|
1818
|
+
routerDir: import_path4.default.join(basePath, "infrastructure", "routes")
|
|
1819
|
+
};
|
|
1820
|
+
await FeatureComponentGeneratorUtils.createEntity(featureName, paths.entityDir);
|
|
1821
|
+
await FeatureComponentGeneratorUtils.createEvent(featureName, paths.eventDir);
|
|
1822
|
+
await FeatureComponentGeneratorUtils.createException(featureName, paths.exceptionDir);
|
|
1823
|
+
await FeatureComponentGeneratorUtils.createRepositoryInterface(featureName, paths.repositoryInterfaceDir);
|
|
1824
|
+
await FeatureComponentGeneratorUtils.createPresenterInterface(featureName, paths.presenterInterfaceDir);
|
|
1825
|
+
await FeatureComponentGeneratorUtils.createService(featureName, paths.serviceDir);
|
|
1826
|
+
await FeatureComponentGeneratorUtils.createDto(featureName, paths.dtoDir);
|
|
1827
|
+
await FeatureComponentGeneratorUtils.createUseCase(featureName, paths.useCaseDir);
|
|
1828
|
+
await FeatureComponentGeneratorUtils.createRepositoryImpl(featureName, paths.repositoryImplDir);
|
|
1829
|
+
await FeatureComponentGeneratorUtils.createPresenterImpl(featureName, paths.presenterImplDir);
|
|
1830
|
+
const controller = await FeatureComponentGeneratorUtils.createController(
|
|
1831
|
+
featureName,
|
|
1832
|
+
paths.controllerDir
|
|
1833
|
+
);
|
|
1834
|
+
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, paths.routerDir, controller.methods);
|
|
1835
|
+
await FeatureComponentGeneratorUtils.createRouter(featureName, paths.routerDir);
|
|
1836
|
+
console.log(
|
|
1837
|
+
import_ansi_colors7.default.bgGreen(
|
|
1838
|
+
import_ansi_colors7.default.white(`
|
|
2039
1839
|
\u{1F389} Feature "${featureName}" scaffolded with Clean Architecture!
|
|
2040
1840
|
`)
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
}
|
|
2045
|
-
});
|
|
1841
|
+
)
|
|
1842
|
+
);
|
|
1843
|
+
};
|
|
2046
1844
|
|
|
2047
1845
|
// src/templates/cleanComponentByStep/cleanComponentByStep.template.ts
|
|
2048
|
-
var import_path5
|
|
2049
|
-
var
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
track();
|
|
2132
|
-
}
|
|
2133
|
-
if (created === 0) {
|
|
2134
|
-
console.log(import_ansi_colors8.default.yellow(`
|
|
2135
|
-
\u26A0\uFE0F No files were created for feature "${featureName}".`));
|
|
2136
|
-
} else {
|
|
2137
|
-
console.log(
|
|
2138
|
-
import_ansi_colors8.default.bgGreen(import_ansi_colors8.default.white(`
|
|
1846
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
1847
|
+
var import_ansi_colors8 = __toESM(require("ansi-colors"), 1);
|
|
1848
|
+
var import_prompts4 = require("@clack/prompts");
|
|
1849
|
+
var cleanComponentByStepTemplate = async (featureName) => {
|
|
1850
|
+
const base = import_path5.default.join("src", "features", featureName);
|
|
1851
|
+
let created = 0;
|
|
1852
|
+
let controller = { controllerName: "", methods: [] };
|
|
1853
|
+
const ask = async (label) => {
|
|
1854
|
+
const answer = await UPrompt.confirm(label, false);
|
|
1855
|
+
if ((0, import_prompts4.isCancel)(answer)) {
|
|
1856
|
+
UFsModule.removeDir(base, true, true);
|
|
1857
|
+
process.exit(0);
|
|
1858
|
+
}
|
|
1859
|
+
return answer;
|
|
1860
|
+
};
|
|
1861
|
+
const track = () => {
|
|
1862
|
+
created++;
|
|
1863
|
+
};
|
|
1864
|
+
console.log(import_ansi_colors8.default.bold(import_ansi_colors8.default.cyan("\n Domain ")));
|
|
1865
|
+
const mkDir = (dir) => {
|
|
1866
|
+
UFsModule.createDirectoryRecursively(dir);
|
|
1867
|
+
return dir;
|
|
1868
|
+
};
|
|
1869
|
+
if (await ask(`Entity - ${featureName}.entity.ts`)) {
|
|
1870
|
+
await FeatureComponentGeneratorUtils.createEntity(featureName, mkDir(import_path5.default.join(base, "domain", "entities")));
|
|
1871
|
+
track();
|
|
1872
|
+
}
|
|
1873
|
+
if (await ask(`Event - ${featureName}.event.ts`)) {
|
|
1874
|
+
await FeatureComponentGeneratorUtils.createEvent(featureName, mkDir(import_path5.default.join(base, "domain", "events")));
|
|
1875
|
+
track();
|
|
1876
|
+
}
|
|
1877
|
+
if (await ask(`Exception - ${featureName}.exception.ts`)) {
|
|
1878
|
+
await FeatureComponentGeneratorUtils.createException(featureName, mkDir(import_path5.default.join(base, "domain", "exceptions")));
|
|
1879
|
+
track();
|
|
1880
|
+
}
|
|
1881
|
+
console.log(import_ansi_colors8.default.bold(import_ansi_colors8.default.cyan("\n Application ")));
|
|
1882
|
+
if (await ask(`Repo Interface - ${featureName}.repository.interface.ts`)) {
|
|
1883
|
+
await FeatureComponentGeneratorUtils.createRepositoryInterface(featureName, mkDir(import_path5.default.join(base, "application", "ports", "repositories")));
|
|
1884
|
+
track();
|
|
1885
|
+
}
|
|
1886
|
+
if (await ask(`Presenter Port - ${featureName}.presenter.interface.ts`)) {
|
|
1887
|
+
await FeatureComponentGeneratorUtils.createPresenterInterface(featureName, mkDir(import_path5.default.join(base, "application", "ports", "presenters")));
|
|
1888
|
+
track();
|
|
1889
|
+
}
|
|
1890
|
+
if (await ask(`Service Port - ${featureName}.service.ts`)) {
|
|
1891
|
+
await FeatureComponentGeneratorUtils.createService(featureName, mkDir(import_path5.default.join(base, "application", "ports", "services")));
|
|
1892
|
+
track();
|
|
1893
|
+
}
|
|
1894
|
+
if (await ask(`DTO - ${featureName}.dto.ts`)) {
|
|
1895
|
+
await FeatureComponentGeneratorUtils.createDto(featureName, mkDir(import_path5.default.join(base, "application", "dtos")));
|
|
1896
|
+
track();
|
|
1897
|
+
}
|
|
1898
|
+
if (await ask(`Use Case - ${featureName}.usecase.ts`)) {
|
|
1899
|
+
await FeatureComponentGeneratorUtils.createUseCase(featureName, mkDir(import_path5.default.join(base, "application", "use-cases")));
|
|
1900
|
+
track();
|
|
1901
|
+
}
|
|
1902
|
+
console.log(import_ansi_colors8.default.bold(import_ansi_colors8.default.cyan("\n Infrastructure ")));
|
|
1903
|
+
if (await ask(`Repo Impl - ${featureName}.repository.ts`)) {
|
|
1904
|
+
await FeatureComponentGeneratorUtils.createRepositoryImpl(featureName, mkDir(import_path5.default.join(base, "infrastructure", "adapters", "repositories")));
|
|
1905
|
+
track();
|
|
1906
|
+
}
|
|
1907
|
+
if (await ask(`Presenter Impl - ${featureName}.presenter.ts`)) {
|
|
1908
|
+
await FeatureComponentGeneratorUtils.createPresenterImpl(featureName, mkDir(import_path5.default.join(base, "infrastructure", "adapters", "presenters")));
|
|
1909
|
+
track();
|
|
1910
|
+
}
|
|
1911
|
+
if (await ask(`Controller - ${featureName}.controller.ts`)) {
|
|
1912
|
+
controller = await FeatureComponentGeneratorUtils.createController(featureName, mkDir(import_path5.default.join(base, "infrastructure", "adapters", "controllers")));
|
|
1913
|
+
track();
|
|
1914
|
+
}
|
|
1915
|
+
if (await ask(`Router Handler - ${featureName}.router.handler.ts`)) {
|
|
1916
|
+
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, mkDir(import_path5.default.join(base, "infrastructure", "routes")), controller.methods);
|
|
1917
|
+
track();
|
|
1918
|
+
}
|
|
1919
|
+
if (await ask(`Router - ${featureName}.router.ts`)) {
|
|
1920
|
+
await FeatureComponentGeneratorUtils.createRouter(featureName, mkDir(import_path5.default.join(base, "infrastructure", "routes")));
|
|
1921
|
+
track();
|
|
1922
|
+
}
|
|
1923
|
+
if (created === 0) {
|
|
1924
|
+
console.log(import_ansi_colors8.default.yellow(`
|
|
1925
|
+
\u26A0 No files were created for feature "${featureName}".`));
|
|
1926
|
+
} else {
|
|
1927
|
+
console.log(
|
|
1928
|
+
import_ansi_colors8.default.bgGreen(import_ansi_colors8.default.white(`
|
|
2139
1929
|
\u{1F389} Feature "${featureName}" \u2014 ${created} file(s) created step by step.
|
|
2140
1930
|
`))
|
|
2141
|
-
|
|
2142
|
-
}
|
|
2143
|
-
};
|
|
1931
|
+
);
|
|
2144
1932
|
}
|
|
2145
|
-
}
|
|
1933
|
+
};
|
|
2146
1934
|
|
|
2147
1935
|
// src/core/components/application/createController.application.ts
|
|
2148
|
-
var
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
} else {
|
|
2173
|
-
switch (askComponentType) {
|
|
2174
|
-
case CCleanType.simple_component:
|
|
2175
|
-
await simpleComponentTemplate(featureName);
|
|
2176
|
-
break;
|
|
2177
|
-
case CCleanType.clean_component_by_step:
|
|
2178
|
-
await cleanComponentByStepTemplate(featureName);
|
|
2179
|
-
break;
|
|
2180
|
-
case CCleanType.full_clean_component:
|
|
2181
|
-
await fullCleanComponentTemplate(featureName);
|
|
2182
|
-
break;
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
};
|
|
1936
|
+
var createComponentApplication = async (featureDirectory, featureName) => {
|
|
1937
|
+
const askComponentType = await _controllerType(
|
|
1938
|
+
"Choose a type of component :",
|
|
1939
|
+
CCleanType.full_clean_component,
|
|
1940
|
+
[
|
|
1941
|
+
{ label: "Simple component", value: [CCleanType.simple_component] },
|
|
1942
|
+
{ label: "CLEAN Architecture component by step", value: [CCleanType.clean_component_by_step] },
|
|
1943
|
+
{ label: "Full CLEAN Architecture component", value: [CCleanType.full_clean_component] }
|
|
1944
|
+
]
|
|
1945
|
+
);
|
|
1946
|
+
if ((0, import_prompts5.isCancel)(askComponentType) === true || askComponentType === void 0) {
|
|
1947
|
+
BaseService._cancelOperation(featureDirectory);
|
|
1948
|
+
} else {
|
|
1949
|
+
switch (askComponentType) {
|
|
1950
|
+
case CCleanType.simple_component:
|
|
1951
|
+
await simpleComponentTemplate(featureName);
|
|
1952
|
+
break;
|
|
1953
|
+
case CCleanType.clean_component_by_step:
|
|
1954
|
+
await cleanComponentByStepTemplate(featureName);
|
|
1955
|
+
break;
|
|
1956
|
+
case CCleanType.full_clean_component:
|
|
1957
|
+
await fullCleanComponentTemplate(featureName);
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
2186
1960
|
}
|
|
2187
|
-
}
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1963
|
+
// src/templates/customModule/buildYourOwnArchitectureScaffold.template.ts
|
|
1964
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
1965
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
1966
|
+
var import_ansi_colors9 = __toESM(require("ansi-colors"), 1);
|
|
1967
|
+
var import_prompts6 = require("@clack/prompts");
|
|
2188
1968
|
|
|
2189
1969
|
// src/core/domains/constants/resolveRoute.constant.ts
|
|
2190
|
-
var CResolveRoute
|
|
2191
|
-
|
|
2192
|
-
"
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
if (lower.includes("create") || lower.includes("add")) return { httpMethod: "post", path: `/${moduleName}` };
|
|
2200
|
-
if (lower.includes("update") || lower.includes("edit")) return { httpMethod: "put", path: `/${moduleName}/:id` };
|
|
2201
|
-
if (lower.includes("delete") || lower.includes("remove")) return { httpMethod: "delete", path: `/${moduleName}/:id` };
|
|
2202
|
-
return { httpMethod: "get", path: `/${moduleName}/${lower}` };
|
|
2203
|
-
};
|
|
2204
|
-
}
|
|
2205
|
-
});
|
|
1970
|
+
var CResolveRoute = (methodName, moduleName) => {
|
|
1971
|
+
const lower = methodName.toLowerCase();
|
|
1972
|
+
if (lower.includes("findall") || lower.includes("getall")) return { httpMethod: "get", path: `/${moduleName}` };
|
|
1973
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) return { httpMethod: "get", path: `/${moduleName}/:id` };
|
|
1974
|
+
if (lower.includes("create") || lower.includes("add")) return { httpMethod: "post", path: `/${moduleName}` };
|
|
1975
|
+
if (lower.includes("update") || lower.includes("edit")) return { httpMethod: "put", path: `/${moduleName}/:id` };
|
|
1976
|
+
if (lower.includes("delete") || lower.includes("remove")) return { httpMethod: "delete", path: `/${moduleName}/:id` };
|
|
1977
|
+
return { httpMethod: "get", path: `/${moduleName}/${lower}` };
|
|
1978
|
+
};
|
|
2206
1979
|
|
|
2207
|
-
// src/templates/customModule/
|
|
2208
|
-
var capitalize17
|
|
2209
|
-
var
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
init_cjs_shims();
|
|
2213
|
-
init_resolveRoute_constant();
|
|
2214
|
-
capitalize17 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2215
|
-
generateCustomControllerTemplate = (controllerName, moduleName, methods) => {
|
|
2216
|
-
const cap = capitalize17(moduleName);
|
|
2217
|
-
const serviceName = `${cap}Service`;
|
|
2218
|
-
const body = methods.length === 0 ? ` // TODO: add your handler methods here` : methods.map((m) => generateMethod3(m, cap, serviceName)).join("\n");
|
|
2219
|
-
const serviceImport = methods.length === 0 ? `` : `import { ${serviceName} } from "./${moduleName}.service";
|
|
2220
|
-
`;
|
|
2221
|
-
return `import { Request, Response } from "opticore-express";
|
|
2222
|
-
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
2223
|
-
${serviceImport}
|
|
2224
|
-
export class ${controllerName} {${methods.length > 0 ? `
|
|
2225
|
-
private static buildService(): ${serviceName} {
|
|
2226
|
-
return new ${serviceName}();
|
|
2227
|
-
}
|
|
2228
|
-
` : ""}
|
|
2229
|
-
${body}
|
|
2230
|
-
private static handleError(error: unknown) {
|
|
2231
|
-
const message = error instanceof Error ? error.message : "Internal server error";
|
|
2232
|
-
return ResponseHandler.error(message, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
2233
|
-
}
|
|
2234
|
-
}`.trimEnd();
|
|
2235
|
-
};
|
|
2236
|
-
generateMethod3 = (method, cap, serviceName) => {
|
|
2237
|
-
const lower = method.toLowerCase();
|
|
2238
|
-
if (lower.includes("findall") || lower.includes("getall")) return methodFindAll(method, cap);
|
|
2239
|
-
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) return methodFindById(method, cap);
|
|
2240
|
-
if (lower.includes("create") || lower.includes("add")) return methodCreate(method, cap);
|
|
2241
|
-
if (lower.includes("update") || lower.includes("edit")) return methodUpdate(method, cap);
|
|
2242
|
-
if (lower.includes("delete") || lower.includes("remove")) return methodDelete(method, cap);
|
|
2243
|
-
return `
|
|
1980
|
+
// src/templates/customModule/buildYourOwnArchitecture.template.ts
|
|
1981
|
+
var capitalize17 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1982
|
+
var generateBuildYourOwnControllerTemplate = (fileName, methods) => {
|
|
1983
|
+
const controllerName = `${capitalize17(fileName)}Controller`;
|
|
1984
|
+
const body = methods.length === 0 ? ` // TODO: add your handler methods here` : methods.map((method) => `
|
|
2244
1985
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2245
1986
|
try {
|
|
2246
|
-
const service = ${cap}Controller.buildService();
|
|
2247
1987
|
// TODO: implement ${method}
|
|
2248
1988
|
return ResponseHandler.success({}, "success", HttpStatusCode.OK);
|
|
2249
1989
|
} catch (error) {
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
}`;
|
|
2253
|
-
};
|
|
2254
|
-
methodFindAll = (m, cap) => `
|
|
2255
|
-
static async ${m}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2256
|
-
try {
|
|
2257
|
-
const service = ${cap}Controller.buildService();
|
|
2258
|
-
const results = await service.findAll();
|
|
2259
|
-
return ResponseHandler.success(results, "success", HttpStatusCode.OK);
|
|
2260
|
-
} catch (error) {
|
|
2261
|
-
return ${cap}Controller.handleError(error);
|
|
2262
|
-
}
|
|
2263
|
-
}`;
|
|
2264
|
-
methodFindById = (m, cap) => `
|
|
2265
|
-
static async ${m}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2266
|
-
try {
|
|
2267
|
-
const { id } = req.params;
|
|
2268
|
-
const service = ${cap}Controller.buildService();
|
|
2269
|
-
const result = await service.findById(id);
|
|
2270
|
-
if (!result) return ResponseHandler.error(\`Not found: \${id}\`, HttpStatusCode.NOT_FOUND);
|
|
2271
|
-
return ResponseHandler.success(result, "success", HttpStatusCode.OK);
|
|
2272
|
-
} catch (error) {
|
|
2273
|
-
return ${cap}Controller.handleError(error);
|
|
2274
|
-
}
|
|
2275
|
-
}`;
|
|
2276
|
-
methodCreate = (m, cap) => `
|
|
2277
|
-
static async ${m}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2278
|
-
try {
|
|
2279
|
-
const service = ${cap}Controller.buildService();
|
|
2280
|
-
const result = await service.create(req.body);
|
|
2281
|
-
return ResponseHandler.success(result, "created", HttpStatusCode.CREATED);
|
|
2282
|
-
} catch (error) {
|
|
2283
|
-
return ${cap}Controller.handleError(error);
|
|
1990
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
1991
|
+
return ResponseHandler.error(message, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
2284
1992
|
}
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
// TODO: implement
|
|
2323
|
-
return data;
|
|
2324
|
-
}
|
|
2325
|
-
async update(id: string, data: Record<string, unknown>): Promise<unknown | null> {
|
|
2326
|
-
// TODO: implement
|
|
2327
|
-
return null;
|
|
2328
|
-
}
|
|
2329
|
-
async delete(id: string): Promise<boolean> {
|
|
2330
|
-
// TODO: implement
|
|
2331
|
-
return false;
|
|
2332
|
-
}
|
|
2333
|
-
}`.trimEnd();
|
|
2334
|
-
};
|
|
2335
|
-
generateCustomRepositoryTemplate = (moduleName) => {
|
|
2336
|
-
const cap = capitalize17(moduleName);
|
|
2337
|
-
const name = moduleName.toLowerCase();
|
|
2338
|
-
const isAuthRelated = name.includes("auth") || name.includes("authenticate") || name.includes("authentication") || name.includes("login") || name.includes("security") || name.includes("session") || name.includes("connect") || name.includes("connexion") || name.includes("connection");
|
|
2339
|
-
if (isAuthRelated) {
|
|
2340
|
-
return `export class ${cap}Repository {
|
|
2341
|
-
// TODO: inject your data source (ORM, DB client, etc.)
|
|
2342
|
-
|
|
2343
|
-
async findByEmail(email: string): Promise<User | null> {
|
|
2344
|
-
throw new Error("Not implemented");
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
async findByUsernameOrEmail(identity: string): Promise<User | null> {
|
|
2348
|
-
throw new Error("Not implemented");
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
async updateLastLogin(userId: string, date: Date): Promise<void> {
|
|
2352
|
-
throw new Error("Not implemented");
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
async incrementLoginAttempts(userId: string): Promise<number> {
|
|
2356
|
-
throw new Error("Not implemented");
|
|
2357
|
-
}
|
|
2358
|
-
|
|
2359
|
-
async resetLoginAttempts(userId: string): Promise<void> {
|
|
2360
|
-
throw new Error("Not implemented");
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
async saveToken(userId: string, token: string): Promise<void> {
|
|
2364
|
-
throw new Error("Not implemented");
|
|
2365
|
-
}
|
|
2366
|
-
}`.trimEnd();
|
|
2367
|
-
}
|
|
2368
|
-
return `export class ${cap}Repository {
|
|
2369
|
-
// TODO: inject your data source (ORM, DB client, etc.)
|
|
2370
|
-
async findAll(): Promise<unknown[]> { throw new Error("Not implemented"); }
|
|
2371
|
-
async findById(id: string): Promise<unknown | null> { throw new Error("Not implemented"); }
|
|
2372
|
-
async create(data: Record<string, unknown>): Promise<unknown> { throw new Error("Not implemented"); }
|
|
2373
|
-
async update(id: string, data: Record<string, unknown>): Promise<unknown | null> { throw new Error("Not implemented"); }
|
|
2374
|
-
async delete(id: string): Promise<boolean> { throw new Error("Not implemented"); }
|
|
2375
|
-
}`.trimEnd();
|
|
2376
|
-
};
|
|
2377
|
-
generateCustomModelTemplate = (moduleName) => {
|
|
2378
|
-
const cap = capitalize17(moduleName);
|
|
2379
|
-
return `export class ${cap}Model {
|
|
1993
|
+
}`).join("\n");
|
|
1994
|
+
return `import { Request, Response } from "opticore-express";
|
|
1995
|
+
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
1996
|
+
|
|
1997
|
+
export class ${controllerName} {
|
|
1998
|
+
${body}
|
|
1999
|
+
}`.trimEnd() + "\n";
|
|
2000
|
+
};
|
|
2001
|
+
var generateBuildYourOwnServiceClassTemplate = (fileName, methods) => {
|
|
2002
|
+
const serviceName = `${capitalize17(fileName)}Service`;
|
|
2003
|
+
const body = methods.length === 0 ? ` // TODO: add your service methods here` : methods.map((method) => `
|
|
2004
|
+
async ${method}(): Promise<unknown> {
|
|
2005
|
+
// TODO: implement ${method}
|
|
2006
|
+
throw new Error("Not implemented");
|
|
2007
|
+
}`).join("\n");
|
|
2008
|
+
return `export class ${serviceName} {
|
|
2009
|
+
${body}
|
|
2010
|
+
}`.trimEnd() + "\n";
|
|
2011
|
+
};
|
|
2012
|
+
var generateBuildYourOwnServiceFunctionTemplate = (fileName) => {
|
|
2013
|
+
const functionName = `${fileName}Service`;
|
|
2014
|
+
return `export async function ${functionName}(): Promise<unknown> {
|
|
2015
|
+
// TODO: implement ${functionName}
|
|
2016
|
+
throw new Error("Not implemented");
|
|
2017
|
+
}`.trimEnd() + "\n";
|
|
2018
|
+
};
|
|
2019
|
+
var generateBuildYourOwnDtoTemplate = (fileName, fields) => {
|
|
2020
|
+
const dtoName = `${capitalize17(fileName)}Dto`;
|
|
2021
|
+
const body = fields.length === 0 ? ` // TODO: define the fields of this DTO` : fields.map((field) => ` ${field.name}: ${field.type};`).join("\n");
|
|
2022
|
+
return `export interface ${dtoName} {
|
|
2023
|
+
${body}
|
|
2024
|
+
}`.trimEnd() + "\n";
|
|
2025
|
+
};
|
|
2026
|
+
var generateBuildYourOwnEntityTemplate = (fileName, properties) => {
|
|
2027
|
+
const entityName = `${capitalize17(fileName)}Entity`;
|
|
2028
|
+
const ctorParams = properties.length === 0 ? ` // TODO: define the properties of this entity` : properties.map((prop) => ` public readonly ${prop.name}: ${prop.type},`).join("\n");
|
|
2029
|
+
return `export class ${entityName} {
|
|
2380
2030
|
constructor(
|
|
2381
|
-
|
|
2382
|
-
// TODO: add your fields here
|
|
2031
|
+
${ctorParams}
|
|
2383
2032
|
) {}
|
|
2384
|
-
}`.trimEnd();
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
// TODO:
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
this.name = "${cap}NotFoundError";
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
export class ${cap}ValidationError extends Error {
|
|
2409
|
-
constructor(message: string) {
|
|
2410
|
-
super(message);
|
|
2411
|
-
this.name = "${cap}ValidationError";
|
|
2412
|
-
}
|
|
2413
|
-
}`.trimEnd();
|
|
2414
|
-
};
|
|
2415
|
-
generateCustomConstantsTemplate = (moduleName) => `// ${moduleName} constants
|
|
2416
|
-
export const ${moduleName.toUpperCase()}_PREFIX = "/${moduleName}";
|
|
2417
|
-
// TODO: add your constants here`.trimEnd();
|
|
2418
|
-
generateCustomRouterHandlerTemplate = (moduleName, controllerMethods) => {
|
|
2419
|
-
const cap = capitalize17(moduleName);
|
|
2420
|
-
const handlerName = `${cap}HandlerRouter`;
|
|
2421
|
-
const controllerName = `${cap}Controller`;
|
|
2422
|
-
const routesCode = (controllerMethods || []).map((method) => {
|
|
2423
|
-
const { httpMethod, path: path10 } = CResolveRoute(method, moduleName);
|
|
2424
|
-
return `{
|
|
2425
|
-
path: \`${path10}\`,
|
|
2426
|
-
method: "${httpMethod}",
|
|
2033
|
+
}`.trimEnd() + "\n";
|
|
2034
|
+
};
|
|
2035
|
+
var generateBuildYourOwnRepositoryTemplate = (fileName, methods) => {
|
|
2036
|
+
const repositoryName = `${capitalize17(fileName)}Repository`;
|
|
2037
|
+
const body = methods.length === 0 ? ` // TODO: define the actions this repository can perform` : methods.map((method) => ` async ${method}(): Promise<unknown> { throw new Error("Not implemented"); }`).join("\n");
|
|
2038
|
+
return `export class ${repositoryName} {
|
|
2039
|
+
// TODO: inject your data source (ORM, DB client, etc.)
|
|
2040
|
+
${body}
|
|
2041
|
+
}`.trimEnd() + "\n";
|
|
2042
|
+
};
|
|
2043
|
+
var generateBuildYourOwnRouteTemplate = (fileName, actions) => {
|
|
2044
|
+
const capitalized = capitalize17(fileName);
|
|
2045
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
2046
|
+
const controllerName = `${capitalized}Controller`;
|
|
2047
|
+
const routes = actions.map((action) => {
|
|
2048
|
+
const { httpMethod, path: path10 } = CResolveRoute(action, fileName);
|
|
2049
|
+
return { httpMethod, path: path10, action };
|
|
2050
|
+
});
|
|
2051
|
+
const body = routes.length === 0 ? ` // TODO: define the routes for this module` : routes.map((route) => `{
|
|
2052
|
+
path: "${route.path}",
|
|
2053
|
+
method: "${route.httpMethod}",
|
|
2427
2054
|
middlewares: [],
|
|
2428
|
-
handler: async (ctx: ICustomContext) => await ${controllerName}.${
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
import { ${controllerName} } from "
|
|
2055
|
+
handler: async (ctx: ICustomContext) => await ${controllerName}.${route.action}(ctx.req, ctx.res)
|
|
2056
|
+
}`).join(",\n").replace(/\n/g, "\n ");
|
|
2057
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
2058
|
+
// TODO: adjust this import if "${controllerName}" lives in a different folder
|
|
2059
|
+
import { ${controllerName} } from "./${fileName}.controller";
|
|
2433
2060
|
|
|
2434
2061
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
2435
2062
|
return OpticoreRoutingFactory.routes(
|
|
2436
2063
|
${controllerName},
|
|
2437
2064
|
[
|
|
2438
|
-
${
|
|
2065
|
+
${body}
|
|
2439
2066
|
]
|
|
2440
2067
|
);
|
|
2441
|
-
};`.trimEnd();
|
|
2442
|
-
|
|
2443
|
-
generateCustomRouterTemplate = (moduleName) => {
|
|
2444
|
-
const cap = capitalize17(moduleName);
|
|
2445
|
-
const handlerName = `${cap}HandlerRouter`;
|
|
2446
|
-
const routerName = `${cap}Router`;
|
|
2447
|
-
return `import { ${handlerName} } from "./core/handler/${moduleName}.router.handler";
|
|
2448
|
-
import { TFeatureRoutes } from "opticore-router";
|
|
2068
|
+
};`.trimEnd() + "\n";
|
|
2069
|
+
};
|
|
2449
2070
|
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2071
|
+
// src/templates/customModule/buildYourOwnArchitectureScaffold.template.ts
|
|
2072
|
+
var ok = (msg) => {
|
|
2073
|
+
console.log(import_ansi_colors9.default.green(`\u2714 ${msg}`));
|
|
2074
|
+
};
|
|
2075
|
+
var info = (msg) => {
|
|
2076
|
+
console.log(import_ansi_colors9.default.cyan(`\u2139 ${msg}`));
|
|
2077
|
+
};
|
|
2078
|
+
var NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
2079
|
+
var askName = async (message, placeholder) => {
|
|
2080
|
+
const raw = await UPrompt.text(message, placeholder, (value) => {
|
|
2081
|
+
if (!value) {
|
|
2082
|
+
return "Please enter a name.";
|
|
2083
|
+
}
|
|
2084
|
+
if (!NAME_PATTERN.test(value)) {
|
|
2085
|
+
return "Use letters, numbers, - or _, starting with a letter.";
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
if ((0, import_prompts6.isCancel)(raw)) {
|
|
2089
|
+
return void 0;
|
|
2459
2090
|
}
|
|
2091
|
+
return raw;
|
|
2092
|
+
};
|
|
2093
|
+
var askCommaSeparatedList = async (message, placeholder) => {
|
|
2094
|
+
const raw = await UPrompt.text(message, placeholder, () => void 0);
|
|
2095
|
+
if ((0, import_prompts6.isCancel)(raw) || !raw) return [];
|
|
2096
|
+
return raw.split(",").map((v) => v.trim()).filter(Boolean);
|
|
2097
|
+
};
|
|
2098
|
+
var parseFieldDefinitions = (raw) => raw.map((entry) => {
|
|
2099
|
+
const [name, type] = entry.split(":").map((v) => v.trim());
|
|
2100
|
+
return { name: name || entry, type: type || "string" };
|
|
2460
2101
|
});
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2102
|
+
var renderTree = (node, prefix = "") => {
|
|
2103
|
+
const lines = [];
|
|
2104
|
+
const children = node.children ?? [];
|
|
2105
|
+
children.forEach((child, index) => {
|
|
2106
|
+
const isLast = index === children.length - 1;
|
|
2107
|
+
const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
2108
|
+
lines.push(`${prefix}${branch}${child.name}${child.type === "dir" ? "/" : ""}`);
|
|
2109
|
+
if (child.type === "dir") {
|
|
2110
|
+
const nextPrefix = prefix + (isLast ? " " : "\u2502 ");
|
|
2111
|
+
lines.push(...renderTree(child, nextPrefix));
|
|
2112
|
+
}
|
|
2113
|
+
});
|
|
2114
|
+
return lines;
|
|
2115
|
+
};
|
|
2116
|
+
var printTree = (root) => {
|
|
2117
|
+
console.log(import_ansi_colors9.default.yellow(`${root.name}/`));
|
|
2118
|
+
renderTree(root).forEach((line) => console.log(import_ansi_colors9.default.yellow(line)));
|
|
2119
|
+
};
|
|
2120
|
+
async function handleFileCreation(dirPath) {
|
|
2121
|
+
const fileType = await UPrompt.select(
|
|
2122
|
+
"What type of file do you want to create?",
|
|
2123
|
+
["controller"],
|
|
2124
|
+
[
|
|
2125
|
+
{ label: "Controller", value: ["controller"] },
|
|
2126
|
+
{ label: "Service", value: ["service"] },
|
|
2127
|
+
{ label: "DTO", value: ["dto"] },
|
|
2128
|
+
{ label: "Entity", value: ["entity"] },
|
|
2129
|
+
{ label: "Repository", value: ["repository"] },
|
|
2130
|
+
{ label: "Route", value: ["route"] }
|
|
2131
|
+
]
|
|
2474
2132
|
);
|
|
2475
|
-
if ((0,
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
"
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
init_prompt_utils();
|
|
2489
|
-
init_featureName_service();
|
|
2490
|
-
init_customModule_template();
|
|
2491
|
-
init_featureComponentGenerator_utils();
|
|
2492
|
-
ok = (msg) => {
|
|
2493
|
-
console.log(import_ansi_colors9.default.green(`\u2705 ${msg}`));
|
|
2494
|
-
};
|
|
2495
|
-
tip = (msg) => {
|
|
2496
|
-
console.log(import_ansi_colors9.default.yellow(` ${msg}`));
|
|
2497
|
-
};
|
|
2498
|
-
capitalize18 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2499
|
-
customModuleScaffoldTemplate = async () => {
|
|
2500
|
-
const rawName = await _featureName();
|
|
2501
|
-
if ((0, import_prompts5.isCancel)(rawName)) {
|
|
2502
|
-
console.log(import_ansi_colors9.default.bgRed(import_ansi_colors9.default.white("Operation cancelled.")));
|
|
2503
|
-
process.exit(0);
|
|
2504
|
-
}
|
|
2505
|
-
const moduleName = rawName.toString();
|
|
2506
|
-
const moduleDir = import_path6.default.join(process.cwd(), "src", "features", moduleName);
|
|
2507
|
-
if (import_fs3.default.existsSync(moduleDir)) {
|
|
2508
|
-
console.log(import_ansi_colors9.default.bgCyan(import_ansi_colors9.default.white(`Module "${moduleName}" already exists.`)));
|
|
2509
|
-
process.exit(0);
|
|
2510
|
-
}
|
|
2511
|
-
const appDir = import_path6.default.join(moduleDir, "app");
|
|
2512
|
-
const coreMiddlewaresDir = import_path6.default.join(moduleDir, "core", "middlewares");
|
|
2513
|
-
const coreHandlerDir = import_path6.default.join(moduleDir, "core", "handler");
|
|
2514
|
-
const sharedUtilsDir = import_path6.default.join(moduleDir, "shared", "utils");
|
|
2515
|
-
const sharedErrorsDir = import_path6.default.join(moduleDir, "shared", "errors");
|
|
2516
|
-
const sharedConstantsDir = import_path6.default.join(moduleDir, "shared", "constants");
|
|
2517
|
-
UFsModule.createDirectoryRecursively(appDir);
|
|
2518
|
-
UFsModule.createDirectoryRecursively(coreHandlerDir);
|
|
2519
|
-
UFsModule.createDirectoryRecursively(sharedUtilsDir);
|
|
2520
|
-
UFsModule.createDirectoryRecursively(sharedErrorsDir);
|
|
2521
|
-
UFsModule.createDirectoryRecursively(sharedConstantsDir);
|
|
2522
|
-
let controllerMethods = [];
|
|
2523
|
-
if (await askFile(`${moduleName}.controller.ts`)) {
|
|
2524
|
-
controllerMethods = await askMethods();
|
|
2525
|
-
UFsModule.createFile(
|
|
2526
|
-
import_path6.default.join(appDir, `${moduleName}.controller.ts`),
|
|
2527
|
-
generateCustomControllerTemplate(`${capitalize18(moduleName)}Controller`, moduleName, controllerMethods)
|
|
2133
|
+
if ((0, import_prompts6.isCancel)(fileType)) return void 0;
|
|
2134
|
+
const baseName = await askName(`Enter the name of this ${fileType} (without extension):`, "user");
|
|
2135
|
+
if (!baseName) return void 0;
|
|
2136
|
+
let fileName;
|
|
2137
|
+
let content;
|
|
2138
|
+
switch (fileType) {
|
|
2139
|
+
case "controller": {
|
|
2140
|
+
const wantsMethods = await UPrompt.confirm("Do you want to create methods for this controller?");
|
|
2141
|
+
let methods = [];
|
|
2142
|
+
if (wantsMethods === true) {
|
|
2143
|
+
methods = await askCommaSeparatedList(
|
|
2144
|
+
"Enter the method names (comma separated):",
|
|
2145
|
+
"create, findAll, findById, update, delete"
|
|
2528
2146
|
);
|
|
2529
|
-
ok(`app/${moduleName}.controller.ts`);
|
|
2530
|
-
}
|
|
2531
|
-
if (await askFile(`${moduleName}.service.ts`)) {
|
|
2532
|
-
UFsModule.createFile(import_path6.default.join(appDir, `${moduleName}.service.ts`), generateCustomServiceTemplate(moduleName));
|
|
2533
|
-
ok(`app/${moduleName}.service.ts`);
|
|
2534
|
-
}
|
|
2535
|
-
if (await askFile(`${moduleName}.repository.ts`)) {
|
|
2536
|
-
UFsModule.createFile(import_path6.default.join(appDir, `${moduleName}.repository.ts`), generateCustomRepositoryTemplate(moduleName));
|
|
2537
|
-
ok(`app/${moduleName}.repository.ts`);
|
|
2538
|
-
}
|
|
2539
|
-
if (await askFile(`${moduleName}.model.ts`)) {
|
|
2540
|
-
UFsModule.createFile(import_path6.default.join(appDir, `${moduleName}.model.ts`), generateCustomModelTemplate(moduleName));
|
|
2541
|
-
ok(`app/${moduleName}.model.ts`);
|
|
2542
|
-
}
|
|
2543
|
-
if (await askFile(`${moduleName}.types.ts`)) {
|
|
2544
|
-
UFsModule.createFile(import_path6.default.join(appDir, `${moduleName}.types.ts`), generateCustomTypesTemplate(moduleName));
|
|
2545
|
-
ok(`app/${moduleName}.types.ts`);
|
|
2546
2147
|
}
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2148
|
+
fileName = `${baseName}.controller.ts`;
|
|
2149
|
+
content = generateBuildYourOwnControllerTemplate(baseName, methods);
|
|
2150
|
+
break;
|
|
2151
|
+
}
|
|
2152
|
+
case "service": {
|
|
2153
|
+
const kind = await UPrompt.select(
|
|
2154
|
+
"Do you want a class with methods, or a service that is just a function?",
|
|
2155
|
+
["class"],
|
|
2156
|
+
[
|
|
2157
|
+
{ label: "Class with methods", value: ["class"] },
|
|
2158
|
+
{ label: "Single function", value: ["function"] }
|
|
2159
|
+
]
|
|
2160
|
+
);
|
|
2161
|
+
if ((0, import_prompts6.isCancel)(kind)) return void 0;
|
|
2162
|
+
fileName = `${baseName}.service.ts`;
|
|
2163
|
+
if (kind === "class") {
|
|
2164
|
+
const methods = await askCommaSeparatedList(
|
|
2165
|
+
"Enter the method names (comma separated):",
|
|
2166
|
+
"findAll, findById, create, update, delete"
|
|
2553
2167
|
);
|
|
2554
|
-
|
|
2168
|
+
content = generateBuildYourOwnServiceClassTemplate(baseName, methods);
|
|
2169
|
+
} else {
|
|
2170
|
+
content = generateBuildYourOwnServiceFunctionTemplate(baseName);
|
|
2555
2171
|
}
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2172
|
+
break;
|
|
2173
|
+
}
|
|
2174
|
+
case "dto": {
|
|
2175
|
+
const raw = await askCommaSeparatedList(
|
|
2176
|
+
"Enter the DTO fields as name:type pairs, comma separated:",
|
|
2177
|
+
"name:string, email:string"
|
|
2178
|
+
);
|
|
2179
|
+
fileName = `${baseName}.dto.ts`;
|
|
2180
|
+
content = generateBuildYourOwnDtoTemplate(baseName, parseFieldDefinitions(raw));
|
|
2181
|
+
break;
|
|
2182
|
+
}
|
|
2183
|
+
case "entity": {
|
|
2184
|
+
const raw = await askCommaSeparatedList(
|
|
2185
|
+
"Enter the entity properties as name:type pairs, comma separated:",
|
|
2186
|
+
"id:string, name:string, createdAt:Date"
|
|
2559
2187
|
);
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
${import_ansi_colors9.default.bgGreen(import_ansi_colors9.default.white(`
|
|
2583
|
-
\u{1F389} Custom module "${moduleName}" scaffolded successfully!
|
|
2584
|
-
`))}`);
|
|
2585
|
-
};
|
|
2188
|
+
fileName = `${baseName}.entity.ts`;
|
|
2189
|
+
content = generateBuildYourOwnEntityTemplate(baseName, parseFieldDefinitions(raw));
|
|
2190
|
+
break;
|
|
2191
|
+
}
|
|
2192
|
+
case "repository": {
|
|
2193
|
+
const methods = await askCommaSeparatedList(
|
|
2194
|
+
"Enter the actions this repository should perform (comma separated):",
|
|
2195
|
+
"findAll, findById, save, update, delete"
|
|
2196
|
+
);
|
|
2197
|
+
fileName = `${baseName}.repository.ts`;
|
|
2198
|
+
content = generateBuildYourOwnRepositoryTemplate(baseName, methods);
|
|
2199
|
+
break;
|
|
2200
|
+
}
|
|
2201
|
+
case "route": {
|
|
2202
|
+
const actions = await askCommaSeparatedList(
|
|
2203
|
+
"Enter the actions to expose as routes (comma separated):",
|
|
2204
|
+
"findAll, findById, create, update, delete"
|
|
2205
|
+
);
|
|
2206
|
+
fileName = `${baseName}.route.ts`;
|
|
2207
|
+
content = generateBuildYourOwnRouteTemplate(baseName, actions);
|
|
2208
|
+
break;
|
|
2209
|
+
}
|
|
2586
2210
|
}
|
|
2587
|
-
|
|
2211
|
+
const filePath = import_path6.default.join(dirPath, fileName);
|
|
2212
|
+
UFsModule.createFile(filePath, content);
|
|
2213
|
+
ok(fileName);
|
|
2214
|
+
return { name: fileName, type: "file" };
|
|
2215
|
+
}
|
|
2216
|
+
async function handleDirectory(dirPath, node) {
|
|
2217
|
+
let keepGoing = true;
|
|
2218
|
+
while (keepGoing) {
|
|
2219
|
+
const choice = await UPrompt.select(
|
|
2220
|
+
`Inside "${node.name}", do you want to create a file or a folder?`,
|
|
2221
|
+
["file"],
|
|
2222
|
+
[
|
|
2223
|
+
{ label: "File", value: ["file"] },
|
|
2224
|
+
{ label: "Folder", value: ["folder"] }
|
|
2225
|
+
]
|
|
2226
|
+
);
|
|
2227
|
+
if ((0, import_prompts6.isCancel)(choice)) return;
|
|
2228
|
+
if (choice === "folder") {
|
|
2229
|
+
const folderName = await askName("Enter the folder name:", "core");
|
|
2230
|
+
if (!folderName) return;
|
|
2231
|
+
const subDir = import_path6.default.join(dirPath, folderName);
|
|
2232
|
+
UFsModule.createDirectoryRecursively(subDir);
|
|
2233
|
+
const subNode = { name: folderName, type: "dir", children: [] };
|
|
2234
|
+
node.children.push(subNode);
|
|
2235
|
+
ok(`${folderName}/`);
|
|
2236
|
+
await handleDirectory(subDir, subNode);
|
|
2237
|
+
} else {
|
|
2238
|
+
const fileNode = await handleFileCreation(dirPath);
|
|
2239
|
+
if (fileNode) {
|
|
2240
|
+
node.children.push(fileNode);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
info(`Current structure of "${node.name}":`);
|
|
2244
|
+
printTree(node);
|
|
2245
|
+
const wantsContinue = await UPrompt.confirm(`Continue creating files/folders inside "${node.name}"?`);
|
|
2246
|
+
if ((0, import_prompts6.isCancel)(wantsContinue) || wantsContinue !== true) {
|
|
2247
|
+
keepGoing = false;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
var buildYourOwnArchitectureScaffoldTemplate = async () => {
|
|
2252
|
+
const featuresDir = import_path6.default.join(process.cwd(), "src", "features");
|
|
2253
|
+
const forest = [];
|
|
2254
|
+
let creatingNewRoot = true;
|
|
2255
|
+
while (creatingNewRoot) {
|
|
2256
|
+
const rootName = await askName("Enter the name of the root folder for your architecture:", "myArchitecture");
|
|
2257
|
+
if (!rootName) {
|
|
2258
|
+
console.log(import_ansi_colors9.default.bgRed(import_ansi_colors9.default.white("Operation cancelled.")));
|
|
2259
|
+
process.exit(0);
|
|
2260
|
+
}
|
|
2261
|
+
const rootDir = import_path6.default.join(featuresDir, rootName);
|
|
2262
|
+
if (import_fs3.default.existsSync(rootDir)) {
|
|
2263
|
+
info(`Folder "${rootName}" already exists, new files/folders will be added inside it.`);
|
|
2264
|
+
}
|
|
2265
|
+
UFsModule.createDirectoryRecursively(rootDir);
|
|
2266
|
+
const rootNode = { name: rootName, type: "dir", children: [] };
|
|
2267
|
+
forest.push(rootNode);
|
|
2268
|
+
await handleDirectory(rootDir, rootNode);
|
|
2269
|
+
const wantsNewRoot = await UPrompt.confirm(
|
|
2270
|
+
"Do you want to create a new folder at the root of your architecture?",
|
|
2271
|
+
false
|
|
2272
|
+
);
|
|
2273
|
+
if ((0, import_prompts6.isCancel)(wantsNewRoot) || wantsNewRoot !== true) {
|
|
2274
|
+
console.log(import_ansi_colors9.default.cyan("En disant non, ce sera la fin de la cr\xE9ation de votre propre architecture."));
|
|
2275
|
+
creatingNewRoot = false;
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
console.log(`
|
|
2279
|
+
${import_ansi_colors9.default.bgGreen(import_ansi_colors9.default.white("\n\u{1F389} Your custom architecture has been created!\n"))}`);
|
|
2280
|
+
forest.forEach((root) => printTree(root));
|
|
2281
|
+
};
|
|
2282
|
+
|
|
2283
|
+
// src/templates/mvcModule/mvcModuleScaffold.template.ts
|
|
2284
|
+
var import_path7 = __toESM(require("path"), 1);
|
|
2285
|
+
var import_ansi_colors10 = __toESM(require("ansi-colors"), 1);
|
|
2286
|
+
var import_prompts7 = require("@clack/prompts");
|
|
2588
2287
|
|
|
2589
2288
|
// src/templates/mvcModule/mvcModule.template.ts
|
|
2590
|
-
var
|
|
2591
|
-
var
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
capitalize19 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2596
|
-
generateMvcModelTemplate = (featureName) => {
|
|
2597
|
-
const capitalized = capitalize19(featureName);
|
|
2598
|
-
const modelName = `${capitalized}Model`;
|
|
2599
|
-
return `/**
|
|
2289
|
+
var capitalize18 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2290
|
+
var generateMvcModelTemplate = (featureName) => {
|
|
2291
|
+
const capitalized = capitalize18(featureName);
|
|
2292
|
+
const modelName = `${capitalized}Model`;
|
|
2293
|
+
return `/**
|
|
2600
2294
|
* ${modelName} \u2014 Model
|
|
2601
2295
|
* Owns both the data shape and the data-access logic for "${featureName}".
|
|
2602
2296
|
*/
|
|
@@ -2650,12 +2344,12 @@ export class ${modelName} {
|
|
|
2650
2344
|
}
|
|
2651
2345
|
}
|
|
2652
2346
|
`;
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2347
|
+
};
|
|
2348
|
+
var generateMvcViewTemplate = (featureName) => {
|
|
2349
|
+
const capitalized = capitalize18(featureName);
|
|
2350
|
+
const modelName = `${capitalized}Model`;
|
|
2351
|
+
const viewName = `${capitalized}View`;
|
|
2352
|
+
return `import { ${modelName} } from "../models/${featureName}.model";
|
|
2659
2353
|
|
|
2660
2354
|
/**
|
|
2661
2355
|
* ${viewName} \u2014 View
|
|
@@ -2676,13 +2370,13 @@ export class ${viewName} {
|
|
|
2676
2370
|
}
|
|
2677
2371
|
}
|
|
2678
2372
|
`;
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2373
|
+
};
|
|
2374
|
+
var generateMvcControllerTemplate = (controllerName, featureName, methods) => {
|
|
2375
|
+
const capitalized = capitalize18(featureName);
|
|
2376
|
+
const modelName = `${capitalized}Model`;
|
|
2377
|
+
const viewName = `${capitalized}View`;
|
|
2378
|
+
const methodsCode = methods.map((method) => generateMethod3(method, capitalized, modelName, viewName)).join("\n");
|
|
2379
|
+
return `import { Request, Response } from "opticore-express";
|
|
2686
2380
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
2687
2381
|
import { ${modelName} } from "../models/${featureName}.model";
|
|
2688
2382
|
import { ${viewName} } from "../views/${featureName}.view";
|
|
@@ -2695,15 +2389,25 @@ ${methodsCode}
|
|
|
2695
2389
|
}
|
|
2696
2390
|
}
|
|
2697
2391
|
`;
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2392
|
+
};
|
|
2393
|
+
var generateMethod3 = (method, capitalized, modelName, viewName) => {
|
|
2394
|
+
const lower = method.toLowerCase();
|
|
2395
|
+
if (lower.includes("findall") || lower.includes("getall")) {
|
|
2396
|
+
return generateFindAllMethod3(method, capitalized, modelName, viewName);
|
|
2397
|
+
}
|
|
2398
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) {
|
|
2399
|
+
return generateFindByIdMethod3(method, capitalized, modelName, viewName);
|
|
2400
|
+
}
|
|
2401
|
+
if (lower.includes("create") || lower.includes("add")) {
|
|
2402
|
+
return generateCreateMethod3(method, capitalized, modelName, viewName);
|
|
2403
|
+
}
|
|
2404
|
+
if (lower.includes("update") || lower.includes("edit")) {
|
|
2405
|
+
return generateUpdateMethod3(method, capitalized, modelName, viewName);
|
|
2406
|
+
}
|
|
2407
|
+
if (lower.includes("delete") || lower.includes("remove")) {
|
|
2408
|
+
return generateDeleteMethod3(method, capitalized, modelName);
|
|
2409
|
+
}
|
|
2410
|
+
return `
|
|
2707
2411
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2708
2412
|
try {
|
|
2709
2413
|
// TODO: Implement ${method} logic
|
|
@@ -2713,8 +2417,8 @@ ${methodsCode}
|
|
|
2713
2417
|
}
|
|
2714
2418
|
}
|
|
2715
2419
|
`;
|
|
2716
|
-
|
|
2717
|
-
|
|
2420
|
+
};
|
|
2421
|
+
var generateFindAllMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2718
2422
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2719
2423
|
try {
|
|
2720
2424
|
const models = await ${modelName}.findAll();
|
|
@@ -2724,7 +2428,7 @@ ${methodsCode}
|
|
|
2724
2428
|
}
|
|
2725
2429
|
}
|
|
2726
2430
|
`;
|
|
2727
|
-
|
|
2431
|
+
var generateFindByIdMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2728
2432
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2729
2433
|
try {
|
|
2730
2434
|
const { id } = req.params;
|
|
@@ -2738,7 +2442,7 @@ ${methodsCode}
|
|
|
2738
2442
|
}
|
|
2739
2443
|
}
|
|
2740
2444
|
`;
|
|
2741
|
-
|
|
2445
|
+
var generateCreateMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2742
2446
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2743
2447
|
try {
|
|
2744
2448
|
const model = await ${modelName}.create(req.body);
|
|
@@ -2748,7 +2452,7 @@ ${methodsCode}
|
|
|
2748
2452
|
}
|
|
2749
2453
|
}
|
|
2750
2454
|
`;
|
|
2751
|
-
|
|
2455
|
+
var generateUpdateMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2752
2456
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2753
2457
|
try {
|
|
2754
2458
|
const { id } = req.params;
|
|
@@ -2762,7 +2466,7 @@ ${methodsCode}
|
|
|
2762
2466
|
}
|
|
2763
2467
|
}
|
|
2764
2468
|
`;
|
|
2765
|
-
|
|
2469
|
+
var generateDeleteMethod3 = (method, capitalized, modelName) => `
|
|
2766
2470
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2767
2471
|
try {
|
|
2768
2472
|
const { id } = req.params;
|
|
@@ -2776,20 +2480,20 @@ ${methodsCode}
|
|
|
2776
2480
|
}
|
|
2777
2481
|
}
|
|
2778
2482
|
`;
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2483
|
+
var generateMvcRouterHandlerTemplate = (featureName, controllerMethods) => {
|
|
2484
|
+
const capitalized = capitalize18(featureName);
|
|
2485
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
2486
|
+
const controllerName = `${capitalized}Controller`;
|
|
2487
|
+
const routesCode = (controllerMethods || []).map((method) => {
|
|
2488
|
+
const { httpMethod, path: path10 } = resolveRoute3(method, featureName);
|
|
2489
|
+
return `{
|
|
2786
2490
|
path: \`${path10}\`,
|
|
2787
2491
|
method: "${httpMethod}",
|
|
2788
2492
|
middlewares: [],
|
|
2789
2493
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
2790
2494
|
}`;
|
|
2791
|
-
|
|
2792
|
-
|
|
2495
|
+
}).join(",\n");
|
|
2496
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
2793
2497
|
import { ${controllerName} } from "../controllers/${featureName}.controller";
|
|
2794
2498
|
|
|
2795
2499
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -2801,12 +2505,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
2801
2505
|
);
|
|
2802
2506
|
};
|
|
2803
2507
|
`;
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2508
|
+
};
|
|
2509
|
+
var generateMvcRouterTemplate = (featureName) => {
|
|
2510
|
+
const capitalized = capitalize18(featureName);
|
|
2511
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
2512
|
+
const routerName = `${capitalized}Router`;
|
|
2513
|
+
return `import { ${handlerName} } from "./${featureName}.router.handler";
|
|
2810
2514
|
import { TFeatureRoutes } from "opticore-router";
|
|
2811
2515
|
|
|
2812
2516
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -2818,101 +2522,97 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
2818
2522
|
]
|
|
2819
2523
|
};
|
|
2820
2524
|
`;
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
if (lower.includes("create") || lower.includes("add")) return { httpMethod: "post", path: `/${featureName}` };
|
|
2827
|
-
if (lower.includes("update") || lower.includes("edit")) return { httpMethod: "put", path: `/${featureName}/:id` };
|
|
2828
|
-
if (lower.includes("delete") || lower.includes("remove")) return { httpMethod: "delete", path: `/${featureName}/:id` };
|
|
2829
|
-
return { httpMethod: "get", path: `/${featureName}/${lower}` };
|
|
2830
|
-
};
|
|
2525
|
+
};
|
|
2526
|
+
var resolveRoute3 = (methodName, featureName) => {
|
|
2527
|
+
const lower = methodName.toLowerCase();
|
|
2528
|
+
if (lower.includes("findall") || lower.includes("getall")) {
|
|
2529
|
+
return { httpMethod: "get", path: `/${featureName}` };
|
|
2831
2530
|
}
|
|
2832
|
-
|
|
2531
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) {
|
|
2532
|
+
return { httpMethod: "get", path: `/${featureName}/:id` };
|
|
2533
|
+
}
|
|
2534
|
+
if (lower.includes("create") || lower.includes("add")) {
|
|
2535
|
+
return { httpMethod: "post", path: `/${featureName}` };
|
|
2536
|
+
}
|
|
2537
|
+
if (lower.includes("update") || lower.includes("edit")) {
|
|
2538
|
+
return { httpMethod: "put", path: `/${featureName}/:id` };
|
|
2539
|
+
}
|
|
2540
|
+
if (lower.includes("delete") || lower.includes("remove")) {
|
|
2541
|
+
return { httpMethod: "delete", path: `/${featureName}/:id` };
|
|
2542
|
+
}
|
|
2543
|
+
return { httpMethod: "get", path: `/${featureName}/${lower}` };
|
|
2544
|
+
};
|
|
2833
2545
|
|
|
2834
2546
|
// src/templates/mvcModule/mvcModuleScaffold.template.ts
|
|
2835
|
-
var
|
|
2836
|
-
var
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
import_path7
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
if (wantsMethods && !(0, import_prompts6.isCancel)(wantsMethods)) {
|
|
2867
|
-
const methodsText = await UPrompt.text(
|
|
2868
|
-
"Enter the method names (comma separated):",
|
|
2869
|
-
"create, findAll, findById, update, delete",
|
|
2870
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
2871
|
-
);
|
|
2872
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
2873
|
-
controllerContent = generateMvcControllerTemplate(controllerName, featureName, methods);
|
|
2874
|
-
} else {
|
|
2875
|
-
controllerContent = `import { Request, Response } from "opticore-express";
|
|
2547
|
+
var capitalize19 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2548
|
+
var mvcModuleTemplate = async (featureName) => {
|
|
2549
|
+
FeatureComponentGeneratorUtils.setStructure("mvc");
|
|
2550
|
+
const basePath = import_path7.default.join("src", "features", featureName);
|
|
2551
|
+
const paths = {
|
|
2552
|
+
modelsDir: import_path7.default.join(basePath, "models"),
|
|
2553
|
+
viewsDir: import_path7.default.join(basePath, "views"),
|
|
2554
|
+
controllersDir: import_path7.default.join(basePath, "controllers"),
|
|
2555
|
+
routesDir: import_path7.default.join(basePath, "routes")
|
|
2556
|
+
};
|
|
2557
|
+
Object.values(paths).forEach((dir) => UFsModule.createDirectoryRecursively(dir));
|
|
2558
|
+
const controllerName = `${capitalize19(featureName)}Controller`;
|
|
2559
|
+
UFsModule.createFile(import_path7.default.join(paths.modelsDir, `${featureName}.model.ts`), generateMvcModelTemplate(featureName));
|
|
2560
|
+
console.log(import_ansi_colors10.default.green(`\u2714 Model created: ${import_path7.default.join(paths.modelsDir, `${featureName}.model.ts`)}`));
|
|
2561
|
+
UFsModule.createFile(import_path7.default.join(paths.viewsDir, `${featureName}.view.ts`), generateMvcViewTemplate(featureName));
|
|
2562
|
+
console.log(import_ansi_colors10.default.green(`\u2714 View created: ${import_path7.default.join(paths.viewsDir, `${featureName}.view.ts`)}`));
|
|
2563
|
+
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
2564
|
+
let methods = [];
|
|
2565
|
+
let controllerContent;
|
|
2566
|
+
if (wantsMethods && !(0, import_prompts7.isCancel)(wantsMethods)) {
|
|
2567
|
+
const methodsText = await UPrompt.text(
|
|
2568
|
+
"Enter the method names (comma separated):",
|
|
2569
|
+
"create, findAll, findById, update, delete",
|
|
2570
|
+
(v) => v ? void 0 : "You must enter at least one method."
|
|
2571
|
+
);
|
|
2572
|
+
if (!(0, import_prompts7.isCancel)(methodsText)) {
|
|
2573
|
+
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
2574
|
+
}
|
|
2575
|
+
controllerContent = generateMvcControllerTemplate(controllerName, featureName, methods);
|
|
2576
|
+
} else {
|
|
2577
|
+
controllerContent = `import { Request, Response } from "opticore-express";
|
|
2876
2578
|
|
|
2877
2579
|
export class ${controllerName} {}
|
|
2878
2580
|
`;
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2581
|
+
}
|
|
2582
|
+
const controllerPath = import_path7.default.join(paths.controllersDir, `${featureName}.controller.ts`);
|
|
2583
|
+
UFsModule.createFile(controllerPath, controllerContent);
|
|
2584
|
+
console.log(import_ansi_colors10.default.green(`\u2714 Controller created: ${controllerPath}`));
|
|
2585
|
+
UFsModule.createFile(
|
|
2586
|
+
import_path7.default.join(paths.routesDir, `${featureName}.router.handler.ts`),
|
|
2587
|
+
generateMvcRouterHandlerTemplate(featureName, methods)
|
|
2588
|
+
);
|
|
2589
|
+
console.log(import_ansi_colors10.default.green(`\u2714 Router Handler created: ${import_path7.default.join(paths.routesDir, `${featureName}.router.handler.ts`)}`));
|
|
2590
|
+
UFsModule.createFile(
|
|
2591
|
+
import_path7.default.join(paths.routesDir, `${featureName}.router.ts`),
|
|
2592
|
+
generateMvcRouterTemplate(featureName)
|
|
2593
|
+
);
|
|
2594
|
+
await FeatureComponentGeneratorUtils.registerModuleRouter(featureName);
|
|
2595
|
+
console.log(import_ansi_colors10.default.green(`\u2714 Router created: ${import_path7.default.join(paths.routesDir, `${featureName}.router.ts`)}`));
|
|
2596
|
+
console.log(
|
|
2597
|
+
import_ansi_colors10.default.bgGreen(
|
|
2598
|
+
import_ansi_colors10.default.white(`
|
|
2897
2599
|
\u{1F389} Feature "${featureName}" scaffolded with MVC architecture!
|
|
2898
2600
|
`)
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2601
|
+
)
|
|
2602
|
+
);
|
|
2603
|
+
};
|
|
2604
|
+
|
|
2605
|
+
// src/templates/layeredModule/layeredModuleScaffold.template.ts
|
|
2606
|
+
var import_path8 = __toESM(require("path"), 1);
|
|
2607
|
+
var import_ansi_colors11 = __toESM(require("ansi-colors"), 1);
|
|
2608
|
+
var import_prompts8 = require("@clack/prompts");
|
|
2904
2609
|
|
|
2905
2610
|
// src/templates/layeredModule/layeredModule.template.ts
|
|
2906
|
-
var
|
|
2907
|
-
var
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
capitalize21 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2912
|
-
generateLayeredEntityTemplate = (featureName) => {
|
|
2913
|
-
const capitalized = capitalize21(featureName);
|
|
2914
|
-
const entityName = `${capitalized}Entity`;
|
|
2915
|
-
return `/**
|
|
2611
|
+
var capitalize20 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2612
|
+
var generateLayeredEntityTemplate = (featureName) => {
|
|
2613
|
+
const capitalized = capitalize20(featureName);
|
|
2614
|
+
const entityName = `${capitalized}Entity`;
|
|
2615
|
+
return `/**
|
|
2916
2616
|
* ${entityName} \u2014 Entity
|
|
2917
2617
|
* Plain data structure for the "${featureName}" domain. No data-access logic here.
|
|
2918
2618
|
*/
|
|
@@ -2925,11 +2625,11 @@ export class ${entityName} {
|
|
|
2925
2625
|
) {}
|
|
2926
2626
|
}
|
|
2927
2627
|
`;
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2628
|
+
};
|
|
2629
|
+
var generateLayeredDtoTemplate = (featureName) => {
|
|
2630
|
+
const capitalized = capitalize20(featureName);
|
|
2631
|
+
const entityName = `${capitalized}Entity`;
|
|
2632
|
+
return `import { ${entityName} } from "../entities/${featureName}.entity";
|
|
2933
2633
|
|
|
2934
2634
|
export interface Create${capitalized}Dto {
|
|
2935
2635
|
// TODO: define the fields required to create a ${featureName}
|
|
@@ -2952,12 +2652,12 @@ export const to${capitalized}ResponseDto = (entity: ${entityName}): ${capitalize
|
|
|
2952
2652
|
updatedAt: entity.updatedAt,
|
|
2953
2653
|
});
|
|
2954
2654
|
`;
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2655
|
+
};
|
|
2656
|
+
var generateLayeredRepositoryTemplate = (featureName) => {
|
|
2657
|
+
const capitalized = capitalize20(featureName);
|
|
2658
|
+
const entityName = `${capitalized}Entity`;
|
|
2659
|
+
const repoName = `${capitalized}Repository`;
|
|
2660
|
+
return `import { ${entityName} } from "../entities/${featureName}.entity";
|
|
2961
2661
|
|
|
2962
2662
|
export class ${repoName} {
|
|
2963
2663
|
private store: Map<string, ${entityName}> = new Map();
|
|
@@ -2991,13 +2691,13 @@ export class ${repoName} {
|
|
|
2991
2691
|
}
|
|
2992
2692
|
}
|
|
2993
2693
|
`;
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
2694
|
+
};
|
|
2695
|
+
var generateLayeredServiceTemplate = (featureName) => {
|
|
2696
|
+
const capitalized = capitalize20(featureName);
|
|
2697
|
+
const entityName = `${capitalized}Entity`;
|
|
2698
|
+
const repoName = `${capitalized}Repository`;
|
|
2699
|
+
const serviceName = `${capitalized}Service`;
|
|
2700
|
+
return `import { ${repoName} } from "../repositories/${featureName}.repository";
|
|
3001
2701
|
import { ${entityName} } from "../entities/${featureName}.entity";
|
|
3002
2702
|
import { Create${capitalized}Dto, Update${capitalized}Dto, ${capitalized}ResponseDto, to${capitalized}ResponseDto } from "../dto/${featureName}.dto";
|
|
3003
2703
|
|
|
@@ -3040,12 +2740,12 @@ export class ${serviceName} {
|
|
|
3040
2740
|
}
|
|
3041
2741
|
}
|
|
3042
2742
|
`;
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
2743
|
+
};
|
|
2744
|
+
var generateLayeredControllerTemplate = (controllerName, featureName, methods) => {
|
|
2745
|
+
const capitalized = capitalize20(featureName);
|
|
2746
|
+
const serviceName = `${capitalized}Service`;
|
|
2747
|
+
const methodsCode = methods.map((method) => generateMethod4(method, capitalized, serviceName)).join("\n");
|
|
2748
|
+
return `import { Request, Response } from "opticore-express";
|
|
3049
2749
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
3050
2750
|
import { ${serviceName} } from "../services/${featureName}.service";
|
|
3051
2751
|
|
|
@@ -3061,15 +2761,15 @@ ${methodsCode}
|
|
|
3061
2761
|
}
|
|
3062
2762
|
}
|
|
3063
2763
|
`;
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
2764
|
+
};
|
|
2765
|
+
var generateMethod4 = (method, capitalized, serviceName) => {
|
|
2766
|
+
const lower = method.toLowerCase();
|
|
2767
|
+
if (lower.includes("findall") || lower.includes("getall")) return generateFindAllMethod4(method, capitalized);
|
|
2768
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) return generateFindByIdMethod4(method, capitalized);
|
|
2769
|
+
if (lower.includes("create") || lower.includes("add")) return generateCreateMethod4(method, capitalized);
|
|
2770
|
+
if (lower.includes("update") || lower.includes("edit")) return generateUpdateMethod4(method, capitalized);
|
|
2771
|
+
if (lower.includes("delete") || lower.includes("remove")) return generateDeleteMethod4(method, capitalized);
|
|
2772
|
+
return `
|
|
3073
2773
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3074
2774
|
try {
|
|
3075
2775
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -3080,8 +2780,8 @@ ${methodsCode}
|
|
|
3080
2780
|
}
|
|
3081
2781
|
}
|
|
3082
2782
|
`;
|
|
3083
|
-
|
|
3084
|
-
|
|
2783
|
+
};
|
|
2784
|
+
var generateFindAllMethod4 = (method, capitalized) => `
|
|
3085
2785
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3086
2786
|
try {
|
|
3087
2787
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -3092,7 +2792,7 @@ ${methodsCode}
|
|
|
3092
2792
|
}
|
|
3093
2793
|
}
|
|
3094
2794
|
`;
|
|
3095
|
-
|
|
2795
|
+
var generateFindByIdMethod4 = (method, capitalized) => `
|
|
3096
2796
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3097
2797
|
try {
|
|
3098
2798
|
const { id } = req.params;
|
|
@@ -3107,7 +2807,7 @@ ${methodsCode}
|
|
|
3107
2807
|
}
|
|
3108
2808
|
}
|
|
3109
2809
|
`;
|
|
3110
|
-
|
|
2810
|
+
var generateCreateMethod4 = (method, capitalized) => `
|
|
3111
2811
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3112
2812
|
try {
|
|
3113
2813
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -3118,7 +2818,7 @@ ${methodsCode}
|
|
|
3118
2818
|
}
|
|
3119
2819
|
}
|
|
3120
2820
|
`;
|
|
3121
|
-
|
|
2821
|
+
var generateUpdateMethod4 = (method, capitalized) => `
|
|
3122
2822
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3123
2823
|
try {
|
|
3124
2824
|
const { id } = req.params;
|
|
@@ -3133,7 +2833,7 @@ ${methodsCode}
|
|
|
3133
2833
|
}
|
|
3134
2834
|
}
|
|
3135
2835
|
`;
|
|
3136
|
-
|
|
2836
|
+
var generateDeleteMethod4 = (method, capitalized) => `
|
|
3137
2837
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3138
2838
|
try {
|
|
3139
2839
|
const { id } = req.params;
|
|
@@ -3148,20 +2848,20 @@ ${methodsCode}
|
|
|
3148
2848
|
}
|
|
3149
2849
|
}
|
|
3150
2850
|
`;
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
2851
|
+
var generateLayeredRouterHandlerTemplate = (featureName, controllerMethods) => {
|
|
2852
|
+
const capitalized = capitalize20(featureName);
|
|
2853
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
2854
|
+
const controllerName = `${capitalized}Controller`;
|
|
2855
|
+
const routesCode = (controllerMethods || []).map((method) => {
|
|
2856
|
+
const { httpMethod, path: path10 } = resolveRoute4(method, featureName);
|
|
2857
|
+
return `{
|
|
3158
2858
|
path: \`${path10}\`,
|
|
3159
2859
|
method: "${httpMethod}",
|
|
3160
2860
|
middlewares: [],
|
|
3161
2861
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
3162
2862
|
}`;
|
|
3163
|
-
|
|
3164
|
-
|
|
2863
|
+
}).join(",\n");
|
|
2864
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
3165
2865
|
import { ${controllerName} } from "../controllers/${featureName}.controller";
|
|
3166
2866
|
|
|
3167
2867
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -3173,12 +2873,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
3173
2873
|
);
|
|
3174
2874
|
};
|
|
3175
2875
|
`;
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
2876
|
+
};
|
|
2877
|
+
var generateLayeredRouterTemplate = (featureName) => {
|
|
2878
|
+
const capitalized = capitalize20(featureName);
|
|
2879
|
+
const handlerName = `${capitalized}HandlerRouter`;
|
|
2880
|
+
const routerName = `${capitalized}Router`;
|
|
2881
|
+
return `import { ${handlerName} } from "./${featureName}.router.handler";
|
|
3182
2882
|
import { TFeatureRoutes } from "opticore-router";
|
|
3183
2883
|
|
|
3184
2884
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -3190,174 +2890,138 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
3190
2890
|
]
|
|
3191
2891
|
};
|
|
3192
2892
|
`;
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
}
|
|
3204
|
-
});
|
|
2893
|
+
};
|
|
2894
|
+
var resolveRoute4 = (methodName, featureName) => {
|
|
2895
|
+
const lower = methodName.toLowerCase();
|
|
2896
|
+
if (lower.includes("findall") || lower.includes("getall")) return { httpMethod: "get", path: `/${featureName}` };
|
|
2897
|
+
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) return { httpMethod: "get", path: `/${featureName}/:id` };
|
|
2898
|
+
if (lower.includes("create") || lower.includes("add")) return { httpMethod: "post", path: `/${featureName}` };
|
|
2899
|
+
if (lower.includes("update") || lower.includes("edit")) return { httpMethod: "put", path: `/${featureName}/:id` };
|
|
2900
|
+
if (lower.includes("delete") || lower.includes("remove")) return { httpMethod: "delete", path: `/${featureName}/:id` };
|
|
2901
|
+
return { httpMethod: "get", path: `/${featureName}/${lower}` };
|
|
2902
|
+
};
|
|
3205
2903
|
|
|
3206
2904
|
// src/templates/layeredModule/layeredModuleScaffold.template.ts
|
|
3207
|
-
var
|
|
3208
|
-
var
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
import_path8
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
if (wantsMethods && !(0, import_prompts7.isCancel)(wantsMethods)) {
|
|
3245
|
-
const methodsText = await UPrompt.text(
|
|
3246
|
-
"Enter the method names (comma separated):",
|
|
3247
|
-
"create, findAll, findById, update, delete",
|
|
3248
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
3249
|
-
);
|
|
3250
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
3251
|
-
controllerContent = generateLayeredControllerTemplate(controllerName, featureName, methods);
|
|
3252
|
-
} else {
|
|
3253
|
-
controllerContent = `import { Request, Response } from "opticore-express";
|
|
2905
|
+
var capitalize21 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2906
|
+
var layeredModuleTemplate = async (featureName) => {
|
|
2907
|
+
FeatureComponentGeneratorUtils.setStructure("layered");
|
|
2908
|
+
const basePath = import_path8.default.join("src", "features", featureName);
|
|
2909
|
+
const paths = {
|
|
2910
|
+
entitiesDir: import_path8.default.join(basePath, "entities"),
|
|
2911
|
+
dtoDir: import_path8.default.join(basePath, "dto"),
|
|
2912
|
+
repositoriesDir: import_path8.default.join(basePath, "repositories"),
|
|
2913
|
+
servicesDir: import_path8.default.join(basePath, "services"),
|
|
2914
|
+
controllersDir: import_path8.default.join(basePath, "controllers"),
|
|
2915
|
+
routesDir: import_path8.default.join(basePath, "routes")
|
|
2916
|
+
};
|
|
2917
|
+
Object.values(paths).forEach((dir) => UFsModule.createDirectoryRecursively(dir));
|
|
2918
|
+
const controllerName = `${capitalize21(featureName)}Controller`;
|
|
2919
|
+
UFsModule.createFile(import_path8.default.join(paths.entitiesDir, `${featureName}.entity.ts`), generateLayeredEntityTemplate(featureName));
|
|
2920
|
+
console.log(import_ansi_colors11.default.green(`\u2714 Entity created: ${import_path8.default.join(paths.entitiesDir, `${featureName}.entity.ts`)}`));
|
|
2921
|
+
UFsModule.createFile(import_path8.default.join(paths.dtoDir, `${featureName}.dto.ts`), generateLayeredDtoTemplate(featureName));
|
|
2922
|
+
console.log(import_ansi_colors11.default.green(`\u2714 DTO created: ${import_path8.default.join(paths.dtoDir, `${featureName}.dto.ts`)}`));
|
|
2923
|
+
UFsModule.createFile(import_path8.default.join(paths.repositoriesDir, `${featureName}.repository.ts`), generateLayeredRepositoryTemplate(featureName));
|
|
2924
|
+
console.log(import_ansi_colors11.default.green(`\u2714 Repository created: ${import_path8.default.join(paths.repositoriesDir, `${featureName}.repository.ts`)}`));
|
|
2925
|
+
UFsModule.createFile(import_path8.default.join(paths.servicesDir, `${featureName}.service.ts`), generateLayeredServiceTemplate(featureName));
|
|
2926
|
+
console.log(import_ansi_colors11.default.green(`\u2714 Service created: ${import_path8.default.join(paths.servicesDir, `${featureName}.service.ts`)}`));
|
|
2927
|
+
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
2928
|
+
let methods = [];
|
|
2929
|
+
let controllerContent;
|
|
2930
|
+
if (wantsMethods && !(0, import_prompts8.isCancel)(wantsMethods)) {
|
|
2931
|
+
const methodsText = await UPrompt.text(
|
|
2932
|
+
"Enter the method names (comma separated):",
|
|
2933
|
+
"create, findAll, findById, update, delete",
|
|
2934
|
+
(v) => v ? void 0 : "You must enter at least one method."
|
|
2935
|
+
);
|
|
2936
|
+
if (!(0, import_prompts8.isCancel)(methodsText)) {
|
|
2937
|
+
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
2938
|
+
}
|
|
2939
|
+
controllerContent = generateLayeredControllerTemplate(controllerName, featureName, methods);
|
|
2940
|
+
} else {
|
|
2941
|
+
controllerContent = `import { Request, Response } from "opticore-express";
|
|
3254
2942
|
|
|
3255
2943
|
export class ${controllerName} {}
|
|
3256
2944
|
`;
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
2945
|
+
}
|
|
2946
|
+
const controllerPath = import_path8.default.join(paths.controllersDir, `${featureName}.controller.ts`);
|
|
2947
|
+
UFsModule.createFile(controllerPath, controllerContent);
|
|
2948
|
+
console.log(import_ansi_colors11.default.green(`\u2714 Controller created: ${controllerPath}`));
|
|
2949
|
+
UFsModule.createFile(
|
|
2950
|
+
import_path8.default.join(paths.routesDir, `${featureName}.router.handler.ts`),
|
|
2951
|
+
generateLayeredRouterHandlerTemplate(featureName, methods)
|
|
2952
|
+
);
|
|
2953
|
+
console.log(import_ansi_colors11.default.green(`\u2714 Router Handler created: ${import_path8.default.join(paths.routesDir, `${featureName}.router.handler.ts`)}`));
|
|
2954
|
+
UFsModule.createFile(
|
|
2955
|
+
import_path8.default.join(paths.routesDir, `${featureName}.router.ts`),
|
|
2956
|
+
generateLayeredRouterTemplate(featureName)
|
|
2957
|
+
);
|
|
2958
|
+
await FeatureComponentGeneratorUtils.registerModuleRouter(featureName);
|
|
2959
|
+
console.log(import_ansi_colors11.default.green(`\u2714 Router created: ${import_path8.default.join(paths.routesDir, `${featureName}.router.ts`)}`));
|
|
2960
|
+
console.log(
|
|
2961
|
+
import_ansi_colors11.default.bgGreen(
|
|
2962
|
+
import_ansi_colors11.default.white(`
|
|
3275
2963
|
\u{1F389} Feature "${featureName}" scaffolded with Layered architecture!
|
|
3276
2964
|
`)
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
}
|
|
3281
|
-
});
|
|
2965
|
+
)
|
|
2966
|
+
);
|
|
2967
|
+
};
|
|
3282
2968
|
|
|
3283
2969
|
// src/core/core.ts
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
"
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
return;
|
|
3331
|
-
}
|
|
3332
|
-
if (!featureChoice || featureChoice !== "opticore_clean_module") {
|
|
3333
|
-
import_process2.default.exit(0);
|
|
3334
|
-
}
|
|
3335
|
-
UCustomFeatureInfo(featureChoice);
|
|
3336
|
-
const featureName = await _featureName();
|
|
3337
|
-
const directory = import_path9.default.join(import_process2.default.cwd(), "src", "features");
|
|
3338
|
-
const featureDirectory = import_path9.default.join(directory, featureName.toString());
|
|
3339
|
-
const featureCleanModule = BaseService._isSubdirectoryExists(featureName);
|
|
3340
|
-
if (featureCleanModule) {
|
|
3341
|
-
BaseService._featureFounded(featureName);
|
|
3342
|
-
}
|
|
3343
|
-
if ((0, import_prompts8.isCancel)(featureName)) {
|
|
3344
|
-
BaseService._cancelOperation(featureDirectory);
|
|
2970
|
+
async function runFeatureCommand() {
|
|
2971
|
+
UWelcomeMessage();
|
|
2972
|
+
const featureChoice = await choiceFeatureCleanModule();
|
|
2973
|
+
if (featureChoice === "custom_feature") {
|
|
2974
|
+
await buildYourOwnArchitectureScaffoldTemplate();
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
if (featureChoice === "mvc_architecture" || featureChoice === "layered_architecture") {
|
|
2978
|
+
const featureName2 = await _featureName();
|
|
2979
|
+
const directory2 = import_path9.default.join(import_process2.default.cwd(), "src", "features");
|
|
2980
|
+
const featureDirectory2 = import_path9.default.join(directory2, featureName2.toString());
|
|
2981
|
+
if (BaseService._isSubdirectoryExists(featureName2)) {
|
|
2982
|
+
BaseService._featureFounded(featureName2);
|
|
2983
|
+
}
|
|
2984
|
+
if ((0, import_prompts9.isCancel)(featureName2)) {
|
|
2985
|
+
BaseService._cancelOperation(featureDirectory2);
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
if (!import_node_fs2.default.existsSync(directory2)) {
|
|
2989
|
+
BaseService._checkFeatureDir();
|
|
2990
|
+
return;
|
|
2991
|
+
}
|
|
2992
|
+
if (featureChoice === "mvc_architecture") {
|
|
2993
|
+
await mvcModuleTemplate(featureName2.toString());
|
|
2994
|
+
} else {
|
|
2995
|
+
await layeredModuleTemplate(featureName2.toString());
|
|
2996
|
+
}
|
|
2997
|
+
return;
|
|
2998
|
+
}
|
|
2999
|
+
if (!featureChoice || featureChoice !== "opticore_clean_module") {
|
|
3000
|
+
import_process2.default.exit(0);
|
|
3001
|
+
}
|
|
3002
|
+
UCustomFeatureInfo(featureChoice);
|
|
3003
|
+
const featureName = await _featureName();
|
|
3004
|
+
const directory = import_path9.default.join(import_process2.default.cwd(), "src", "features");
|
|
3005
|
+
const featureDirectory = import_path9.default.join(directory, featureName.toString());
|
|
3006
|
+
const featureCleanModule = BaseService._isSubdirectoryExists(featureName);
|
|
3007
|
+
if (featureCleanModule) {
|
|
3008
|
+
BaseService._featureFounded(featureName);
|
|
3009
|
+
}
|
|
3010
|
+
if ((0, import_prompts9.isCancel)(featureName)) {
|
|
3011
|
+
BaseService._cancelOperation(featureDirectory);
|
|
3012
|
+
} else {
|
|
3013
|
+
try {
|
|
3014
|
+
if (import_node_fs2.default.existsSync(directory)) {
|
|
3015
|
+
await createComponentApplication(featureDirectory, featureName);
|
|
3345
3016
|
} else {
|
|
3346
|
-
|
|
3347
|
-
if (import_node_fs2.default.existsSync(directory)) {
|
|
3348
|
-
await createComponentApplication(featureDirectory, featureName);
|
|
3349
|
-
} else {
|
|
3350
|
-
BaseService._checkFeatureDir();
|
|
3351
|
-
}
|
|
3352
|
-
} catch (err) {
|
|
3353
|
-
console.error(err.message);
|
|
3354
|
-
import_process2.default.exit();
|
|
3355
|
-
}
|
|
3017
|
+
BaseService._checkFeatureDir();
|
|
3356
3018
|
}
|
|
3357
|
-
}
|
|
3019
|
+
} catch (err) {
|
|
3020
|
+
console.error(err.message);
|
|
3021
|
+
import_process2.default.exit();
|
|
3022
|
+
}
|
|
3358
3023
|
}
|
|
3359
|
-
}
|
|
3024
|
+
}
|
|
3360
3025
|
|
|
3361
3026
|
// src/index.ts
|
|
3362
|
-
|
|
3363
|
-
Promise.resolve().then(() => init_core());
|
|
3027
|
+
runFeatureCommand();
|