@expressots/cli 1.7.1 → 1.8.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.
Files changed (72) hide show
  1. package/README.md +8 -0
  2. package/bin/@types/config.d.ts +39 -39
  3. package/bin/@types/config.js +2 -2
  4. package/bin/@types/index.d.ts +1 -1
  5. package/bin/@types/index.js +17 -17
  6. package/bin/app.container.d.ts +1 -1
  7. package/bin/app.container.js +8 -8
  8. package/bin/cli.d.ts +2 -2
  9. package/bin/cli.js +38 -38
  10. package/bin/commands/__tests__/project.commands.spec.d.ts +1 -0
  11. package/bin/commands/__tests__/project.commands.spec.js +8 -0
  12. package/bin/commands/project.commands.d.ts +8 -8
  13. package/bin/commands/project.commands.js +137 -136
  14. package/bin/generate/cli.d.ts +4 -4
  15. package/bin/generate/cli.js +66 -66
  16. package/bin/generate/form.d.ts +20 -20
  17. package/bin/generate/form.js +30 -30
  18. package/bin/generate/index.d.ts +1 -1
  19. package/bin/generate/index.js +17 -17
  20. package/bin/generate/utils/command-utils.d.ts +123 -123
  21. package/bin/generate/utils/command-utils.js +314 -310
  22. package/bin/generate/utils/nonopininated-cmd.d.ts +9 -9
  23. package/bin/generate/utils/nonopininated-cmd.js +248 -248
  24. package/bin/generate/utils/opinionated-cmd.d.ts +11 -11
  25. package/bin/generate/utils/opinionated-cmd.js +481 -480
  26. package/bin/help/cli.d.ts +4 -4
  27. package/bin/help/cli.js +15 -15
  28. package/bin/help/form.d.ts +2 -2
  29. package/bin/help/form.js +28 -28
  30. package/bin/help/index.d.ts +1 -1
  31. package/bin/help/index.js +17 -2
  32. package/bin/index.d.ts +6 -4
  33. package/bin/index.js +22 -20
  34. package/bin/info/cli.d.ts +4 -4
  35. package/bin/info/cli.js +15 -15
  36. package/bin/info/form.d.ts +2 -2
  37. package/bin/info/form.js +36 -36
  38. package/bin/info/index.d.ts +1 -1
  39. package/bin/info/index.js +17 -17
  40. package/bin/new/cli.d.ts +4 -4
  41. package/bin/new/cli.js +51 -51
  42. package/bin/new/form.d.ts +2 -2
  43. package/bin/new/form.js +235 -213
  44. package/bin/new/index.d.ts +1 -1
  45. package/bin/new/index.js +17 -17
  46. package/bin/providers/cli.d.ts +4 -4
  47. package/bin/providers/cli.js +43 -38
  48. package/bin/providers/external/external.provider.d.ts +2 -0
  49. package/bin/providers/external/external.provider.js +49 -0
  50. package/bin/providers/index.d.ts +1 -1
  51. package/bin/providers/index.js +17 -17
  52. package/bin/providers/prisma/prisma.provider.d.ts +2 -2
  53. package/bin/providers/prisma/prisma.provider.js +272 -270
  54. package/bin/types.d.ts +1 -1
  55. package/bin/types.js +17 -17
  56. package/bin/utils/add-controller-to-module.d.ts +1 -1
  57. package/bin/utils/add-controller-to-module.js +46 -46
  58. package/bin/utils/add-module-to-container.d.ts +3 -3
  59. package/bin/utils/add-module-to-container.js +129 -129
  60. package/bin/utils/center-text.d.ts +2 -2
  61. package/bin/utils/center-text.js +10 -10
  62. package/bin/utils/cli-ui.d.ts +3 -3
  63. package/bin/utils/cli-ui.js +19 -19
  64. package/bin/utils/compiler.d.ts +15 -15
  65. package/bin/utils/compiler.js +93 -93
  66. package/bin/utils/find-folder.d.ts +5 -5
  67. package/bin/utils/find-folder.js +37 -37
  68. package/bin/utils/index.d.ts +1 -1
  69. package/bin/utils/index.js +17 -17
  70. package/bin/utils/verify-file-exists.d.ts +2 -2
  71. package/bin/utils/verify-file-exists.js +30 -30
  72. package/package.json +31 -28
