opticore-feature-component 1.0.8 → 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-XPB2Z5AR.js → chunk-X2ZHQ6T5.js} +6 -2
- 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 +1293 -1614
- 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,115 +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
|
-
const 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
|
-
if ((0, import_prompts.isCancel)(optSelected)) {
|
|
167
|
-
return optSelected;
|
|
168
|
-
}
|
|
169
|
-
return optSelected[0];
|
|
170
133
|
}
|
|
171
|
-
}
|
|
134
|
+
}
|
|
135
|
+
process.exit(0);
|
|
172
136
|
}
|
|
173
|
-
|
|
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
|
+
};
|
|
174
149
|
|
|
175
150
|
// src/utils/choiceFeatureCleanModule.ts
|
|
176
151
|
async function choiceFeatureCleanModule() {
|
|
@@ -191,18 +166,9 @@ async function choiceFeatureCleanModule() {
|
|
|
191
166
|
return featureSelected;
|
|
192
167
|
}
|
|
193
168
|
}
|
|
194
|
-
var import_ansi_colors2, import_prompts2;
|
|
195
|
-
var init_choiceFeatureCleanModule = __esm({
|
|
196
|
-
"src/utils/choiceFeatureCleanModule.ts"() {
|
|
197
|
-
"use strict";
|
|
198
|
-
init_cjs_shims();
|
|
199
|
-
import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
|
|
200
|
-
import_prompts2 = require("@clack/prompts");
|
|
201
|
-
init_prompt_utils();
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
169
|
|
|
205
170
|
// src/utils/customFeatureInfo.utils.ts
|
|
171
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
|
|
206
172
|
function UCustomFeatureInfo(choice) {
|
|
207
173
|
console.log(
|
|
208
174
|
`
|
|
@@ -234,114 +200,90 @@ You have chosen : ${choice === "opticore_clean_module" ? import_ansi_colors3.def
|
|
|
234
200
|
console.log(diagram.join(`
|
|
235
201
|
`));
|
|
236
202
|
}
|
|
237
|
-
var import_ansi_colors3;
|
|
238
|
-
var init_customFeatureInfo_utils = __esm({
|
|
239
|
-
"src/utils/customFeatureInfo.utils.ts"() {
|
|
240
|
-
"use strict";
|
|
241
|
-
init_cjs_shims();
|
|
242
|
-
import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
203
|
|
|
246
204
|
// src/services/featureName.service.ts
|
|
247
|
-
var _featureName
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
"
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
"Enter feature's name :",
|
|
256
|
-
"login",
|
|
257
|
-
(value) => {
|
|
258
|
-
let pattern = new RegExp("^[a-z][A-Za-z_-]+$");
|
|
259
|
-
if (!value) {
|
|
260
|
-
return "Please enter a feature's name.";
|
|
261
|
-
}
|
|
262
|
-
if (!pattern.test(value)) {
|
|
263
|
-
return "Please enter a valide feature's name.";
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
);
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
// src/services/base.service.ts
|
|
272
|
-
var import_path, import_node_fs, import_ansi_colors4, import_process, BaseService;
|
|
273
|
-
var init_base_service = __esm({
|
|
274
|
-
"src/services/base.service.ts"() {
|
|
275
|
-
"use strict";
|
|
276
|
-
init_cjs_shims();
|
|
277
|
-
import_path = __toESM(require("path"), 1);
|
|
278
|
-
import_node_fs = __toESM(require("fs"), 1);
|
|
279
|
-
import_ansi_colors4 = __toESM(require("ansi-colors"), 1);
|
|
280
|
-
import_process = __toESM(require("process"), 1);
|
|
281
|
-
init_fsModule_utils();
|
|
282
|
-
BaseService = class {
|
|
283
|
-
static _isSubdirectoryExists(subdirectory) {
|
|
284
|
-
const subdirectoryString = typeof subdirectory === "symbol" ? subdirectory.toString() : String(subdirectory);
|
|
285
|
-
const subdirectoryPath = import_path.default.join(import_process.default.cwd(), "src", "features", subdirectoryString);
|
|
286
|
-
try {
|
|
287
|
-
const stats = import_node_fs.default.statSync(subdirectoryPath);
|
|
288
|
-
return stats.isDirectory();
|
|
289
|
-
} catch (error) {
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
static _featureFounded(feature) {
|
|
294
|
-
console.log(`${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(`${import_ansi_colors4.default.bold(`feature ${feature} is already exists.`)}`)}`)}`);
|
|
295
|
-
import_process.default.exit(0);
|
|
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.";
|
|
296
213
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
import_process.default.exit();
|
|
214
|
+
if (!pattern.test(value)) {
|
|
215
|
+
return "Please enter a valide feature's name.";
|
|
300
216
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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.
|
|
315
259
|
`);
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
static async _createApplicationDirComponent(feature) {
|
|
319
|
-
let application = "";
|
|
320
|
-
application = `${feature}/application`;
|
|
321
|
-
UFsModule.createDirectoryRecursively(application);
|
|
322
|
-
return application;
|
|
323
|
-
}
|
|
324
|
-
static async _createDomainDirComponent(feature) {
|
|
325
|
-
let domain = "";
|
|
326
|
-
domain = `${feature}/domain`;
|
|
327
|
-
UFsModule.createDirectoryRecursively(domain);
|
|
328
|
-
return domain;
|
|
329
|
-
}
|
|
330
|
-
static async _createInfraDirComponent(feature) {
|
|
331
|
-
let infrastructure = "";
|
|
332
|
-
infrastructure = `${feature}/infrastructure`;
|
|
333
|
-
UFsModule.createDirectoryRecursively(infrastructure);
|
|
334
|
-
return infrastructure;
|
|
335
|
-
}
|
|
336
|
-
static async _createPersistenceDirComponent(feature) {
|
|
337
|
-
let persistence = "";
|
|
338
|
-
persistence = `${feature}/persistence`;
|
|
339
|
-
UFsModule.createDirectoryRecursively(persistence);
|
|
340
|
-
return persistence;
|
|
341
|
-
}
|
|
342
|
-
};
|
|
260
|
+
return { featureDir, feature };
|
|
343
261
|
}
|
|
344
|
-
|
|
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
|
+
};
|
|
345
287
|
|
|
346
288
|
// src/services/controllerType.service.ts
|
|
347
289
|
async function _controllerType(messageText, defaultValue, options) {
|
|
@@ -351,41 +293,36 @@ async function _controllerType(messageText, defaultValue, options) {
|
|
|
351
293
|
options
|
|
352
294
|
);
|
|
353
295
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
init_cjs_shims();
|
|
358
|
-
init_prompt_utils();
|
|
359
|
-
}
|
|
360
|
-
});
|
|
296
|
+
|
|
297
|
+
// src/core/components/application/createController.application.ts
|
|
298
|
+
var import_prompts5 = require("@clack/prompts");
|
|
361
299
|
|
|
362
300
|
// src/core/domains/constants/cleanType.constant.ts
|
|
363
|
-
var CCleanType
|
|
364
|
-
|
|
365
|
-
"
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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");
|
|
375
317
|
|
|
376
318
|
// src/templates/cleanComponents/controller.template.ts
|
|
377
|
-
var generateControllerTemplate
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const useCaseName = `${capitalized}UseCase`;
|
|
385
|
-
const presenterName = `${capitalized}Presenter`;
|
|
386
|
-
const methodsCode = methods.map((method) => generateMethod(method, featureName, capitalized)).join("\n");
|
|
387
|
-
const errorHandler = errorHandlerAppend(capitalized);
|
|
388
|
-
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";
|
|
389
326
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
390
327
|
import { ${useCaseName} } from "../../../application/use-cases/${featureName}.usecase";
|
|
391
328
|
import { ${presenterName} } from "../presenters/${featureName}.presenter";
|
|
@@ -408,25 +345,25 @@ ${methodsCode}
|
|
|
408
345
|
${errorHandler}
|
|
409
346
|
}
|
|
410
347
|
`;
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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 `
|
|
430
367
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
431
368
|
try {
|
|
432
369
|
const useCase = ${capitalized}Controller.buildUseCase();
|
|
@@ -439,8 +376,8 @@ ${errorHandler}
|
|
|
439
376
|
}
|
|
440
377
|
}
|
|
441
378
|
`;
|
|
442
|
-
|
|
443
|
-
|
|
379
|
+
};
|
|
380
|
+
var generateFindAllMethod = (method, featureName, capitalized) => `
|
|
444
381
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
445
382
|
try {
|
|
446
383
|
const useCase = ${capitalized}Controller.buildUseCase();
|
|
@@ -453,7 +390,7 @@ ${errorHandler}
|
|
|
453
390
|
}
|
|
454
391
|
}
|
|
455
392
|
`;
|
|
456
|
-
|
|
393
|
+
var generateFindByIdMethod = (method, featureName, capitalized) => `
|
|
457
394
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
458
395
|
try {
|
|
459
396
|
const { id } = req.params;
|
|
@@ -470,7 +407,7 @@ ${errorHandler}
|
|
|
470
407
|
}
|
|
471
408
|
}
|
|
472
409
|
`;
|
|
473
|
-
|
|
410
|
+
var generateCreateMethod = (method, featureName, capitalized) => `
|
|
474
411
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
475
412
|
try {
|
|
476
413
|
const dto = req.body; // TODO: Validate with your validation layer
|
|
@@ -484,7 +421,7 @@ ${errorHandler}
|
|
|
484
421
|
}
|
|
485
422
|
}
|
|
486
423
|
`;
|
|
487
|
-
|
|
424
|
+
var generateUpdateMethod = (method, featureName, capitalized) => `
|
|
488
425
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
489
426
|
try {
|
|
490
427
|
const { id } = req.params;
|
|
@@ -502,7 +439,7 @@ ${errorHandler}
|
|
|
502
439
|
}
|
|
503
440
|
}
|
|
504
441
|
`;
|
|
505
|
-
|
|
442
|
+
var generateDeleteMethod = (method, featureName, capitalized) => `
|
|
506
443
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
507
444
|
try {
|
|
508
445
|
const { id } = req.params;
|
|
@@ -518,7 +455,7 @@ ${errorHandler}
|
|
|
518
455
|
}
|
|
519
456
|
}
|
|
520
457
|
`;
|
|
521
|
-
|
|
458
|
+
var errorHandlerAppend = (capitalized) => `
|
|
522
459
|
private static handleError(error: unknown) {
|
|
523
460
|
const message = error instanceof Error
|
|
524
461
|
? error.message
|
|
@@ -526,19 +463,12 @@ ${errorHandler}
|
|
|
526
463
|
return ResponseHandler.error(message, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
527
464
|
}
|
|
528
465
|
`;
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
});
|
|
466
|
+
var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
532
467
|
|
|
533
468
|
// src/templates/cleanComponents/entity.template.ts
|
|
534
|
-
var generateEntityTemplate,
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
"use strict";
|
|
538
|
-
init_cjs_shims();
|
|
539
|
-
generateEntityTemplate = (entityName, featureName) => {
|
|
540
|
-
const capitalized = capitalize2(featureName);
|
|
541
|
-
return `/**
|
|
469
|
+
var generateEntityTemplate = (entityName, featureName) => {
|
|
470
|
+
const capitalized = capitalize2(featureName);
|
|
471
|
+
return `/**
|
|
542
472
|
* ${entityName} \u2014 Domain Entity
|
|
543
473
|
* Represents the core business object for the "${featureName}" feature.
|
|
544
474
|
* No framework dependency, pure business logic only.
|
|
@@ -601,21 +531,14 @@ export class ${entityName} {
|
|
|
601
531
|
}
|
|
602
532
|
}
|
|
603
533
|
`;
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
});
|
|
534
|
+
};
|
|
535
|
+
var capitalize2 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
608
536
|
|
|
609
537
|
// src/templates/cleanComponents/repositoryInterface.template.ts
|
|
610
|
-
var generateRepositoryInterfaceTemplate,
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
init_cjs_shims();
|
|
615
|
-
generateRepositoryInterfaceTemplate = (interfaceName, featureName) => {
|
|
616
|
-
const entityName = `${capitalize3(featureName)}Entity`;
|
|
617
|
-
const entityImport = `../../../domain/entities/${featureName}.entity`;
|
|
618
|
-
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}";
|
|
619
542
|
|
|
620
543
|
/**
|
|
621
544
|
* ${interfaceName} \u2014 Repository Port (Application Layer)
|
|
@@ -655,24 +578,17 @@ export interface ${interfaceName} {
|
|
|
655
578
|
delete(id: string): Promise<boolean>;
|
|
656
579
|
}
|
|
657
580
|
`;
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
});
|
|
581
|
+
};
|
|
582
|
+
var capitalize3 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
662
583
|
|
|
663
584
|
// src/templates/cleanComponents/repositoryImpl.template.ts
|
|
664
|
-
var generateRepositoryImplTemplate,
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const implName = `${capitalized}Repository`;
|
|
672
|
-
const interfaceName = `I${capitalized}Repository`;
|
|
673
|
-
const entityName = `${capitalized}Entity`;
|
|
674
|
-
const entityImport = `../../../domain/entities/${featureName}.entity`;
|
|
675
|
-
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}";
|
|
676
592
|
import { ${entityName} } from "${entityImport}";
|
|
677
593
|
|
|
678
594
|
/**
|
|
@@ -764,22 +680,15 @@ export class ${implName} implements ${interfaceName} {
|
|
|
764
680
|
}
|
|
765
681
|
}
|
|
766
682
|
`;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
}
|
|
770
|
-
});
|
|
683
|
+
};
|
|
684
|
+
var capitalize4 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
771
685
|
|
|
772
686
|
// src/templates/cleanComponents/useCase.template.ts
|
|
773
|
-
var generateUseCaseTemplate,
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
generateUseCaseTemplate = (useCaseName, featureName) => {
|
|
779
|
-
const capitalized = capitalize5(featureName);
|
|
780
|
-
const interfaceName = `I${capitalized}Repository`;
|
|
781
|
-
const entityName = `${capitalized}Entity`;
|
|
782
|
-
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";
|
|
783
692
|
import { ${entityName} } from "../../domain/entities/${featureName}.entity";
|
|
784
693
|
import {
|
|
785
694
|
Create${capitalized}Dto,
|
|
@@ -846,20 +755,13 @@ export class ${useCaseName} {
|
|
|
846
755
|
}
|
|
847
756
|
}
|
|
848
757
|
`;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
});
|
|
758
|
+
};
|
|
759
|
+
var capitalize5 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
853
760
|
|
|
854
761
|
// src/templates/cleanComponents/dto.template.ts
|
|
855
|
-
var generateDtoTemplate
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
"use strict";
|
|
859
|
-
init_cjs_shims();
|
|
860
|
-
generateDtoTemplate = (featureName) => {
|
|
861
|
-
const capitalized = capitalize6(featureName);
|
|
862
|
-
return `/**
|
|
762
|
+
var generateDtoTemplate = (featureName) => {
|
|
763
|
+
const capitalized = capitalize6(featureName);
|
|
764
|
+
return `/**
|
|
863
765
|
* ${capitalized}Dto \u2014 Data Transfer Objects (Application Layer)
|
|
864
766
|
*
|
|
865
767
|
* DTOs define the shape of data entering and leaving use cases.
|
|
@@ -913,21 +815,14 @@ export class ${capitalized}DtoMapper {
|
|
|
913
815
|
}
|
|
914
816
|
}
|
|
915
817
|
`;
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
}
|
|
919
|
-
});
|
|
818
|
+
};
|
|
819
|
+
var capitalize6 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
920
820
|
|
|
921
821
|
// src/templates/cleanComponents/presenter.template.ts
|
|
922
|
-
var generatePresenterInterfaceTemplate
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
init_cjs_shims();
|
|
927
|
-
generatePresenterInterfaceTemplate = (featureName) => {
|
|
928
|
-
const capitalized = capitalize7(featureName);
|
|
929
|
-
const interfaceName = `I${capitalized}Presenter`;
|
|
930
|
-
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";
|
|
931
826
|
|
|
932
827
|
/**
|
|
933
828
|
* ${interfaceName} \u2014 Presenter Port (Application Layer)
|
|
@@ -954,12 +849,12 @@ export interface ${interfaceName} {
|
|
|
954
849
|
presentNotFound(id?: string): unknown;
|
|
955
850
|
}
|
|
956
851
|
`;
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
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";
|
|
963
858
|
import { ${capitalized}ResponseDto } from "../../../application/dtos/${featureName}.dto";
|
|
964
859
|
|
|
965
860
|
/**
|
|
@@ -995,40 +890,33 @@ export class ${implName} implements ${interfaceName} {
|
|
|
995
890
|
}
|
|
996
891
|
}
|
|
997
892
|
`;
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}
|
|
1001
|
-
});
|
|
893
|
+
};
|
|
894
|
+
var capitalize7 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1002
895
|
|
|
1003
896
|
// src/templates/cleanComponents/router.template.ts
|
|
1004
|
-
var resolveRoute
|
|
1005
|
-
|
|
1006
|
-
"
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
const handlerName = `${capitalized}HandlerRouter`;
|
|
1021
|
-
const controllerName = `${capitalized}Controller`;
|
|
1022
|
-
const routesCode = (controllerMethods || []).map((method) => {
|
|
1023
|
-
const { httpMethod, path: path10 } = resolveRoute(method, featureName);
|
|
1024
|
-
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 `{
|
|
1025
913
|
path: \`${path10}\`,
|
|
1026
914
|
method: "${httpMethod}",
|
|
1027
915
|
middlewares: [],
|
|
1028
916
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
1029
917
|
}`;
|
|
1030
|
-
|
|
1031
|
-
|
|
918
|
+
}).join(",\n");
|
|
919
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
1032
920
|
import { ${controllerName} } from "../adapters/controllers/${featureName}.controller";
|
|
1033
921
|
|
|
1034
922
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -1040,12 +928,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
1040
928
|
);
|
|
1041
929
|
};
|
|
1042
930
|
`;
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
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";
|
|
1049
937
|
import { TFeatureRoutes } from "opticore-router";
|
|
1050
938
|
|
|
1051
939
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -1057,20 +945,13 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
1057
945
|
]
|
|
1058
946
|
};
|
|
1059
947
|
`;
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
948
|
+
};
|
|
949
|
+
var capitalize8 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1064
950
|
|
|
1065
951
|
// src/templates/cleanComponents/event.template.ts
|
|
1066
|
-
var generateEventTemplate
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
"use strict";
|
|
1070
|
-
init_cjs_shims();
|
|
1071
|
-
generateEventTemplate = (featureName) => {
|
|
1072
|
-
const capitalized = capitalize9(featureName);
|
|
1073
|
-
return `/**
|
|
952
|
+
var generateEventTemplate = (featureName) => {
|
|
953
|
+
const capitalized = capitalize9(featureName);
|
|
954
|
+
return `/**
|
|
1074
955
|
* ${capitalized}Event \u2014 Domain Events
|
|
1075
956
|
*
|
|
1076
957
|
* Domain events capture facts that happened in the domain.
|
|
@@ -1140,20 +1021,13 @@ export class ${capitalized}DeletedEvent implements IDomainEvent {
|
|
|
1140
1021
|
}
|
|
1141
1022
|
}
|
|
1142
1023
|
`;
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1024
|
+
};
|
|
1025
|
+
var capitalize9 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1147
1026
|
|
|
1148
1027
|
// src/templates/cleanComponents/exception.template.ts
|
|
1149
|
-
var generateExceptionTemplate
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
"use strict";
|
|
1153
|
-
init_cjs_shims();
|
|
1154
|
-
generateExceptionTemplate = (featureName) => {
|
|
1155
|
-
const capitalized = capitalize10(featureName);
|
|
1156
|
-
return `/**
|
|
1028
|
+
var generateExceptionTemplate = (featureName) => {
|
|
1029
|
+
const capitalized = capitalize10(featureName);
|
|
1030
|
+
return `/**
|
|
1157
1031
|
* ${capitalized}Exception \u2014 Domain Exceptions
|
|
1158
1032
|
*
|
|
1159
1033
|
* Domain exceptions represent violations of business rules specific to "${featureName}".
|
|
@@ -1242,20 +1116,13 @@ export class ${capitalized}InvalidDataException extends ${capitalized}DomainExce
|
|
|
1242
1116
|
export const is${capitalized}DomainException = (error: unknown): error is ${capitalized}DomainException =>
|
|
1243
1117
|
error instanceof ${capitalized}DomainException;
|
|
1244
1118
|
`;
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
});
|
|
1119
|
+
};
|
|
1120
|
+
var capitalize10 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1249
1121
|
|
|
1250
1122
|
// src/templates/cleanComponents/service.template.ts
|
|
1251
|
-
var generateServiceTemplate
|
|
1252
|
-
|
|
1253
|
-
"
|
|
1254
|
-
"use strict";
|
|
1255
|
-
init_cjs_shims();
|
|
1256
|
-
generateServiceTemplate = (featureName) => {
|
|
1257
|
-
const capitalized = capitalize11(featureName);
|
|
1258
|
-
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";
|
|
1259
1126
|
|
|
1260
1127
|
/**
|
|
1261
1128
|
* I${capitalized}Service \u2014 Application Service Port
|
|
@@ -1306,21 +1173,14 @@ export interface I${capitalized}Service {
|
|
|
1306
1173
|
// exportToCsv(filters: Record<string, unknown>): Promise<Buffer>;
|
|
1307
1174
|
}
|
|
1308
1175
|
`;
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1176
|
+
};
|
|
1177
|
+
var capitalize11 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1313
1178
|
|
|
1314
1179
|
// src/templates/simpleComponent/model.template.ts
|
|
1315
|
-
var generateModelTemplate
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
init_cjs_shims();
|
|
1320
|
-
generateModelTemplate = (featureName) => {
|
|
1321
|
-
const capitalized = capitalize12(featureName);
|
|
1322
|
-
const modelName = `${capitalized}Model`;
|
|
1323
|
-
return `/**
|
|
1180
|
+
var generateModelTemplate = (featureName) => {
|
|
1181
|
+
const capitalized = capitalize12(featureName);
|
|
1182
|
+
const modelName = `${capitalized}Model`;
|
|
1183
|
+
return `/**
|
|
1324
1184
|
* ${modelName} \u2014 Data Model
|
|
1325
1185
|
* Plain data structure for the "${featureName}" feature.
|
|
1326
1186
|
*/
|
|
@@ -1341,22 +1201,15 @@ export class ${modelName} {
|
|
|
1341
1201
|
}
|
|
1342
1202
|
}
|
|
1343
1203
|
`;
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
}
|
|
1347
|
-
});
|
|
1204
|
+
};
|
|
1205
|
+
var capitalize12 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1348
1206
|
|
|
1349
1207
|
// src/templates/simpleComponent/simpleRepository.template.ts
|
|
1350
|
-
var generateSimpleRepositoryTemplate
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
generateSimpleRepositoryTemplate = (featureName) => {
|
|
1356
|
-
const capitalized = capitalize13(featureName);
|
|
1357
|
-
const repoName = `${capitalized}Repository`;
|
|
1358
|
-
const modelName = `${capitalized}Model`;
|
|
1359
|
-
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";
|
|
1360
1213
|
|
|
1361
1214
|
export class ${repoName} {
|
|
1362
1215
|
private store: Map<string, ${modelName}> = new Map();
|
|
@@ -1390,23 +1243,16 @@ export class ${repoName} {
|
|
|
1390
1243
|
}
|
|
1391
1244
|
}
|
|
1392
1245
|
`;
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1246
|
+
};
|
|
1247
|
+
var capitalize13 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1397
1248
|
|
|
1398
1249
|
// src/templates/simpleComponent/simpleService.template.ts
|
|
1399
|
-
var generateSimpleServiceTemplate
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
const capitalized = capitalize14(featureName);
|
|
1406
|
-
const serviceName = `${capitalized}Service`;
|
|
1407
|
-
const repoName = `${capitalized}Repository`;
|
|
1408
|
-
const modelName = `${capitalized}Model`;
|
|
1409
|
-
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";
|
|
1410
1256
|
import { ${modelName} } from "../models/${featureName}.model";
|
|
1411
1257
|
|
|
1412
1258
|
export class ${serviceName} {
|
|
@@ -1444,22 +1290,15 @@ export class ${serviceName} {
|
|
|
1444
1290
|
}
|
|
1445
1291
|
}
|
|
1446
1292
|
`;
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1293
|
+
};
|
|
1294
|
+
var capitalize14 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1451
1295
|
|
|
1452
1296
|
// src/templates/simpleComponent/simpleController.template.ts
|
|
1453
|
-
var generateSimpleControllerTemplate
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
generateSimpleControllerTemplate = (controllerName, featureName, methods) => {
|
|
1459
|
-
const capitalized = capitalize15(featureName);
|
|
1460
|
-
const serviceName = `${capitalized}Service`;
|
|
1461
|
-
const methodsCode = methods.map((method) => generateMethod2(method, capitalized, serviceName)).join("\n");
|
|
1462
|
-
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";
|
|
1463
1302
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
1464
1303
|
import { ${serviceName} } from "../services/${featureName}.service";
|
|
1465
1304
|
|
|
@@ -1475,25 +1314,25 @@ ${methodsCode}
|
|
|
1475
1314
|
}
|
|
1476
1315
|
}
|
|
1477
1316
|
`;
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
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 `
|
|
1497
1336
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1498
1337
|
try {
|
|
1499
1338
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -1504,8 +1343,8 @@ ${methodsCode}
|
|
|
1504
1343
|
}
|
|
1505
1344
|
}
|
|
1506
1345
|
`;
|
|
1507
|
-
|
|
1508
|
-
|
|
1346
|
+
};
|
|
1347
|
+
var generateFindAllMethod2 = (method, capitalized) => `
|
|
1509
1348
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1510
1349
|
try {
|
|
1511
1350
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -1516,7 +1355,7 @@ ${methodsCode}
|
|
|
1516
1355
|
}
|
|
1517
1356
|
}
|
|
1518
1357
|
`;
|
|
1519
|
-
|
|
1358
|
+
var generateFindByIdMethod2 = (method, capitalized) => `
|
|
1520
1359
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1521
1360
|
try {
|
|
1522
1361
|
const { id } = req.params;
|
|
@@ -1531,7 +1370,7 @@ ${methodsCode}
|
|
|
1531
1370
|
}
|
|
1532
1371
|
}
|
|
1533
1372
|
`;
|
|
1534
|
-
|
|
1373
|
+
var generateCreateMethod2 = (method, capitalized) => `
|
|
1535
1374
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1536
1375
|
try {
|
|
1537
1376
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -1542,7 +1381,7 @@ ${methodsCode}
|
|
|
1542
1381
|
}
|
|
1543
1382
|
}
|
|
1544
1383
|
`;
|
|
1545
|
-
|
|
1384
|
+
var generateUpdateMethod2 = (method, capitalized) => `
|
|
1546
1385
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1547
1386
|
try {
|
|
1548
1387
|
const { id } = req.params;
|
|
@@ -1557,7 +1396,7 @@ ${methodsCode}
|
|
|
1557
1396
|
}
|
|
1558
1397
|
}
|
|
1559
1398
|
`;
|
|
1560
|
-
|
|
1399
|
+
var generateDeleteMethod2 = (method, capitalized) => `
|
|
1561
1400
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
1562
1401
|
try {
|
|
1563
1402
|
const { id } = req.params;
|
|
@@ -1572,49 +1411,42 @@ ${methodsCode}
|
|
|
1572
1411
|
}
|
|
1573
1412
|
}
|
|
1574
1413
|
`;
|
|
1575
|
-
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1414
|
+
var capitalize15 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1578
1415
|
|
|
1579
1416
|
// src/templates/simpleComponent/simpleRouter.template.ts
|
|
1580
|
-
var resolveRoute2
|
|
1581
|
-
|
|
1582
|
-
"
|
|
1583
|
-
"
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
const handlerName = `${capitalized}HandlerRouter`;
|
|
1607
|
-
const controllerName = `${capitalized}Controller`;
|
|
1608
|
-
const routesCode = (controllerMethods || []).map((method) => {
|
|
1609
|
-
const { httpMethod, path: path10 } = resolveRoute2(method, featureName);
|
|
1610
|
-
return `{
|
|
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 `{
|
|
1611
1443
|
path: \`${path10}\`,
|
|
1612
1444
|
method: "${httpMethod}",
|
|
1613
1445
|
middlewares: [],
|
|
1614
1446
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
1615
1447
|
}`;
|
|
1616
|
-
|
|
1617
|
-
|
|
1448
|
+
}).join(",\n");
|
|
1449
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
1618
1450
|
import { ${controllerName} } from "../controllers/${featureName}.controller";
|
|
1619
1451
|
|
|
1620
1452
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -1626,12 +1458,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
1626
1458
|
);
|
|
1627
1459
|
};
|
|
1628
1460
|
`;
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
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";
|
|
1635
1467
|
import { TFeatureRoutes } from "opticore-router";
|
|
1636
1468
|
|
|
1637
1469
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -1643,596 +1475,513 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
1643
1475
|
]
|
|
1644
1476
|
};
|
|
1645
1477
|
`;
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1478
|
+
};
|
|
1479
|
+
var capitalize16 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1650
1480
|
|
|
1651
1481
|
// src/utils/featureComponentGenerator.utils.ts
|
|
1652
|
-
var
|
|
1653
|
-
|
|
1654
|
-
"src/
|
|
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
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
/**
|
|
1772
|
-
* Creates the concrete presenter implementation.
|
|
1773
|
-
*/
|
|
1774
|
-
static async createPresenterImpl(featureName, presenterImplDir) {
|
|
1775
|
-
const filePath = import_path2.default.join(presenterImplDir, `${featureName}.presenter.ts`);
|
|
1776
|
-
UFsModule.createFile(filePath, generatePresenterImplTemplate(featureName));
|
|
1777
|
-
console.log(import_ansi_colors5.default.green(`\u2714 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);
|
|
1778
1601
|
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
*
|
|
1783
|
-
* @returns The controller class name and the list of chosen methods.
|
|
1784
|
-
*/
|
|
1785
|
-
static async createController(featureName, controllerDir) {
|
|
1786
|
-
const controllerName = `${this.capitalize(featureName)}Controller`;
|
|
1787
|
-
const filePath = import_path2.default.join(controllerDir, `${featureName}.controller.ts`);
|
|
1788
|
-
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
1789
|
-
let methods = [];
|
|
1790
|
-
let content;
|
|
1791
|
-
if (wantsMethods && !(0, import_prompts3.isCancel)(wantsMethods)) {
|
|
1792
|
-
const methodsText = await UPrompt.text(
|
|
1793
|
-
"Enter the method names (comma separated):",
|
|
1794
|
-
"create, findAll, findById, update, delete",
|
|
1795
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
1796
|
-
);
|
|
1797
|
-
if (!(0, import_prompts3.isCancel)(methodsText)) {
|
|
1798
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
1799
|
-
}
|
|
1800
|
-
content = generateControllerTemplate(controllerName, featureName, methods);
|
|
1801
|
-
} else {
|
|
1802
|
-
content = `import { Request, Response } from "express";
|
|
1602
|
+
content = generateControllerTemplate(controllerName, featureName, methods);
|
|
1603
|
+
} else {
|
|
1604
|
+
content = `import { Request, Response } from "express";
|
|
1803
1605
|
|
|
1804
1606
|
export class ${controllerName} {}
|
|
1805
1607
|
`;
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
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);
|
|
1834
1654
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
static async createSimpleController(featureName, controllerDir) {
|
|
1839
|
-
const controllerName = `${this.capitalize(featureName)}Controller`;
|
|
1840
|
-
const filePath = import_path2.default.join(controllerDir, `${featureName}.controller.ts`);
|
|
1841
|
-
const wantsMethods = await UPrompt.confirm("Do you want to add methods to the controller?");
|
|
1842
|
-
let methods = [];
|
|
1843
|
-
let content;
|
|
1844
|
-
if (wantsMethods && !(0, import_prompts3.isCancel)(wantsMethods)) {
|
|
1845
|
-
const methodsText = await UPrompt.text(
|
|
1846
|
-
"Enter the method names (comma separated):",
|
|
1847
|
-
"create, findAll, findById, update, delete",
|
|
1848
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
1849
|
-
);
|
|
1850
|
-
if (!(0, import_prompts3.isCancel)(methodsText)) {
|
|
1851
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
1852
|
-
}
|
|
1853
|
-
content = generateSimpleControllerTemplate(controllerName, featureName, methods);
|
|
1854
|
-
} else {
|
|
1855
|
-
content = `import { Request, Response } from "express";
|
|
1655
|
+
content = generateSimpleControllerTemplate(controllerName, featureName, methods);
|
|
1656
|
+
} else {
|
|
1657
|
+
content = `import { Request, Response } from "express";
|
|
1856
1658
|
|
|
1857
1659
|
export class ${controllerName} {}
|
|
1858
1660
|
`;
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
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;
|
|
1863
1703
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
static async createRouterHandler(featureName, routerHandlerDir, controllerMethods) {
|
|
1869
|
-
const filePath = import_path2.default.join(routerHandlerDir, `${featureName}.router.handler.ts`);
|
|
1870
|
-
const content = this.structure === "simple" ? generateSimpleRouterHandlerTemplate(featureName, controllerMethods) : generateRouterHandlerTemplate(featureName, controllerMethods);
|
|
1871
|
-
UFsModule.createFile(filePath, content);
|
|
1872
|
-
console.log(import_ansi_colors5.default.green(`\u2714 Router Handler created: ${filePath}`));
|
|
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;
|
|
1873
1708
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
static async createRouter(featureName, routerDir) {
|
|
1879
|
-
const filePath = import_path2.default.join(routerDir, `${featureName}.router.ts`);
|
|
1880
|
-
const content = this.structure === "simple" ? generateSimpleRouterTemplate(featureName) : generateRouterTemplate(featureName);
|
|
1881
|
-
UFsModule.createFile(filePath, content);
|
|
1882
|
-
await this.updateRegisterRouter(featureName);
|
|
1883
|
-
console.log(import_ansi_colors5.default.green(`\u2714 Router 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;
|
|
1884
1713
|
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1714
|
+
if (lastImportIndex !== -1) {
|
|
1715
|
+
lines.splice(lastImportIndex + 1, 0, importStatement);
|
|
1716
|
+
content = lines.join("\n");
|
|
1717
|
+
} else {
|
|
1718
|
+
content = importStatement + "\n" + content;
|
|
1887
1719
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
const lines = content.split("\n");
|
|
1908
|
-
let lastImportIndex = -1;
|
|
1909
|
-
for (let i = 0; i < lines.length; i++) {
|
|
1910
|
-
if (lines[i].trim().startsWith("import ")) lastImportIndex = i;
|
|
1911
|
-
}
|
|
1912
|
-
if (lastImportIndex !== -1) {
|
|
1913
|
-
lines.splice(lastImportIndex + 1, 0, importStatement);
|
|
1914
|
-
content = lines.join("\n");
|
|
1915
|
-
} else {
|
|
1916
|
-
content = importStatement + "\n" + content;
|
|
1917
|
-
}
|
|
1918
|
-
const ARRAY_OPEN = "registered([";
|
|
1919
|
-
const ARRAY_CLOSE = "]);";
|
|
1920
|
-
const startIdx = content.indexOf(ARRAY_OPEN);
|
|
1921
|
-
if (startIdx === -1) {
|
|
1922
|
-
console.log(import_ansi_colors5.default.yellow(`\u26A0 Could not find 'registered([' in register.router.ts.`));
|
|
1923
|
-
return;
|
|
1924
|
-
}
|
|
1925
|
-
const endIdx = content.indexOf(ARRAY_CLOSE, startIdx + ARRAY_OPEN.length);
|
|
1926
|
-
if (endIdx === -1) {
|
|
1927
|
-
console.log(import_ansi_colors5.default.yellow(`\u26A0 Could not find matching ']);' in register.router.ts.`));
|
|
1928
|
-
return;
|
|
1929
|
-
}
|
|
1930
|
-
const arrayContent = content.substring(startIdx + ARRAY_OPEN.length, endIdx);
|
|
1931
|
-
const existingRoutes = arrayContent.split("\n").map((l) => l.trim().replace(/,+$/, "")).filter(Boolean);
|
|
1932
|
-
if (!existingRoutes.includes(routerName)) {
|
|
1933
|
-
existingRoutes.push(routerName);
|
|
1934
|
-
}
|
|
1935
|
-
const indentedRoutes = existingRoutes.map((r) => ` ${r},`).join("\n");
|
|
1936
|
-
const newContent = content.substring(0, startIdx + ARRAY_OPEN.length) + `
|
|
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;
|
|
1726
|
+
}
|
|
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) + `
|
|
1937
1739
|
${indentedRoutes}
|
|
1938
1740
|
` + content.substring(endIdx);
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
}
|
|
1945
|
-
};
|
|
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
|
+
}
|
|
1946
1746
|
}
|
|
1947
|
-
}
|
|
1747
|
+
};
|
|
1948
1748
|
|
|
1949
1749
|
// src/templates/simpleComponent/simpleComponent.template.ts
|
|
1950
|
-
var
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
import_path3
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
const controller = await FeatureComponentGeneratorUtils.createSimpleController(
|
|
1981
|
-
featureName,
|
|
1982
|
-
paths.controllersDir
|
|
1983
|
-
);
|
|
1984
|
-
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, paths.routesDir, controller.methods);
|
|
1985
|
-
await FeatureComponentGeneratorUtils.createRouter(featureName, paths.routesDir);
|
|
1986
|
-
console.log(
|
|
1987
|
-
import_ansi_colors6.default.bgGreen(
|
|
1988
|
-
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(`
|
|
1989
1780
|
\u{1F389} Feature "${featureName}" scaffolded with Simple Component!
|
|
1990
1781
|
`)
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
}
|
|
1995
|
-
});
|
|
1782
|
+
)
|
|
1783
|
+
);
|
|
1784
|
+
};
|
|
1996
1785
|
|
|
1997
1786
|
// src/templates/fullCleanComponent/fullCleanComponent.template.ts
|
|
1998
|
-
var import_path4
|
|
1999
|
-
var
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
import_path4
|
|
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
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
paths.controllerDir
|
|
2051
|
-
);
|
|
2052
|
-
await FeatureComponentGeneratorUtils.createRouterHandler(featureName, paths.routerDir, controller.methods);
|
|
2053
|
-
await FeatureComponentGeneratorUtils.createRouter(featureName, paths.routerDir);
|
|
2054
|
-
console.log(
|
|
2055
|
-
import_ansi_colors7.default.bgGreen(
|
|
2056
|
-
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(`
|
|
2057
1839
|
\u{1F389} Feature "${featureName}" scaffolded with Clean Architecture!
|
|
2058
1840
|
`)
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
}
|
|
2063
|
-
});
|
|
1841
|
+
)
|
|
1842
|
+
);
|
|
1843
|
+
};
|
|
2064
1844
|
|
|
2065
1845
|
// src/templates/cleanComponentByStep/cleanComponentByStep.template.ts
|
|
2066
|
-
var import_path5
|
|
2067
|
-
var
|
|
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
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
track();
|
|
2146
|
-
}
|
|
2147
|
-
if (await ask(`Router - ${featureName}.router.ts`)) {
|
|
2148
|
-
await FeatureComponentGeneratorUtils.createRouter(featureName, mkDir(import_path5.default.join(base, "infrastructure", "routes")));
|
|
2149
|
-
track();
|
|
2150
|
-
}
|
|
2151
|
-
if (created === 0) {
|
|
2152
|
-
console.log(import_ansi_colors8.default.yellow(`
|
|
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(`
|
|
2153
1925
|
\u26A0 No files were created for feature "${featureName}".`));
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
1926
|
+
} else {
|
|
1927
|
+
console.log(
|
|
1928
|
+
import_ansi_colors8.default.bgGreen(import_ansi_colors8.default.white(`
|
|
2157
1929
|
\u{1F389} Feature "${featureName}" \u2014 ${created} file(s) created step by step.
|
|
2158
1930
|
`))
|
|
2159
|
-
|
|
2160
|
-
}
|
|
2161
|
-
};
|
|
1931
|
+
);
|
|
2162
1932
|
}
|
|
2163
|
-
}
|
|
1933
|
+
};
|
|
2164
1934
|
|
|
2165
1935
|
// src/core/components/application/createController.application.ts
|
|
2166
|
-
var
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
} else {
|
|
2191
|
-
switch (askComponentType) {
|
|
2192
|
-
case CCleanType.simple_component:
|
|
2193
|
-
await simpleComponentTemplate(featureName);
|
|
2194
|
-
break;
|
|
2195
|
-
case CCleanType.clean_component_by_step:
|
|
2196
|
-
await cleanComponentByStepTemplate(featureName);
|
|
2197
|
-
break;
|
|
2198
|
-
case CCleanType.full_clean_component:
|
|
2199
|
-
await fullCleanComponentTemplate(featureName);
|
|
2200
|
-
break;
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
};
|
|
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
|
+
}
|
|
2204
1960
|
}
|
|
2205
|
-
}
|
|
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");
|
|
2206
1968
|
|
|
2207
1969
|
// src/core/domains/constants/resolveRoute.constant.ts
|
|
2208
|
-
var CResolveRoute
|
|
2209
|
-
|
|
2210
|
-
"
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
if (lower.includes("create") || lower.includes("add")) return { httpMethod: "post", path: `/${moduleName}` };
|
|
2218
|
-
if (lower.includes("update") || lower.includes("edit")) return { httpMethod: "put", path: `/${moduleName}/:id` };
|
|
2219
|
-
if (lower.includes("delete") || lower.includes("remove")) return { httpMethod: "delete", path: `/${moduleName}/:id` };
|
|
2220
|
-
return { httpMethod: "get", path: `/${moduleName}/${lower}` };
|
|
2221
|
-
};
|
|
2222
|
-
}
|
|
2223
|
-
});
|
|
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
|
+
};
|
|
2224
1979
|
|
|
2225
1980
|
// src/templates/customModule/buildYourOwnArchitecture.template.ts
|
|
2226
|
-
var capitalize17
|
|
2227
|
-
var
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
init_cjs_shims();
|
|
2231
|
-
init_resolveRoute_constant();
|
|
2232
|
-
capitalize17 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2233
|
-
generateBuildYourOwnControllerTemplate = (fileName, methods) => {
|
|
2234
|
-
const controllerName = `${capitalize17(fileName)}Controller`;
|
|
2235
|
-
const body = methods.length === 0 ? ` // TODO: add your handler methods here` : methods.map((method) => `
|
|
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) => `
|
|
2236
1985
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2237
1986
|
try {
|
|
2238
1987
|
// TODO: implement ${method}
|
|
@@ -2242,70 +1991,70 @@ var init_buildYourOwnArchitecture_template = __esm({
|
|
|
2242
1991
|
return ResponseHandler.error(message, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
2243
1992
|
}
|
|
2244
1993
|
}`).join("\n");
|
|
2245
|
-
|
|
1994
|
+
return `import { Request, Response } from "opticore-express";
|
|
2246
1995
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
2247
1996
|
|
|
2248
1997
|
export class ${controllerName} {
|
|
2249
1998
|
${body}
|
|
2250
1999
|
}`.trimEnd() + "\n";
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
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) => `
|
|
2255
2004
|
async ${method}(): Promise<unknown> {
|
|
2256
2005
|
// TODO: implement ${method}
|
|
2257
2006
|
throw new Error("Not implemented");
|
|
2258
2007
|
}`).join("\n");
|
|
2259
|
-
|
|
2008
|
+
return `export class ${serviceName} {
|
|
2260
2009
|
${body}
|
|
2261
2010
|
}`.trimEnd() + "\n";
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2011
|
+
};
|
|
2012
|
+
var generateBuildYourOwnServiceFunctionTemplate = (fileName) => {
|
|
2013
|
+
const functionName = `${fileName}Service`;
|
|
2014
|
+
return `export async function ${functionName}(): Promise<unknown> {
|
|
2266
2015
|
// TODO: implement ${functionName}
|
|
2267
2016
|
throw new Error("Not implemented");
|
|
2268
2017
|
}`.trimEnd() + "\n";
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
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} {
|
|
2274
2023
|
${body}
|
|
2275
2024
|
}`.trimEnd() + "\n";
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
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} {
|
|
2281
2030
|
constructor(
|
|
2282
2031
|
${ctorParams}
|
|
2283
2032
|
) {}
|
|
2284
2033
|
}`.trimEnd() + "\n";
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
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} {
|
|
2290
2039
|
// TODO: inject your data source (ORM, DB client, etc.)
|
|
2291
2040
|
${body}
|
|
2292
2041
|
}`.trimEnd() + "\n";
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
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) => `{
|
|
2303
2052
|
path: "${route.path}",
|
|
2304
2053
|
method: "${route.httpMethod}",
|
|
2305
2054
|
middlewares: [],
|
|
2306
2055
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${route.action}(ctx.req, ctx.res)
|
|
2307
2056
|
}`).join(",\n").replace(/\n/g, "\n ");
|
|
2308
|
-
|
|
2057
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
2309
2058
|
// TODO: adjust this import if "${controllerName}" lives in a different folder
|
|
2310
2059
|
import { ${controllerName} } from "./${fileName}.controller";
|
|
2311
2060
|
|
|
@@ -2317,11 +2066,57 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
2317
2066
|
]
|
|
2318
2067
|
);
|
|
2319
2068
|
};`.trimEnd() + "\n";
|
|
2320
|
-
|
|
2321
|
-
}
|
|
2322
|
-
});
|
|
2069
|
+
};
|
|
2323
2070
|
|
|
2324
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;
|
|
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" };
|
|
2101
|
+
});
|
|
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
|
+
};
|
|
2325
2120
|
async function handleFileCreation(dirPath) {
|
|
2326
2121
|
const fileType = await UPrompt.select(
|
|
2327
2122
|
"What type of file do you want to create?",
|
|
@@ -2453,111 +2248,49 @@ async function handleDirectory(dirPath, node) {
|
|
|
2453
2248
|
}
|
|
2454
2249
|
}
|
|
2455
2250
|
}
|
|
2456
|
-
var
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
}
|
|
2483
|
-
});
|
|
2484
|
-
if ((0, import_prompts6.isCancel)(raw)) {
|
|
2485
|
-
return void 0;
|
|
2486
|
-
}
|
|
2487
|
-
return raw;
|
|
2488
|
-
};
|
|
2489
|
-
askCommaSeparatedList = async (message, placeholder) => {
|
|
2490
|
-
const raw = await UPrompt.text(message, placeholder, () => void 0);
|
|
2491
|
-
if ((0, import_prompts6.isCancel)(raw) || !raw) return [];
|
|
2492
|
-
return raw.split(",").map((v) => v.trim()).filter(Boolean);
|
|
2493
|
-
};
|
|
2494
|
-
parseFieldDefinitions = (raw) => raw.map((entry) => {
|
|
2495
|
-
const [name, type] = entry.split(":").map((v) => v.trim());
|
|
2496
|
-
return { name: name || entry, type: type || "string" };
|
|
2497
|
-
});
|
|
2498
|
-
renderTree = (node, prefix = "") => {
|
|
2499
|
-
const lines = [];
|
|
2500
|
-
const children = node.children ?? [];
|
|
2501
|
-
children.forEach((child, index) => {
|
|
2502
|
-
const isLast = index === children.length - 1;
|
|
2503
|
-
const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
2504
|
-
lines.push(`${prefix}${branch}${child.name}${child.type === "dir" ? "/" : ""}`);
|
|
2505
|
-
if (child.type === "dir") {
|
|
2506
|
-
const nextPrefix = prefix + (isLast ? " " : "\u2502 ");
|
|
2507
|
-
lines.push(...renderTree(child, nextPrefix));
|
|
2508
|
-
}
|
|
2509
|
-
});
|
|
2510
|
-
return lines;
|
|
2511
|
-
};
|
|
2512
|
-
printTree = (root) => {
|
|
2513
|
-
console.log(import_ansi_colors9.default.yellow(`${root.name}/`));
|
|
2514
|
-
renderTree(root).forEach((line) => console.log(import_ansi_colors9.default.yellow(line)));
|
|
2515
|
-
};
|
|
2516
|
-
buildYourOwnArchitectureScaffoldTemplate = async () => {
|
|
2517
|
-
const featuresDir = import_path6.default.join(process.cwd(), "src", "features");
|
|
2518
|
-
const forest = [];
|
|
2519
|
-
let creatingNewRoot = true;
|
|
2520
|
-
while (creatingNewRoot) {
|
|
2521
|
-
const rootName = await askName("Enter the name of the root folder for your architecture:", "myArchitecture");
|
|
2522
|
-
if (!rootName) {
|
|
2523
|
-
console.log(import_ansi_colors9.default.bgRed(import_ansi_colors9.default.white("Operation cancelled.")));
|
|
2524
|
-
process.exit(0);
|
|
2525
|
-
}
|
|
2526
|
-
const rootDir = import_path6.default.join(featuresDir, rootName);
|
|
2527
|
-
if (import_fs3.default.existsSync(rootDir)) {
|
|
2528
|
-
info(`Folder "${rootName}" already exists, new files/folders will be added inside it.`);
|
|
2529
|
-
}
|
|
2530
|
-
UFsModule.createDirectoryRecursively(rootDir);
|
|
2531
|
-
const rootNode = { name: rootName, type: "dir", children: [] };
|
|
2532
|
-
forest.push(rootNode);
|
|
2533
|
-
await handleDirectory(rootDir, rootNode);
|
|
2534
|
-
const wantsNewRoot = await UPrompt.confirm(
|
|
2535
|
-
"Do you want to create a new folder at the root of your architecture?",
|
|
2536
|
-
false
|
|
2537
|
-
);
|
|
2538
|
-
if ((0, import_prompts6.isCancel)(wantsNewRoot) || wantsNewRoot !== true) {
|
|
2539
|
-
console.log(import_ansi_colors9.default.cyan("En disant non, ce sera la fin de la cr\xE9ation de votre propre architecture."));
|
|
2540
|
-
creatingNewRoot = false;
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
console.log(`
|
|
2544
|
-
${import_ansi_colors9.default.bgGreen(import_ansi_colors9.default.white("\n\u{1F389} Your custom architecture has been created!\n"))}`);
|
|
2545
|
-
forest.forEach((root) => printTree(root));
|
|
2546
|
-
};
|
|
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
|
+
}
|
|
2547
2277
|
}
|
|
2548
|
-
|
|
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");
|
|
2549
2287
|
|
|
2550
2288
|
// src/templates/mvcModule/mvcModule.template.ts
|
|
2551
|
-
var capitalize18
|
|
2552
|
-
var
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
capitalize18 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2557
|
-
generateMvcModelTemplate = (featureName) => {
|
|
2558
|
-
const capitalized = capitalize18(featureName);
|
|
2559
|
-
const modelName = `${capitalized}Model`;
|
|
2560
|
-
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 `/**
|
|
2561
2294
|
* ${modelName} \u2014 Model
|
|
2562
2295
|
* Owns both the data shape and the data-access logic for "${featureName}".
|
|
2563
2296
|
*/
|
|
@@ -2611,12 +2344,12 @@ export class ${modelName} {
|
|
|
2611
2344
|
}
|
|
2612
2345
|
}
|
|
2613
2346
|
`;
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
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";
|
|
2620
2353
|
|
|
2621
2354
|
/**
|
|
2622
2355
|
* ${viewName} \u2014 View
|
|
@@ -2637,13 +2370,13 @@ export class ${viewName} {
|
|
|
2637
2370
|
}
|
|
2638
2371
|
}
|
|
2639
2372
|
`;
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
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";
|
|
2647
2380
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
2648
2381
|
import { ${modelName} } from "../models/${featureName}.model";
|
|
2649
2382
|
import { ${viewName} } from "../views/${featureName}.view";
|
|
@@ -2656,25 +2389,25 @@ ${methodsCode}
|
|
|
2656
2389
|
}
|
|
2657
2390
|
}
|
|
2658
2391
|
`;
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
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 `
|
|
2678
2411
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2679
2412
|
try {
|
|
2680
2413
|
// TODO: Implement ${method} logic
|
|
@@ -2684,8 +2417,8 @@ ${methodsCode}
|
|
|
2684
2417
|
}
|
|
2685
2418
|
}
|
|
2686
2419
|
`;
|
|
2687
|
-
|
|
2688
|
-
|
|
2420
|
+
};
|
|
2421
|
+
var generateFindAllMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2689
2422
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2690
2423
|
try {
|
|
2691
2424
|
const models = await ${modelName}.findAll();
|
|
@@ -2695,7 +2428,7 @@ ${methodsCode}
|
|
|
2695
2428
|
}
|
|
2696
2429
|
}
|
|
2697
2430
|
`;
|
|
2698
|
-
|
|
2431
|
+
var generateFindByIdMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2699
2432
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2700
2433
|
try {
|
|
2701
2434
|
const { id } = req.params;
|
|
@@ -2709,7 +2442,7 @@ ${methodsCode}
|
|
|
2709
2442
|
}
|
|
2710
2443
|
}
|
|
2711
2444
|
`;
|
|
2712
|
-
|
|
2445
|
+
var generateCreateMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2713
2446
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2714
2447
|
try {
|
|
2715
2448
|
const model = await ${modelName}.create(req.body);
|
|
@@ -2719,7 +2452,7 @@ ${methodsCode}
|
|
|
2719
2452
|
}
|
|
2720
2453
|
}
|
|
2721
2454
|
`;
|
|
2722
|
-
|
|
2455
|
+
var generateUpdateMethod3 = (method, capitalized, modelName, viewName) => `
|
|
2723
2456
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2724
2457
|
try {
|
|
2725
2458
|
const { id } = req.params;
|
|
@@ -2733,7 +2466,7 @@ ${methodsCode}
|
|
|
2733
2466
|
}
|
|
2734
2467
|
}
|
|
2735
2468
|
`;
|
|
2736
|
-
|
|
2469
|
+
var generateDeleteMethod3 = (method, capitalized, modelName) => `
|
|
2737
2470
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
2738
2471
|
try {
|
|
2739
2472
|
const { id } = req.params;
|
|
@@ -2747,20 +2480,20 @@ ${methodsCode}
|
|
|
2747
2480
|
}
|
|
2748
2481
|
}
|
|
2749
2482
|
`;
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
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 `{
|
|
2757
2490
|
path: \`${path10}\`,
|
|
2758
2491
|
method: "${httpMethod}",
|
|
2759
2492
|
middlewares: [],
|
|
2760
2493
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
2761
2494
|
}`;
|
|
2762
|
-
|
|
2763
|
-
|
|
2495
|
+
}).join(",\n");
|
|
2496
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
2764
2497
|
import { ${controllerName} } from "../controllers/${featureName}.controller";
|
|
2765
2498
|
|
|
2766
2499
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -2772,12 +2505,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
2772
2505
|
);
|
|
2773
2506
|
};
|
|
2774
2507
|
`;
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
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";
|
|
2781
2514
|
import { TFeatureRoutes } from "opticore-router";
|
|
2782
2515
|
|
|
2783
2516
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -2789,113 +2522,97 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
2789
2522
|
]
|
|
2790
2523
|
};
|
|
2791
2524
|
`;
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
}
|
|
2798
|
-
if (lower.includes("findbyid") || lower.includes("getbyid") || lower.includes("getone")) {
|
|
2799
|
-
return { httpMethod: "get", path: `/${featureName}/:id` };
|
|
2800
|
-
}
|
|
2801
|
-
if (lower.includes("create") || lower.includes("add")) {
|
|
2802
|
-
return { httpMethod: "post", path: `/${featureName}` };
|
|
2803
|
-
}
|
|
2804
|
-
if (lower.includes("update") || lower.includes("edit")) {
|
|
2805
|
-
return { httpMethod: "put", path: `/${featureName}/:id` };
|
|
2806
|
-
}
|
|
2807
|
-
if (lower.includes("delete") || lower.includes("remove")) {
|
|
2808
|
-
return { httpMethod: "delete", path: `/${featureName}/:id` };
|
|
2809
|
-
}
|
|
2810
|
-
return { httpMethod: "get", path: `/${featureName}/${lower}` };
|
|
2811
|
-
};
|
|
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}` };
|
|
2812
2530
|
}
|
|
2813
|
-
|
|
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
|
+
};
|
|
2814
2545
|
|
|
2815
2546
|
// src/templates/mvcModule/mvcModuleScaffold.template.ts
|
|
2816
|
-
var
|
|
2817
|
-
var
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
import_path7
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
if (wantsMethods && !(0, import_prompts7.isCancel)(wantsMethods)) {
|
|
2848
|
-
const methodsText = await UPrompt.text(
|
|
2849
|
-
"Enter the method names (comma separated):",
|
|
2850
|
-
"create, findAll, findById, update, delete",
|
|
2851
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
2852
|
-
);
|
|
2853
|
-
if (!(0, import_prompts7.isCancel)(methodsText)) {
|
|
2854
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
2855
|
-
}
|
|
2856
|
-
controllerContent = generateMvcControllerTemplate(controllerName, featureName, methods);
|
|
2857
|
-
} else {
|
|
2858
|
-
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";
|
|
2859
2578
|
|
|
2860
2579
|
export class ${controllerName} {}
|
|
2861
2580
|
`;
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
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(`
|
|
2880
2599
|
\u{1F389} Feature "${featureName}" scaffolded with MVC architecture!
|
|
2881
2600
|
`)
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
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");
|
|
2887
2609
|
|
|
2888
2610
|
// src/templates/layeredModule/layeredModule.template.ts
|
|
2889
|
-
var capitalize20
|
|
2890
|
-
var
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
capitalize20 = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
2895
|
-
generateLayeredEntityTemplate = (featureName) => {
|
|
2896
|
-
const capitalized = capitalize20(featureName);
|
|
2897
|
-
const entityName = `${capitalized}Entity`;
|
|
2898
|
-
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 `/**
|
|
2899
2616
|
* ${entityName} \u2014 Entity
|
|
2900
2617
|
* Plain data structure for the "${featureName}" domain. No data-access logic here.
|
|
2901
2618
|
*/
|
|
@@ -2908,11 +2625,11 @@ export class ${entityName} {
|
|
|
2908
2625
|
) {}
|
|
2909
2626
|
}
|
|
2910
2627
|
`;
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2628
|
+
};
|
|
2629
|
+
var generateLayeredDtoTemplate = (featureName) => {
|
|
2630
|
+
const capitalized = capitalize20(featureName);
|
|
2631
|
+
const entityName = `${capitalized}Entity`;
|
|
2632
|
+
return `import { ${entityName} } from "../entities/${featureName}.entity";
|
|
2916
2633
|
|
|
2917
2634
|
export interface Create${capitalized}Dto {
|
|
2918
2635
|
// TODO: define the fields required to create a ${featureName}
|
|
@@ -2935,12 +2652,12 @@ export const to${capitalized}ResponseDto = (entity: ${entityName}): ${capitalize
|
|
|
2935
2652
|
updatedAt: entity.updatedAt,
|
|
2936
2653
|
});
|
|
2937
2654
|
`;
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
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";
|
|
2944
2661
|
|
|
2945
2662
|
export class ${repoName} {
|
|
2946
2663
|
private store: Map<string, ${entityName}> = new Map();
|
|
@@ -2974,13 +2691,13 @@ export class ${repoName} {
|
|
|
2974
2691
|
}
|
|
2975
2692
|
}
|
|
2976
2693
|
`;
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
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";
|
|
2984
2701
|
import { ${entityName} } from "../entities/${featureName}.entity";
|
|
2985
2702
|
import { Create${capitalized}Dto, Update${capitalized}Dto, ${capitalized}ResponseDto, to${capitalized}ResponseDto } from "../dto/${featureName}.dto";
|
|
2986
2703
|
|
|
@@ -3023,12 +2740,12 @@ export class ${serviceName} {
|
|
|
3023
2740
|
}
|
|
3024
2741
|
}
|
|
3025
2742
|
`;
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
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";
|
|
3032
2749
|
import { ResponseHandler, HttpStatusCode, IResponseHandlerSuccessData } from "opticore-http-response";
|
|
3033
2750
|
import { ${serviceName} } from "../services/${featureName}.service";
|
|
3034
2751
|
|
|
@@ -3044,15 +2761,15 @@ ${methodsCode}
|
|
|
3044
2761
|
}
|
|
3045
2762
|
}
|
|
3046
2763
|
`;
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
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 `
|
|
3056
2773
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3057
2774
|
try {
|
|
3058
2775
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -3063,8 +2780,8 @@ ${methodsCode}
|
|
|
3063
2780
|
}
|
|
3064
2781
|
}
|
|
3065
2782
|
`;
|
|
3066
|
-
|
|
3067
|
-
|
|
2783
|
+
};
|
|
2784
|
+
var generateFindAllMethod4 = (method, capitalized) => `
|
|
3068
2785
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3069
2786
|
try {
|
|
3070
2787
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -3075,7 +2792,7 @@ ${methodsCode}
|
|
|
3075
2792
|
}
|
|
3076
2793
|
}
|
|
3077
2794
|
`;
|
|
3078
|
-
|
|
2795
|
+
var generateFindByIdMethod4 = (method, capitalized) => `
|
|
3079
2796
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3080
2797
|
try {
|
|
3081
2798
|
const { id } = req.params;
|
|
@@ -3090,7 +2807,7 @@ ${methodsCode}
|
|
|
3090
2807
|
}
|
|
3091
2808
|
}
|
|
3092
2809
|
`;
|
|
3093
|
-
|
|
2810
|
+
var generateCreateMethod4 = (method, capitalized) => `
|
|
3094
2811
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3095
2812
|
try {
|
|
3096
2813
|
const service = ${capitalized}Controller.buildService();
|
|
@@ -3101,7 +2818,7 @@ ${methodsCode}
|
|
|
3101
2818
|
}
|
|
3102
2819
|
}
|
|
3103
2820
|
`;
|
|
3104
|
-
|
|
2821
|
+
var generateUpdateMethod4 = (method, capitalized) => `
|
|
3105
2822
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3106
2823
|
try {
|
|
3107
2824
|
const { id } = req.params;
|
|
@@ -3116,7 +2833,7 @@ ${methodsCode}
|
|
|
3116
2833
|
}
|
|
3117
2834
|
}
|
|
3118
2835
|
`;
|
|
3119
|
-
|
|
2836
|
+
var generateDeleteMethod4 = (method, capitalized) => `
|
|
3120
2837
|
static async ${method}(req: Request, res: Response): Promise<IResponseHandlerSuccessData | ReturnType<typeof ResponseHandler.error>> {
|
|
3121
2838
|
try {
|
|
3122
2839
|
const { id } = req.params;
|
|
@@ -3131,20 +2848,20 @@ ${methodsCode}
|
|
|
3131
2848
|
}
|
|
3132
2849
|
}
|
|
3133
2850
|
`;
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
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 `{
|
|
3141
2858
|
path: \`${path10}\`,
|
|
3142
2859
|
method: "${httpMethod}",
|
|
3143
2860
|
middlewares: [],
|
|
3144
2861
|
handler: async (ctx: ICustomContext) => await ${controllerName}.${method}(ctx.req, ctx.res)
|
|
3145
2862
|
}`;
|
|
3146
|
-
|
|
3147
|
-
|
|
2863
|
+
}).join(",\n");
|
|
2864
|
+
return `import { OpticoreRoutingFactory, ICustomContext, IMultipleRouteDefinition } from "opticore-router";
|
|
3148
2865
|
import { ${controllerName} } from "../controllers/${featureName}.controller";
|
|
3149
2866
|
|
|
3150
2867
|
export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
@@ -3156,12 +2873,12 @@ export const ${handlerName}: () => IMultipleRouteDefinition = () => {
|
|
|
3156
2873
|
);
|
|
3157
2874
|
};
|
|
3158
2875
|
`;
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
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";
|
|
3165
2882
|
import { TFeatureRoutes } from "opticore-router";
|
|
3166
2883
|
|
|
3167
2884
|
export const ${routerName}: TFeatureRoutes = {
|
|
@@ -3173,176 +2890,138 @@ export const ${routerName}: TFeatureRoutes = {
|
|
|
3173
2890
|
]
|
|
3174
2891
|
};
|
|
3175
2892
|
`;
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
}
|
|
3187
|
-
});
|
|
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
|
+
};
|
|
3188
2903
|
|
|
3189
2904
|
// src/templates/layeredModule/layeredModuleScaffold.template.ts
|
|
3190
|
-
var
|
|
3191
|
-
var
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
import_path8
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
if (wantsMethods && !(0, import_prompts8.isCancel)(wantsMethods)) {
|
|
3228
|
-
const methodsText = await UPrompt.text(
|
|
3229
|
-
"Enter the method names (comma separated):",
|
|
3230
|
-
"create, findAll, findById, update, delete",
|
|
3231
|
-
(v) => v ? void 0 : "You must enter at least one method."
|
|
3232
|
-
);
|
|
3233
|
-
if (!(0, import_prompts8.isCancel)(methodsText)) {
|
|
3234
|
-
methods = methodsText.split(",").map((m) => m.trim()).filter(Boolean);
|
|
3235
|
-
}
|
|
3236
|
-
controllerContent = generateLayeredControllerTemplate(controllerName, featureName, methods);
|
|
3237
|
-
} else {
|
|
3238
|
-
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";
|
|
3239
2942
|
|
|
3240
2943
|
export class ${controllerName} {}
|
|
3241
2944
|
`;
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
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(`
|
|
3260
2963
|
\u{1F389} Feature "${featureName}" scaffolded with Layered architecture!
|
|
3261
2964
|
`)
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
}
|
|
3266
|
-
});
|
|
2965
|
+
)
|
|
2966
|
+
);
|
|
2967
|
+
};
|
|
3267
2968
|
|
|
3268
2969
|
// src/core/core.ts
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
"
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
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
|
-
return;
|
|
3316
|
-
}
|
|
3317
|
-
if (!featureChoice || featureChoice !== "opticore_clean_module") {
|
|
3318
|
-
import_process2.default.exit(0);
|
|
3319
|
-
}
|
|
3320
|
-
UCustomFeatureInfo(featureChoice);
|
|
3321
|
-
const featureName = await _featureName();
|
|
3322
|
-
const directory = import_path9.default.join(import_process2.default.cwd(), "src", "features");
|
|
3323
|
-
const featureDirectory = import_path9.default.join(directory, featureName.toString());
|
|
3324
|
-
const featureCleanModule = BaseService._isSubdirectoryExists(featureName);
|
|
3325
|
-
if (featureCleanModule) {
|
|
3326
|
-
BaseService._featureFounded(featureName);
|
|
3327
|
-
}
|
|
3328
|
-
if ((0, import_prompts9.isCancel)(featureName)) {
|
|
3329
|
-
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);
|
|
3330
3016
|
} else {
|
|
3331
|
-
|
|
3332
|
-
if (import_node_fs2.default.existsSync(directory)) {
|
|
3333
|
-
await createComponentApplication(featureDirectory, featureName);
|
|
3334
|
-
} else {
|
|
3335
|
-
BaseService._checkFeatureDir();
|
|
3336
|
-
}
|
|
3337
|
-
} catch (err) {
|
|
3338
|
-
console.error(err.message);
|
|
3339
|
-
import_process2.default.exit();
|
|
3340
|
-
}
|
|
3017
|
+
BaseService._checkFeatureDir();
|
|
3341
3018
|
}
|
|
3342
|
-
}
|
|
3019
|
+
} catch (err) {
|
|
3020
|
+
console.error(err.message);
|
|
3021
|
+
import_process2.default.exit();
|
|
3022
|
+
}
|
|
3343
3023
|
}
|
|
3344
|
-
}
|
|
3024
|
+
}
|
|
3345
3025
|
|
|
3346
3026
|
// src/index.ts
|
|
3347
|
-
|
|
3348
|
-
Promise.resolve().then(() => init_core());
|
|
3027
|
+
runFeatureCommand();
|