@@ -1,480 +1,481 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.opinionatedProcess = void 0;
30
- const boost_ts_1 = require("@expressots/boost-ts");
31
- const nodePath = __importStar(require("node:path"));
32
- const fs_1 = __importDefault(require("fs"));
33
- const cli_ui_1 = require("../../utils/cli-ui");
34
- const command_utils_1 = require("./command-utils");
35
- const add_controller_to_module_1 = require("../../utils/add-controller-to-module");
36
- const add_module_to_container_1 = require("../../utils/add-module-to-container");
37
- /**
38
- * Process commands for opinionated service scaffolding
39
- * @param schematic - Resource to scaffold
40
- * @param target - Target path
41
- * @param method - HTTP method
42
- * @param expressoConfig - Expresso configuration [expressots.config.ts]
43
- * @param pathStyle - Path command style [sugar, nested, single]
44
- * @returns
45
- */
46
- async function opinionatedProcess(schematic, target, method, expressoConfig, pathStyle) {
47
- const f = await (0, command_utils_1.validateAndPrepareFile)({
48
- schematic,
49
- target,
50
- method,
51
- expressoConfig,
52
- });
53
- switch (schematic) {
54
- case "service":
55
- await generateControllerService(f.outputPath, f.className, f.path, method, f.file);
56
- const u = await (0, command_utils_1.validateAndPrepareFile)({
57
- schematic: "usecase",
58
- target,
59
- method,
60
- expressoConfig,
61
- });
62
- await generateUseCaseService(u.outputPath, u.className, method, u.moduleName, u.path, u.fileName);
63
- const d = await (0, command_utils_1.validateAndPrepareFile)({
64
- schematic: "dto",
65
- target,
66
- method,
67
- expressoConfig,
68
- });
69
- await generateDTO(d.outputPath, d.className, d.moduleName, d.path);
70
- const m = await (0, command_utils_1.validateAndPrepareFile)({
71
- schematic: "module",
72
- target,
73
- method,
74
- expressoConfig,
75
- });
76
- if (pathStyle === "sugar" /* PathStyle.Sugar */) {
77
- await generateModuleServiceSugarPath(f.outputPath, m.className, m.moduleName, m.path, m.file, m.folderToScaffold);
78
- }
79
- else if (pathStyle === "nested" /* PathStyle.Nested */) {
80
- await generateModuleServiceNestedPath(f.outputPath, m.className, m.path, m.folderToScaffold);
81
- }
82
- else if (pathStyle === "single" /* PathStyle.Single */) {
83
- await generateModuleServiceSinglePath(f.outputPath, m.className, m.moduleName, m.path, m.file, m.folderToScaffold);
84
- }
85
- await (0, cli_ui_1.printGenerateSuccess)("controller", f.file);
86
- await (0, cli_ui_1.printGenerateSuccess)("usecase", f.file);
87
- await (0, cli_ui_1.printGenerateSuccess)("dto", f.file);
88
- await (0, cli_ui_1.printGenerateSuccess)("module", f.file);
89
- break;
90
- case "usecase":
91
- await generateUseCase(f.outputPath, f.className, f.moduleName, f.path, f.fileName);
92
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
93
- break;
94
- case "controller":
95
- await generateController(f.outputPath, f.className, f.path, method, f.file);
96
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
97
- break;
98
- case "dto":
99
- await generateDTO(f.outputPath, f.className, f.moduleName, f.path);
100
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
101
- break;
102
- case "provider":
103
- await generateProvider(f.outputPath, f.className, f.moduleName, f.path);
104
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
105
- break;
106
- case "entity":
107
- await generateEntity(f.outputPath, f.className, f.moduleName, f.path);
108
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
109
- break;
110
- case "middleware":
111
- await generateMiddleware(f.outputPath, f.className, f.moduleName, f.path);
112
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
113
- break;
114
- case "module":
115
- await generateModule(f.outputPath, f.className, f.moduleName, f.path);
116
- await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
117
- break;
118
- }
119
- return f.file;
120
- }
121
- exports.opinionatedProcess = opinionatedProcess;
122
- /* Generate Resource */
123
- /**
124
- * Generate a controller service
125
- * @param outputPath - The output path
126
- * @param className - The class name
127
- * @param moduleName - The module name
128
- * @param path - The path
129
- * @param method - The method
130
- * @param file - The file
131
- */
132
- async function generateControllerService(outputPath, className, path, method, file) {
133
- let templateBasedMethod = "";
134
- switch (method) {
135
- case "put":
136
- templateBasedMethod =
137
- "../templates/opinionated/controller-service-put.tpl";
138
- break;
139
- case "patch":
140
- templateBasedMethod =
141
- "../templates/opinionated/controller-service-patch.tpl";
142
- break;
143
- case "post":
144
- templateBasedMethod =
145
- "../templates/opinionated/controller-service-post.tpl";
146
- break;
147
- case "delete":
148
- templateBasedMethod =
149
- "../templates/opinionated/controller-service-delete.tpl";
150
- break;
151
- default:
152
- templateBasedMethod =
153
- "../templates/opinionated/controller-service-get.tpl";
154
- break;
155
- }
156
- (0, command_utils_1.writeTemplate)({
157
- outputPath,
158
- template: {
159
- path: templateBasedMethod,
160
- data: {
161
- className,
162
- fileName: (0, command_utils_1.getFileNameWithoutExtension)(file),
163
- useCase: (0, boost_ts_1.anyCaseToCamelCase)(className),
164
- route: path.replace(/\/$/, ""),
165
- construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
166
- method: (0, command_utils_1.getHttpMethod)(method),
167
- },
168
- },
169
- });
170
- }
171
- /**
172
- * Generate a use case
173
- * @param outputPath - The output path
174
- * @param className - The class name
175
- * @param moduleName - The module name
176
- * @param path - The path
177
- * @param template - The template
178
- */
179
- async function generateUseCaseService(outputPath, className, method, moduleName, path, fileName) {
180
- let templateBasedMethod = "";
181
- switch (method) {
182
- case "put":
183
- templateBasedMethod =
184
- "../templates/opinionated/usecase-service.tpl";
185
- break;
186
- case "patch":
187
- templateBasedMethod =
188
- "../templates/opinionated/usecase-service.tpl";
189
- break;
190
- case "post":
191
- templateBasedMethod =
192
- "../templates/opinionated/usecase-service.tpl";
193
- break;
194
- case "delete":
195
- templateBasedMethod =
196
- "../templates/opinionated/usecase-service-delete.tpl";
197
- break;
198
- default:
199
- templateBasedMethod = "../templates/opinionated/usecase.tpl";
200
- break;
201
- }
202
- (0, command_utils_1.writeTemplate)({
203
- outputPath,
204
- template: {
205
- path: templateBasedMethod,
206
- data: {
207
- className,
208
- moduleName,
209
- path,
210
- fileName,
211
- },
212
- },
213
- });
214
- }
215
- /**
216
- * Generate a use case
217
- * @param outputPath - The output path
218
- * @param className - The class name
219
- * @param moduleName - The module name
220
- * @param path - The path
221
- * @param fileName - The file name
222
- */
223
- async function generateUseCase(outputPath, className, moduleName, path, fileName) {
224
- (0, command_utils_1.writeTemplate)({
225
- outputPath,
226
- template: {
227
- path: "../templates/opinionated/usecase.tpl",
228
- data: {
229
- className,
230
- moduleName,
231
- path,
232
- fileName,
233
- },
234
- },
235
- });
236
- }
237
- /**
238
- * Generate a controller
239
- * @param outputPath - The output path
240
- * @param className - The class name
241
- * @param path - The path
242
- * @param method - The method
243
- * @param file - The file
244
- */
245
- async function generateController(outputPath, className, path, method, file) {
246
- const templateBasedMethod = "../templates/opinionated/controller-service.tpl";
247
- (0, command_utils_1.writeTemplate)({
248
- outputPath,
249
- template: {
250
- path: templateBasedMethod,
251
- data: {
252
- className,
253
- fileName: (0, command_utils_1.getFileNameWithoutExtension)(file),
254
- useCase: (0, boost_ts_1.anyCaseToCamelCase)(className),
255
- route: path.replace(/\/$/, ""),
256
- construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
257
- method: (0, command_utils_1.getHttpMethod)(method),
258
- },
259
- },
260
- });
261
- }
262
- /**
263
- * Generate a DTO
264
- * @param outputPath - The output path
265
- * @param className - The class name
266
- * @param moduleName - The module name
267
- * @param path - The path
268
- */
269
- async function generateDTO(outputPath, className, moduleName, path) {
270
- (0, command_utils_1.writeTemplate)({
271
- outputPath,
272
- template: {
273
- path: "../templates/opinionated/dto.tpl",
274
- data: {
275
- className,
276
- moduleName,
277
- path,
278
- },
279
- },
280
- });
281
- }
282
- /**
283
- * Generate a provider
284
- * @param outputPath - The output path
285
- * @param className - The class name
286
- * @param moduleName - The module name
287
- * @param path - The path
288
- */
289
- async function generateProvider(outputPath, className, moduleName, path) {
290
- (0, command_utils_1.writeTemplate)({
291
- outputPath,
292
- template: {
293
- path: "../templates/opinionated/provider.tpl",
294
- data: {
295
- className,
296
- moduleName,
297
- path,
298
- },
299
- },
300
- });
301
- }
302
- /**
303
- * Generate an entity
304
- * @param outputPath - The output path
305
- * @param className - The class name
306
- * @param moduleName - The module name
307
- * @param path - The path
308
- */
309
- async function generateEntity(outputPath, className, moduleName, path) {
310
- (0, command_utils_1.writeTemplate)({
311
- outputPath,
312
- template: {
313
- path: "../templates/opinionated/entity.tpl",
314
- data: {
315
- className,
316
- moduleName,
317
- path,
318
- },
319
- },
320
- });
321
- }
322
- /**
323
- * Generate a middleware
324
- * @param outputPath - The output path
325
- * @param className - The class name
326
- * @param moduleName - The module name
327
- * @param path - The path
328
- */
329
- async function generateMiddleware(outputPath, className, moduleName, path) {
330
- (0, command_utils_1.writeTemplate)({
331
- outputPath,
332
- template: {
333
- path: "../templates/opinionated/middleware.tpl",
334
- data: {
335
- className,
336
- moduleName,
337
- path,
338
- },
339
- },
340
- });
341
- }
342
- /**
343
- * Generate a module for service scaffolding with sugar path
344
- * @param outputPath - The output path
345
- * @param className - The class name
346
- * @param moduleName - The module name
347
- * @param path - The path
348
- */
349
- async function generateModuleServiceSugarPath(outputPathController, className, moduleName, path, file, folderToScaffold) {
350
- const newModuleFile = await (0, command_utils_1.extractFirstWord)(file);
351
- const newModulePath = nodePath
352
- .join(folderToScaffold, path, "..")
353
- .normalize();
354
- const newModuleName = `${newModuleFile}.module.ts`;
355
- const newModuleOutputPath = `${newModulePath}/${newModuleName}`.replace("\\", "/");
356
- const controllerToModule = nodePath
357
- .relative(newModuleOutputPath, outputPathController)
358
- .normalize()
359
- .replace(/\.ts$/, "")
360
- .replace(/\\/g, "/")
361
- .replace(/\.\./g, ".");
362
- const controllerFullPath = nodePath
363
- .join(folderToScaffold, path, "..", newModuleName)
364
- .normalize();
365
- if (fs_1.default.existsSync(newModuleOutputPath)) {
366
- await (0, add_controller_to_module_1.addControllerToModule)(controllerFullPath, `${className}Controller`, controllerToModule);
367
- return;
368
- }
369
- (0, command_utils_1.writeTemplate)({
370
- outputPath: newModuleOutputPath,
371
- template: {
372
- path: "../templates/opinionated/module-service.tpl",
373
- data: {
374
- className,
375
- moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleName),
376
- path: controllerToModule,
377
- },
378
- },
379
- });
380
- await (0, add_module_to_container_1.addModuleToContainer)((0, boost_ts_1.anyCaseToPascalCase)(moduleName), `${moduleName}/${file.replace(".ts", "")}`, path);
381
- }
382
- /**
383
- * Generate a module for service scaffolding with single path
384
- * @param outputPath - The output path
385
- * @param className - The class name
386
- * @param moduleName - The module name
387
- * @param path - The path
388
- */
389
- async function generateModuleServiceSinglePath(outputPathController, className, moduleName, path, file, folderToScaffold) {
390
- const newModuleFile = await (0, command_utils_1.extractFirstWord)(file);
391
- const newModulePath = nodePath.join(folderToScaffold, path).normalize();
392
- const newModuleName = `${newModuleFile}.module.ts`;
393
- const newModuleOutputPath = `${newModulePath}/${newModuleName}`.replace("\\", "/");
394
- const controllerToModule = nodePath
395
- .relative(newModuleOutputPath, outputPathController)
396
- .normalize()
397
- .replace(/\.ts$/, "")
398
- .replace(/\\/g, "/")
399
- .replace(/\.\./g, ".");
400
- const controllerFullPath = nodePath
401
- .join(folderToScaffold, path, "..", newModuleName)
402
- .normalize();
403
- if (fs_1.default.existsSync(newModuleOutputPath)) {
404
- await (0, add_controller_to_module_1.addControllerToModule)(controllerFullPath, `${className}Controller`, controllerToModule);
405
- return;
406
- }
407
- (0, command_utils_1.writeTemplate)({
408
- outputPath: newModuleOutputPath,
409
- template: {
410
- path: "../templates/opinionated/module-service.tpl",
411
- data: {
412
- className,
413
- moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleName),
414
- path: controllerToModule,
415
- },
416
- },
417
- });
418
- await (0, add_module_to_container_1.addModuleToContainer)((0, boost_ts_1.anyCaseToPascalCase)(moduleName), `${moduleName}/${file.replace(".ts", "")}`, path);
419
- }
420
- /**
421
- * Generate a module for service scaffolding with nested path
422
- * @param outputPathController
423
- * @param className
424
- * @param path
425
- * @param folderToScaffold
426
- * @returns
427
- */
428
- async function generateModuleServiceNestedPath(outputPathController, className, path, folderToScaffold) {
429
- const moduleFileName = nodePath.basename(path, "/");
430
- const newModulePath = nodePath
431
- .join(folderToScaffold, path, "..")
432
- .normalize();
433
- const newModuleName = `${moduleFileName}.module.ts`;
434
- const newModuleOutputPath = `${newModulePath}/${newModuleName}`.replace("\\", "/");
435
- const controllerToModule = nodePath
436
- .relative(newModuleOutputPath, outputPathController)
437
- .normalize()
438
- .replace(/\.ts$/, "")
439
- .replace(/\\/g, "/")
440
- .replace(/\.\./g, ".");
441
- const controllerFullPath = nodePath
442
- .join(folderToScaffold, path, "..", newModuleName)
443
- .normalize();
444
- if (fs_1.default.existsSync(newModuleOutputPath)) {
445
- await (0, add_controller_to_module_1.addControllerToModule)(controllerFullPath, `${className}Controller`, controllerToModule);
446
- return;
447
- }
448
- (0, command_utils_1.writeTemplate)({
449
- outputPath: newModuleOutputPath,
450
- template: {
451
- path: "../templates/opinionated/module-service.tpl",
452
- data: {
453
- className,
454
- moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleFileName),
455
- path: controllerToModule,
456
- },
457
- },
458
- });
459
- await (0, add_module_to_container_1.addModuleToContainerNestedPath)((0, boost_ts_1.anyCaseToPascalCase)(moduleFileName), path);
460
- }
461
- /**
462
- * Generate a module
463
- * @param outputPath - The output path
464
- * @param className - The class name
465
- * @param moduleName - The module name
466
- * @param path - The path
467
- */
468
- async function generateModule(outputPath, className, moduleName, path) {
469
- (0, command_utils_1.writeTemplate)({
470
- outputPath,
471
- template: {
472
- path: "../templates/opinionated/module.tpl",
473
- data: {
474
- className,
475
- moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleName),
476
- path,
477
- },
478
- },
479
- });
480
- }
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.opinionatedProcess = void 0;
30
+ const boost_ts_1 = require("@expressots/boost-ts");
31
+ const nodePath = __importStar(require("node:path"));
32
+ const fs_1 = __importDefault(require("fs"));
33
+ const cli_ui_1 = require("../../utils/cli-ui");
34
+ const command_utils_1 = require("./command-utils");
35
+ const add_controller_to_module_1 = require("../../utils/add-controller-to-module");
36
+ const add_module_to_container_1 = require("../../utils/add-module-to-container");
37
+ /**
38
+ * Process commands for opinionated service scaffolding
39
+ * @param schematic - Resource to scaffold
40
+ * @param target - Target path
41
+ * @param method - HTTP method
42
+ * @param expressoConfig - Expresso configuration [expressots.config.ts]
43
+ * @param pathStyle - Path command style [sugar, nested, single]
44
+ * @returns
45
+ */
46
+ async function opinionatedProcess(schematic, target, method, expressoConfig, pathStyle) {
47
+ const f = await (0, command_utils_1.validateAndPrepareFile)({
48
+ schematic,
49
+ target,
50
+ method,
51
+ expressoConfig,
52
+ });
53
+ switch (schematic) {
54
+ case "service": {
55
+ await generateControllerService(f.outputPath, f.className, f.path, method, f.file);
56
+ const u = await (0, command_utils_1.validateAndPrepareFile)({
57
+ schematic: "usecase",
58
+ target,
59
+ method,
60
+ expressoConfig,
61
+ });
62
+ await generateUseCaseService(u.outputPath, u.className, method, u.moduleName, u.path, u.fileName);
63
+ const d = await (0, command_utils_1.validateAndPrepareFile)({
64
+ schematic: "dto",
65
+ target,
66
+ method,
67
+ expressoConfig,
68
+ });
69
+ await generateDTO(d.outputPath, d.className, d.moduleName, d.path);
70
+ const m = await (0, command_utils_1.validateAndPrepareFile)({
71
+ schematic: "module",
72
+ target,
73
+ method,
74
+ expressoConfig,
75
+ });
76
+ if (pathStyle === "sugar" /* PathStyle.Sugar */) {
77
+ await generateModuleServiceSugarPath(f.outputPath, m.className, m.moduleName, m.path, m.file, m.folderToScaffold);
78
+ }
79
+ else if (pathStyle === "nested" /* PathStyle.Nested */) {
80
+ await generateModuleServiceNestedPath(f.outputPath, m.className, m.path, m.folderToScaffold);
81
+ }
82
+ else if (pathStyle === "single" /* PathStyle.Single */) {
83
+ await generateModuleServiceSinglePath(f.outputPath, m.className, m.moduleName, m.path, m.file, m.folderToScaffold);
84
+ }
85
+ await (0, cli_ui_1.printGenerateSuccess)("controller", f.file);
86
+ await (0, cli_ui_1.printGenerateSuccess)("usecase", f.file);
87
+ await (0, cli_ui_1.printGenerateSuccess)("dto", f.file);
88
+ await (0, cli_ui_1.printGenerateSuccess)("module", f.file);
89
+ break;
90
+ }
91
+ case "usecase":
92
+ await generateUseCase(f.outputPath, f.className, f.moduleName, f.path, f.fileName);
93
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
94
+ break;
95
+ case "controller":
96
+ await generateController(f.outputPath, f.className, f.path, method, f.file);
97
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
98
+ break;
99
+ case "dto":
100
+ await generateDTO(f.outputPath, f.className, f.moduleName, f.path);
101
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
102
+ break;
103
+ case "provider":
104
+ await generateProvider(f.outputPath, f.className, f.moduleName, f.path);
105
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
106
+ break;
107
+ case "entity":
108
+ await generateEntity(f.outputPath, f.className, f.moduleName, f.path);
109
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
110
+ break;
111
+ case "middleware":
112
+ await generateMiddleware(f.outputPath, f.className, f.moduleName, f.path);
113
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
114
+ break;
115
+ case "module":
116
+ await generateModule(f.outputPath, f.className, f.moduleName, f.path);
117
+ await (0, cli_ui_1.printGenerateSuccess)(schematic, f.file);
118
+ break;
119
+ }
120
+ return f.file;
121
+ }
122
+ exports.opinionatedProcess = opinionatedProcess;
123
+ /* Generate Resource */
124
+ /**
125
+ * Generate a controller service
126
+ * @param outputPath - The output path
127
+ * @param className - The class name
128
+ * @param moduleName - The module name
129
+ * @param path - The path
130
+ * @param method - The method
131
+ * @param file - The file
132
+ */
133
+ async function generateControllerService(outputPath, className, path, method, file) {
134
+ let templateBasedMethod = "";
135
+ switch (method) {
136
+ case "put":
137
+ templateBasedMethod =
138
+ "../templates/opinionated/controller-service-put.tpl";
139
+ break;
140
+ case "patch":
141
+ templateBasedMethod =
142
+ "../templates/opinionated/controller-service-patch.tpl";
143
+ break;
144
+ case "post":
145
+ templateBasedMethod =
146
+ "../templates/opinionated/controller-service-post.tpl";
147
+ break;
148
+ case "delete":
149
+ templateBasedMethod =
150
+ "../templates/opinionated/controller-service-delete.tpl";
151
+ break;
152
+ default:
153
+ templateBasedMethod =
154
+ "../templates/opinionated/controller-service-get.tpl";
155
+ break;
156
+ }
157
+ (0, command_utils_1.writeTemplate)({
158
+ outputPath,
159
+ template: {
160
+ path: templateBasedMethod,
161
+ data: {
162
+ className,
163
+ fileName: (0, command_utils_1.getFileNameWithoutExtension)(file),
164
+ useCase: (0, boost_ts_1.anyCaseToCamelCase)(className),
165
+ route: path.replace(/\/$/, ""),
166
+ construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
167
+ method: (0, command_utils_1.getHttpMethod)(method),
168
+ },
169
+ },
170
+ });
171
+ }
172
+ /**
173
+ * Generate a use case
174
+ * @param outputPath - The output path
175
+ * @param className - The class name
176
+ * @param moduleName - The module name
177
+ * @param path - The path
178
+ * @param template - The template
179
+ */
180
+ async function generateUseCaseService(outputPath, className, method, moduleName, path, fileName) {
181
+ let templateBasedMethod = "";
182
+ switch (method) {
183
+ case "put":
184
+ templateBasedMethod =
185
+ "../templates/opinionated/usecase-service.tpl";
186
+ break;
187
+ case "patch":
188
+ templateBasedMethod =
189
+ "../templates/opinionated/usecase-service.tpl";
190
+ break;
191
+ case "post":
192
+ templateBasedMethod =
193
+ "../templates/opinionated/usecase-service.tpl";
194
+ break;
195
+ case "delete":
196
+ templateBasedMethod =
197
+ "../templates/opinionated/usecase-service-delete.tpl";
198
+ break;
199
+ default:
200
+ templateBasedMethod = "../templates/opinionated/usecase.tpl";
201
+ break;
202
+ }
203
+ (0, command_utils_1.writeTemplate)({
204
+ outputPath,
205
+ template: {
206
+ path: templateBasedMethod,
207
+ data: {
208
+ className,
209
+ moduleName,
210
+ path,
211
+ fileName,
212
+ },
213
+ },
214
+ });
215
+ }
216
+ /**
217
+ * Generate a use case
218
+ * @param outputPath - The output path
219
+ * @param className - The class name
220
+ * @param moduleName - The module name
221
+ * @param path - The path
222
+ * @param fileName - The file name
223
+ */
224
+ async function generateUseCase(outputPath, className, moduleName, path, fileName) {
225
+ (0, command_utils_1.writeTemplate)({
226
+ outputPath,
227
+ template: {
228
+ path: "../templates/opinionated/usecase.tpl",
229
+ data: {
230
+ className,
231
+ moduleName,
232
+ path,
233
+ fileName,
234
+ },
235
+ },
236
+ });
237
+ }
238
+ /**
239
+ * Generate a controller
240
+ * @param outputPath - The output path
241
+ * @param className - The class name
242
+ * @param path - The path
243
+ * @param method - The method
244
+ * @param file - The file
245
+ */
246
+ async function generateController(outputPath, className, path, method, file) {
247
+ const templateBasedMethod = "../templates/opinionated/controller-service.tpl";
248
+ (0, command_utils_1.writeTemplate)({
249
+ outputPath,
250
+ template: {
251
+ path: templateBasedMethod,
252
+ data: {
253
+ className,
254
+ fileName: (0, command_utils_1.getFileNameWithoutExtension)(file),
255
+ useCase: (0, boost_ts_1.anyCaseToCamelCase)(className),
256
+ route: path.replace(/\/$/, ""),
257
+ construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
258
+ method: (0, command_utils_1.getHttpMethod)(method),
259
+ },
260
+ },
261
+ });
262
+ }
263
+ /**
264
+ * Generate a DTO
265
+ * @param outputPath - The output path
266
+ * @param className - The class name
267
+ * @param moduleName - The module name
268
+ * @param path - The path
269
+ */
270
+ async function generateDTO(outputPath, className, moduleName, path) {
271
+ (0, command_utils_1.writeTemplate)({
272
+ outputPath,
273
+ template: {
274
+ path: "../templates/opinionated/dto.tpl",
275
+ data: {
276
+ className,
277
+ moduleName,
278
+ path,
279
+ },
280
+ },
281
+ });
282
+ }
283
+ /**
284
+ * Generate a provider
285
+ * @param outputPath - The output path
286
+ * @param className - The class name
287
+ * @param moduleName - The module name
288
+ * @param path - The path
289
+ */
290
+ async function generateProvider(outputPath, className, moduleName, path) {
291
+ (0, command_utils_1.writeTemplate)({
292
+ outputPath,
293
+ template: {
294
+ path: "../templates/opinionated/provider.tpl",
295
+ data: {
296
+ className,
297
+ moduleName,
298
+ path,
299
+ },
300
+ },
301
+ });
302
+ }
303
+ /**
304
+ * Generate an entity
305
+ * @param outputPath - The output path
306
+ * @param className - The class name
307
+ * @param moduleName - The module name
308
+ * @param path - The path
309
+ */
310
+ async function generateEntity(outputPath, className, moduleName, path) {
311
+ (0, command_utils_1.writeTemplate)({
312
+ outputPath,
313
+ template: {
314
+ path: "../templates/opinionated/entity.tpl",
315
+ data: {
316
+ className,
317
+ moduleName,
318
+ path,
319
+ },
320
+ },
321
+ });
322
+ }
323
+ /**
324
+ * Generate a middleware
325
+ * @param outputPath - The output path
326
+ * @param className - The class name
327
+ * @param moduleName - The module name
328
+ * @param path - The path
329
+ */
330
+ async function generateMiddleware(outputPath, className, moduleName, path) {
331
+ (0, command_utils_1.writeTemplate)({
332
+ outputPath,
333
+ template: {
334
+ path: "../templates/opinionated/middleware.tpl",
335
+ data: {
336
+ className,
337
+ moduleName,
338
+ path,
339
+ },
340
+ },
341
+ });
342
+ }
343
+ /**
344
+ * Generate a module for service scaffolding with sugar path
345
+ * @param outputPath - The output path
346
+ * @param className - The class name
347
+ * @param moduleName - The module name
348
+ * @param path - The path
349
+ */
350
+ async function generateModuleServiceSugarPath(outputPathController, className, moduleName, path, file, folderToScaffold) {
351
+ const newModuleFile = await (0, command_utils_1.extractFirstWord)(file);
352
+ const newModulePath = nodePath
353
+ .join(folderToScaffold, path, "..")
354
+ .normalize();
355
+ const newModuleName = `${newModuleFile}.module.ts`;
356
+ const newModuleOutputPath = `${newModulePath}/${newModuleName}`.replace("\\", "/");
357
+ const controllerToModule = nodePath
358
+ .relative(newModuleOutputPath, outputPathController)
359
+ .normalize()
360
+ .replace(/\.ts$/, "")
361
+ .replace(/\\/g, "/")
362
+ .replace(/\.\./g, ".");
363
+ const controllerFullPath = nodePath
364
+ .join(folderToScaffold, path, "..", newModuleName)
365
+ .normalize();
366
+ if (fs_1.default.existsSync(newModuleOutputPath)) {
367
+ await (0, add_controller_to_module_1.addControllerToModule)(controllerFullPath, `${className}Controller`, controllerToModule);
368
+ return;
369
+ }
370
+ (0, command_utils_1.writeTemplate)({
371
+ outputPath: newModuleOutputPath,
372
+ template: {
373
+ path: "../templates/opinionated/module-service.tpl",
374
+ data: {
375
+ className,
376
+ moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleName),
377
+ path: controllerToModule,
378
+ },
379
+ },
380
+ });
381
+ await (0, add_module_to_container_1.addModuleToContainer)((0, boost_ts_1.anyCaseToPascalCase)(moduleName), `${moduleName}/${file.replace(".ts", "")}`, path);
382
+ }
383
+ /**
384
+ * Generate a module for service scaffolding with single path
385
+ * @param outputPath - The output path
386
+ * @param className - The class name
387
+ * @param moduleName - The module name
388
+ * @param path - The path
389
+ */
390
+ async function generateModuleServiceSinglePath(outputPathController, className, moduleName, path, file, folderToScaffold) {
391
+ const newModuleFile = await (0, command_utils_1.extractFirstWord)(file);
392
+ const newModulePath = nodePath.join(folderToScaffold, path).normalize();
393
+ const newModuleName = `${newModuleFile}.module.ts`;
394
+ const newModuleOutputPath = `${newModulePath}/${newModuleName}`.replace("\\", "/");
395
+ const controllerToModule = nodePath
396
+ .relative(newModuleOutputPath, outputPathController)
397
+ .normalize()
398
+ .replace(/\.ts$/, "")
399
+ .replace(/\\/g, "/")
400
+ .replace(/\.\./g, ".");
401
+ const controllerFullPath = nodePath
402
+ .join(folderToScaffold, path, "..", newModuleName)
403
+ .normalize();
404
+ if (fs_1.default.existsSync(newModuleOutputPath)) {
405
+ await (0, add_controller_to_module_1.addControllerToModule)(controllerFullPath, `${className}Controller`, controllerToModule);
406
+ return;
407
+ }
408
+ (0, command_utils_1.writeTemplate)({
409
+ outputPath: newModuleOutputPath,
410
+ template: {
411
+ path: "../templates/opinionated/module-service.tpl",
412
+ data: {
413
+ className,
414
+ moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleName),
415
+ path: controllerToModule,
416
+ },
417
+ },
418
+ });
419
+ await (0, add_module_to_container_1.addModuleToContainer)((0, boost_ts_1.anyCaseToPascalCase)(moduleName), `${moduleName}/${file.replace(".ts", "")}`, path);
420
+ }
421
+ /**
422
+ * Generate a module for service scaffolding with nested path
423
+ * @param outputPathController
424
+ * @param className
425
+ * @param path
426
+ * @param folderToScaffold
427
+ * @returns
428
+ */
429
+ async function generateModuleServiceNestedPath(outputPathController, className, path, folderToScaffold) {
430
+ const moduleFileName = nodePath.basename(path, "/");
431
+ const newModulePath = nodePath
432
+ .join(folderToScaffold, path, "..")
433
+ .normalize();
434
+ const newModuleName = `${moduleFileName}.module.ts`;
435
+ const newModuleOutputPath = `${newModulePath}/${newModuleName}`.replace("\\", "/");
436
+ const controllerToModule = nodePath
437
+ .relative(newModuleOutputPath, outputPathController)
438
+ .normalize()
439
+ .replace(/\.ts$/, "")
440
+ .replace(/\\/g, "/")
441
+ .replace(/\.\./g, ".");
442
+ const controllerFullPath = nodePath
443
+ .join(folderToScaffold, path, "..", newModuleName)
444
+ .normalize();
445
+ if (fs_1.default.existsSync(newModuleOutputPath)) {
446
+ await (0, add_controller_to_module_1.addControllerToModule)(controllerFullPath, `${className}Controller`, controllerToModule);
447
+ return;
448
+ }
449
+ (0, command_utils_1.writeTemplate)({
450
+ outputPath: newModuleOutputPath,
451
+ template: {
452
+ path: "../templates/opinionated/module-service.tpl",
453
+ data: {
454
+ className,
455
+ moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleFileName),
456
+ path: controllerToModule,
457
+ },
458
+ },
459
+ });
460
+ await (0, add_module_to_container_1.addModuleToContainerNestedPath)((0, boost_ts_1.anyCaseToPascalCase)(moduleFileName), path);
461
+ }
462
+ /**
463
+ * Generate a module
464
+ * @param outputPath - The output path
465
+ * @param className - The class name
466
+ * @param moduleName - The module name
467
+ * @param path - The path
468
+ */
469
+ async function generateModule(outputPath, className, moduleName, path) {
470
+ (0, command_utils_1.writeTemplate)({
471
+ outputPath,
472
+ template: {
473
+ path: "../templates/opinionated/module.tpl",
474
+ data: {
475
+ className,
476
+ moduleName: (0, boost_ts_1.anyCaseToPascalCase)(moduleName),
477
+ path,
478
+ },
479
+ },
480
+ });
481
+ }