@expressots/cli 1.7.1 → 1.8.1

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 +65 -51
  42. package/bin/new/form.d.ts +2 -2
  43. package/bin/new/form.js +238 -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 +35 -31
@@ -1,310 +1,314 @@
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.checkPathStyle = exports.extractFirstWord = exports.getNameWithScaffoldPattern = exports.schematicFolder = exports.writeTemplate = exports.getHttpMethod = exports.splitTarget = exports.getFileNameWithoutExtension = exports.validateAndPrepareFile = void 0;
30
- const node_fs_1 = require("node:fs");
31
- const nodePath = __importStar(require("node:path"));
32
- const mustache_1 = require("mustache");
33
- const boost_ts_1 = require("@expressots/boost-ts");
34
- const cli_ui_1 = require("../../utils/cli-ui");
35
- const verify_file_exists_1 = require("../../utils/verify-file-exists");
36
- const compiler_1 = __importDefault(require("../../utils/compiler"));
37
- /**
38
- * Create a template based on the schematic
39
- * @param fp
40
- * @returns the file created
41
- */
42
- async function validateAndPrepareFile(fp) {
43
- const { sourceRoot, scaffoldSchematics, opinionated } = fp.expressoConfig;
44
- if (sourceRoot === "") {
45
- (0, cli_ui_1.printError)("You must specify a source root in your expressots.config.ts", "sourceRoot");
46
- process.exit(1);
47
- }
48
- if (opinionated) {
49
- const folderSchematic = (0, exports.schematicFolder)(fp.schematic);
50
- const folderToScaffold = `${sourceRoot}/${folderSchematic}`;
51
- const { path, file, className, moduleName, modulePath } = await (0, exports.splitTarget)({
52
- target: fp.target,
53
- schematic: fp.schematic,
54
- });
55
- const outputPath = `${folderToScaffold}/${path}/${file}`;
56
- await (0, verify_file_exists_1.verifyIfFileExists)(outputPath, fp.schematic);
57
- (0, node_fs_1.mkdirSync)(`${folderToScaffold}/${path}`, { recursive: true });
58
- return {
59
- path,
60
- file,
61
- className,
62
- moduleName,
63
- modulePath,
64
- outputPath,
65
- folderToScaffold,
66
- fileName: getFileNameWithoutExtension(file),
67
- schematic: fp.schematic,
68
- };
69
- }
70
- const folderSchematic = "";
71
- const folderToScaffold = `${sourceRoot}/${folderSchematic}`;
72
- const { path, file, className, moduleName, modulePath } = await (0, exports.splitTarget)({
73
- target: fp.target,
74
- schematic: fp.schematic,
75
- });
76
- const fileBaseSchema = scaffoldSchematics === null || scaffoldSchematics === void 0 ? void 0 : scaffoldSchematics[fp.schematic];
77
- const validateFileSchema = fileBaseSchema !== undefined
78
- ? file.replace(fp.schematic, fileBaseSchema)
79
- : file;
80
- const outputPath = `${folderToScaffold}/${path}/${validateFileSchema}`;
81
- await (0, verify_file_exists_1.verifyIfFileExists)(outputPath, fp.schematic);
82
- (0, node_fs_1.mkdirSync)(`${folderToScaffold}/${path}`, { recursive: true });
83
- return {
84
- path,
85
- file,
86
- className,
87
- moduleName,
88
- modulePath,
89
- outputPath,
90
- folderToScaffold,
91
- fileName: getFileNameWithoutExtension(file),
92
- schematic: fileBaseSchema !== undefined ? fileBaseSchema : fp.schematic,
93
- };
94
- }
95
- exports.validateAndPrepareFile = validateAndPrepareFile;
96
- /**
97
- * Get the file name without the extension
98
- * @param filePath
99
- * @returns the file name
100
- */
101
- function getFileNameWithoutExtension(filePath) {
102
- return filePath.split(".")[0];
103
- }
104
- exports.getFileNameWithoutExtension = getFileNameWithoutExtension;
105
- /**
106
- * Split the target into path, file, class name, module name and module path
107
- * @param target
108
- * @param schematic
109
- * @returns the split target
110
- */
111
- const splitTarget = async ({ target, schematic, }) => {
112
- const pathContent = target
113
- .split("/")
114
- .filter((item) => item !== "");
115
- const endsWithSlash = target.endsWith("/");
116
- let path = "";
117
- let fileName = "";
118
- let module = "";
119
- let modulePath = "";
120
- if (target.includes("/") ||
121
- target.includes("\\") ||
122
- target.includes("//")) {
123
- if (schematic === "service")
124
- schematic = "controller";
125
- if (schematic === "service" ||
126
- (schematic === "controller" && pathContent.length > 4)) {
127
- (0, cli_ui_1.printError)("Max path depth is 4.", pathContent.join("/"));
128
- process.exit(1);
129
- }
130
- if (endsWithSlash) {
131
- fileName = pathContent[pathContent.length - 1];
132
- path = pathContent.join("/");
133
- module =
134
- pathContent.length == 1
135
- ? pathContent[pathContent.length - 1]
136
- : pathContent[pathContent.length - 2];
137
- modulePath = pathContent.slice(0, -1).join("/");
138
- }
139
- else {
140
- fileName = pathContent[pathContent.length - 1];
141
- path = pathContent.slice(0, -1).join("/");
142
- module =
143
- pathContent.length == 2
144
- ? pathContent[pathContent.length - 2]
145
- : pathContent[pathContent.length - 3];
146
- modulePath = pathContent.slice(0, -2).join("/");
147
- }
148
- return {
149
- path,
150
- file: `${await (0, exports.getNameWithScaffoldPattern)(fileName)}.${schematic}.ts`,
151
- className: (0, boost_ts_1.anyCaseToPascalCase)(fileName),
152
- moduleName: module,
153
- modulePath,
154
- };
155
- }
156
- else {
157
- if (schematic === "service")
158
- schematic = "controller";
159
- // 1. Extract the name (first part of the target)
160
- const [name, ...remainingPath] = target.split("/");
161
- // 2. Check if the name is camelCase or kebab-case
162
- const camelCaseRegex = /[A-Z]/;
163
- const kebabCaseRegex = /[_\-\s]+/;
164
- const isCamelCase = camelCaseRegex.test(name);
165
- const isKebabCase = kebabCaseRegex.test(name);
166
- if (isCamelCase || isKebabCase) {
167
- const [wordName, ...path] = name === null || name === void 0 ? void 0 : name.split(isCamelCase ? /(?=[A-Z])/ : kebabCaseRegex).map((word) => word.toLowerCase());
168
- return {
169
- path: `${wordName}/${pathEdgeCase(path)}${pathEdgeCase(remainingPath)}`,
170
- file: `${await (0, exports.getNameWithScaffoldPattern)(name)}.${schematic}.ts`,
171
- className: (0, boost_ts_1.anyCaseToPascalCase)(name),
172
- moduleName: wordName,
173
- modulePath: pathContent[0].split("-")[1],
174
- };
175
- }
176
- // 3. Return the base case
177
- return {
178
- path: "",
179
- file: `${await (0, exports.getNameWithScaffoldPattern)(name)}.${schematic}.ts`,
180
- className: (0, boost_ts_1.anyCaseToPascalCase)(name),
181
- moduleName: name,
182
- modulePath: "",
183
- };
184
- }
185
- };
186
- exports.splitTarget = splitTarget;
187
- /**
188
- * Write the template based on the http method
189
- * @param method - the http method
190
- * @returns decorator - the decorator to be used
191
- */
192
- const getHttpMethod = (method) => {
193
- switch (method) {
194
- case "put":
195
- return "Put";
196
- case "post":
197
- return "Post";
198
- case "patch":
199
- return "Patch";
200
- case "delete":
201
- return "Delete";
202
- default:
203
- return "Get";
204
- }
205
- };
206
- exports.getHttpMethod = getHttpMethod;
207
- /**
208
- * Write the template based on the schematics
209
- * @param outputPath - the output path
210
- * @param template - the template to be used
211
- * @returns void
212
- */
213
- const writeTemplate = ({ outputPath, template: { path, data }, }) => {
214
- (0, node_fs_1.writeFileSync)(outputPath, (0, mustache_1.render)((0, node_fs_1.readFileSync)(nodePath.join(__dirname, path), "utf8"), data));
215
- };
216
- exports.writeTemplate = writeTemplate;
217
- /**
218
- * Returns the folder where the schematic should be placed
219
- * @param schematic
220
- */
221
- const schematicFolder = (schematic) => {
222
- switch (schematic) {
223
- case "usecase":
224
- return "useCases";
225
- case "controller":
226
- return "useCases";
227
- case "dto":
228
- return "useCases";
229
- case "service":
230
- return "useCases";
231
- case "provider":
232
- return "providers";
233
- case "entity":
234
- return "entities";
235
- case "middleware":
236
- return "providers/middlewares";
237
- case "module":
238
- return "useCases";
239
- }
240
- return undefined;
241
- };
242
- exports.schematicFolder = schematicFolder;
243
- /**
244
- * Get the name with the scaffold pattern
245
- * @param name
246
- * @returns the name in the scaffold pattern
247
- */
248
- const getNameWithScaffoldPattern = async (name) => {
249
- const configObject = await compiler_1.default.loadConfig();
250
- switch (configObject.scaffoldPattern) {
251
- case "lowercase" /* Pattern.LOWER_CASE */:
252
- return (0, boost_ts_1.anyCaseToLowerCase)(name);
253
- case "kebab-case" /* Pattern.KEBAB_CASE */:
254
- return (0, boost_ts_1.anyCaseToKebabCase)(name);
255
- case "PascalCase" /* Pattern.PASCAL_CASE */:
256
- return (0, boost_ts_1.anyCaseToPascalCase)(name);
257
- case "camelCase" /* Pattern.CAMEL_CASE */:
258
- return (0, boost_ts_1.anyCaseToCamelCase)(name);
259
- }
260
- };
261
- exports.getNameWithScaffoldPattern = getNameWithScaffoldPattern;
262
- /**
263
- * Get the path edge case
264
- * @param path
265
- * @returns the path edge case from the last element of the path
266
- */
267
- const pathEdgeCase = (path) => {
268
- return `${path.join("/")}${path.length > 0 ? "/" : ""}`;
269
- };
270
- /**
271
- * Extract the first word from a file and convert it to the scaffold pattern
272
- * @param file
273
- * @returns the first word in the scaffold pattern
274
- */
275
- async function extractFirstWord(file) {
276
- const f = file.split(".")[0];
277
- const regex = /(?:-|(?<=[a-z])(?=[A-Z]))/;
278
- const firstWord = f.split(regex)[0];
279
- const config = await compiler_1.default.loadConfig();
280
- switch (config.scaffoldPattern) {
281
- case "lowercase" /* Pattern.LOWER_CASE */:
282
- return (0, boost_ts_1.anyCaseToLowerCase)(firstWord);
283
- case "kebab-case" /* Pattern.KEBAB_CASE */:
284
- return (0, boost_ts_1.anyCaseToKebabCase)(firstWord);
285
- case "PascalCase" /* Pattern.PASCAL_CASE */:
286
- return (0, boost_ts_1.anyCaseToPascalCase)(firstWord);
287
- case "camelCase" /* Pattern.CAMEL_CASE */:
288
- return (0, boost_ts_1.anyCaseToCamelCase)(firstWord);
289
- }
290
- }
291
- exports.extractFirstWord = extractFirstWord;
292
- /**
293
- * Check if the path is a nested path, a single path or a sugar path
294
- * @param path
295
- * @returns the path style
296
- */
297
- const checkPathStyle = (path) => {
298
- const singleOrNestedPathRegex = /\/|\\/;
299
- const sugarPathRegex = /^\w+-\w+$/;
300
- if (singleOrNestedPathRegex.test(path)) {
301
- return "nested" /* PathStyle.Nested */;
302
- }
303
- else if (sugarPathRegex.test(path)) {
304
- return "sugar" /* PathStyle.Sugar */;
305
- }
306
- else {
307
- return "single" /* PathStyle.Single */;
308
- }
309
- };
310
- exports.checkPathStyle = checkPathStyle;
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.checkPathStyle = exports.extractFirstWord = exports.getNameWithScaffoldPattern = exports.schematicFolder = exports.writeTemplate = exports.getHttpMethod = exports.splitTarget = exports.getFileNameWithoutExtension = exports.validateAndPrepareFile = void 0;
30
+ const node_fs_1 = require("node:fs");
31
+ const nodePath = __importStar(require("node:path"));
32
+ const mustache_1 = require("mustache");
33
+ const boost_ts_1 = require("@expressots/boost-ts");
34
+ const cli_ui_1 = require("../../utils/cli-ui");
35
+ const verify_file_exists_1 = require("../../utils/verify-file-exists");
36
+ const compiler_1 = __importDefault(require("../../utils/compiler"));
37
+ /**
38
+ * Create a template based on the schematic
39
+ * @param fp
40
+ * @returns the file created
41
+ */
42
+ async function validateAndPrepareFile(fp) {
43
+ const { sourceRoot, scaffoldSchematics, opinionated } = fp.expressoConfig;
44
+ if (sourceRoot === "") {
45
+ (0, cli_ui_1.printError)("You must specify a source root in your expressots.config.ts", "sourceRoot");
46
+ process.exit(1);
47
+ }
48
+ if (opinionated) {
49
+ const folderSchematic = (0, exports.schematicFolder)(fp.schematic);
50
+ const folderToScaffold = `${sourceRoot}/${folderSchematic}`;
51
+ const { path, file, className, moduleName, modulePath } = await (0, exports.splitTarget)({
52
+ target: fp.target,
53
+ schematic: fp.schematic,
54
+ });
55
+ const outputPath = `${folderToScaffold}/${path}/${file}`;
56
+ await (0, verify_file_exists_1.verifyIfFileExists)(outputPath, fp.schematic);
57
+ (0, node_fs_1.mkdirSync)(`${folderToScaffold}/${path}`, { recursive: true });
58
+ return {
59
+ path,
60
+ file,
61
+ className,
62
+ moduleName,
63
+ modulePath,
64
+ outputPath,
65
+ folderToScaffold,
66
+ fileName: getFileNameWithoutExtension(file),
67
+ schematic: fp.schematic,
68
+ };
69
+ }
70
+ const folderSchematic = "";
71
+ const folderToScaffold = `${sourceRoot}/${folderSchematic}`;
72
+ const { path, file, className, moduleName, modulePath } = await (0, exports.splitTarget)({
73
+ target: fp.target,
74
+ schematic: fp.schematic,
75
+ });
76
+ const fileBaseSchema = scaffoldSchematics?.[fp.schematic];
77
+ const validateFileSchema = fileBaseSchema !== undefined
78
+ ? file.replace(fp.schematic, fileBaseSchema)
79
+ : file;
80
+ const outputPath = `${folderToScaffold}/${path}/${validateFileSchema}`;
81
+ await (0, verify_file_exists_1.verifyIfFileExists)(outputPath, fp.schematic);
82
+ (0, node_fs_1.mkdirSync)(`${folderToScaffold}/${path}`, { recursive: true });
83
+ return {
84
+ path,
85
+ file,
86
+ className,
87
+ moduleName,
88
+ modulePath,
89
+ outputPath,
90
+ folderToScaffold,
91
+ fileName: getFileNameWithoutExtension(file),
92
+ schematic: fileBaseSchema !== undefined ? fileBaseSchema : fp.schematic,
93
+ };
94
+ }
95
+ exports.validateAndPrepareFile = validateAndPrepareFile;
96
+ /**
97
+ * Get the file name without the extension
98
+ * @param filePath
99
+ * @returns the file name
100
+ */
101
+ function getFileNameWithoutExtension(filePath) {
102
+ return filePath.split(".")[0];
103
+ }
104
+ exports.getFileNameWithoutExtension = getFileNameWithoutExtension;
105
+ /**
106
+ * Split the target into path, file, class name, module name and module path
107
+ * @param target
108
+ * @param schematic
109
+ * @returns the split target
110
+ */
111
+ const splitTarget = async ({ target, schematic, }) => {
112
+ const pathContent = target
113
+ .split("/")
114
+ .filter((item) => item !== "");
115
+ const endsWithSlash = target.endsWith("/");
116
+ let path = "";
117
+ let fileName = "";
118
+ let module = "";
119
+ let modulePath = "";
120
+ if (target.includes("/") ||
121
+ target.includes("\\") ||
122
+ target.includes("//")) {
123
+ if (schematic === "service")
124
+ schematic = "controller";
125
+ if (schematic === "service" ||
126
+ (schematic === "controller" && pathContent.length > 4)) {
127
+ (0, cli_ui_1.printError)("Max path depth is 4.", pathContent.join("/"));
128
+ process.exit(1);
129
+ }
130
+ if (endsWithSlash) {
131
+ fileName = pathContent[pathContent.length - 1];
132
+ path = pathContent.join("/");
133
+ module =
134
+ pathContent.length == 1
135
+ ? pathContent[pathContent.length - 1]
136
+ : pathContent[pathContent.length - 2];
137
+ modulePath = pathContent.slice(0, -1).join("/");
138
+ }
139
+ else {
140
+ fileName = pathContent[pathContent.length - 1];
141
+ path = pathContent.slice(0, -1).join("/");
142
+ module =
143
+ pathContent.length == 2
144
+ ? pathContent[pathContent.length - 2]
145
+ : pathContent[pathContent.length - 3];
146
+ modulePath = pathContent.slice(0, -2).join("/");
147
+ }
148
+ return {
149
+ path,
150
+ file: `${await (0, exports.getNameWithScaffoldPattern)(fileName)}.${schematic}.ts`,
151
+ className: (0, boost_ts_1.anyCaseToPascalCase)(fileName),
152
+ moduleName: module,
153
+ modulePath,
154
+ };
155
+ }
156
+ else {
157
+ if (schematic === "service")
158
+ schematic = "controller";
159
+ // 1. Extract the name (first part of the target)
160
+ const [name, ...remainingPath] = target.split("/");
161
+ // 2. Check if the name is camelCase or kebab-case
162
+ const camelCaseRegex = /[A-Z]/;
163
+ const kebabCaseRegex = /[_\-\s]+/;
164
+ const isCamelCase = camelCaseRegex.test(name);
165
+ const isKebabCase = kebabCaseRegex.test(name);
166
+ if (isCamelCase || isKebabCase) {
167
+ const [wordName, ...path] = name
168
+ ? name
169
+ .split(isCamelCase ? /(?=[A-Z])/ : kebabCaseRegex)
170
+ .map((word) => word.toLowerCase())
171
+ : [];
172
+ return {
173
+ path: `${wordName}/${pathEdgeCase(path)}${pathEdgeCase(remainingPath)}`,
174
+ file: `${await (0, exports.getNameWithScaffoldPattern)(name)}.${schematic}.ts`,
175
+ className: (0, boost_ts_1.anyCaseToPascalCase)(name),
176
+ moduleName: wordName,
177
+ modulePath: pathContent[0].split("-")[1],
178
+ };
179
+ }
180
+ // 3. Return the base case
181
+ return {
182
+ path: "",
183
+ file: `${await (0, exports.getNameWithScaffoldPattern)(name)}.${schematic}.ts`,
184
+ className: (0, boost_ts_1.anyCaseToPascalCase)(name),
185
+ moduleName: name,
186
+ modulePath: "",
187
+ };
188
+ }
189
+ };
190
+ exports.splitTarget = splitTarget;
191
+ /**
192
+ * Write the template based on the http method
193
+ * @param method - the http method
194
+ * @returns decorator - the decorator to be used
195
+ */
196
+ const getHttpMethod = (method) => {
197
+ switch (method) {
198
+ case "put":
199
+ return "Put";
200
+ case "post":
201
+ return "Post";
202
+ case "patch":
203
+ return "Patch";
204
+ case "delete":
205
+ return "Delete";
206
+ default:
207
+ return "Get";
208
+ }
209
+ };
210
+ exports.getHttpMethod = getHttpMethod;
211
+ /**
212
+ * Write the template based on the schematics
213
+ * @param outputPath - the output path
214
+ * @param template - the template to be used
215
+ * @returns void
216
+ */
217
+ const writeTemplate = ({ outputPath, template: { path, data }, }) => {
218
+ (0, node_fs_1.writeFileSync)(outputPath, (0, mustache_1.render)((0, node_fs_1.readFileSync)(nodePath.join(__dirname, path), "utf8"), data));
219
+ };
220
+ exports.writeTemplate = writeTemplate;
221
+ /**
222
+ * Returns the folder where the schematic should be placed
223
+ * @param schematic
224
+ */
225
+ const schematicFolder = (schematic) => {
226
+ switch (schematic) {
227
+ case "usecase":
228
+ return "useCases";
229
+ case "controller":
230
+ return "useCases";
231
+ case "dto":
232
+ return "useCases";
233
+ case "service":
234
+ return "useCases";
235
+ case "provider":
236
+ return "providers";
237
+ case "entity":
238
+ return "entities";
239
+ case "middleware":
240
+ return "providers/middlewares";
241
+ case "module":
242
+ return "useCases";
243
+ }
244
+ return undefined;
245
+ };
246
+ exports.schematicFolder = schematicFolder;
247
+ /**
248
+ * Get the name with the scaffold pattern
249
+ * @param name
250
+ * @returns the name in the scaffold pattern
251
+ */
252
+ const getNameWithScaffoldPattern = async (name) => {
253
+ const configObject = await compiler_1.default.loadConfig();
254
+ switch (configObject.scaffoldPattern) {
255
+ case "lowercase" /* Pattern.LOWER_CASE */:
256
+ return (0, boost_ts_1.anyCaseToLowerCase)(name);
257
+ case "kebab-case" /* Pattern.KEBAB_CASE */:
258
+ return (0, boost_ts_1.anyCaseToKebabCase)(name);
259
+ case "PascalCase" /* Pattern.PASCAL_CASE */:
260
+ return (0, boost_ts_1.anyCaseToPascalCase)(name);
261
+ case "camelCase" /* Pattern.CAMEL_CASE */:
262
+ return (0, boost_ts_1.anyCaseToCamelCase)(name);
263
+ }
264
+ };
265
+ exports.getNameWithScaffoldPattern = getNameWithScaffoldPattern;
266
+ /**
267
+ * Get the path edge case
268
+ * @param path
269
+ * @returns the path edge case from the last element of the path
270
+ */
271
+ const pathEdgeCase = (path) => {
272
+ return `${path.join("/")}${path.length > 0 ? "/" : ""}`;
273
+ };
274
+ /**
275
+ * Extract the first word from a file and convert it to the scaffold pattern
276
+ * @param file
277
+ * @returns the first word in the scaffold pattern
278
+ */
279
+ async function extractFirstWord(file) {
280
+ const f = file.split(".")[0];
281
+ const regex = /(?:-|(?<=[a-z])(?=[A-Z]))/;
282
+ const firstWord = f.split(regex)[0];
283
+ const config = await compiler_1.default.loadConfig();
284
+ switch (config.scaffoldPattern) {
285
+ case "lowercase" /* Pattern.LOWER_CASE */:
286
+ return (0, boost_ts_1.anyCaseToLowerCase)(firstWord);
287
+ case "kebab-case" /* Pattern.KEBAB_CASE */:
288
+ return (0, boost_ts_1.anyCaseToKebabCase)(firstWord);
289
+ case "PascalCase" /* Pattern.PASCAL_CASE */:
290
+ return (0, boost_ts_1.anyCaseToPascalCase)(firstWord);
291
+ case "camelCase" /* Pattern.CAMEL_CASE */:
292
+ return (0, boost_ts_1.anyCaseToCamelCase)(firstWord);
293
+ }
294
+ }
295
+ exports.extractFirstWord = extractFirstWord;
296
+ /**
297
+ * Check if the path is a nested path, a single path or a sugar path
298
+ * @param path
299
+ * @returns the path style
300
+ */
301
+ const checkPathStyle = (path) => {
302
+ const singleOrNestedPathRegex = /\/|\\/;
303
+ const sugarPathRegex = /^\w+-\w+$/;
304
+ if (singleOrNestedPathRegex.test(path)) {
305
+ return "nested" /* PathStyle.Nested */;
306
+ }
307
+ else if (sugarPathRegex.test(path)) {
308
+ return "sugar" /* PathStyle.Sugar */;
309
+ }
310
+ else {
311
+ return "single" /* PathStyle.Single */;
312
+ }
313
+ };
314
+ exports.checkPathStyle = checkPathStyle;
@@ -1,9 +1,9 @@
1
- import { ExpressoConfig } from "../../@types";
2
- /**
3
- * Process the non-opinionated command
4
- * @param schematic - The schematic
5
- * @param target - The target
6
- * @param method - The method
7
- * @param expressoConfig - The expresso config
8
- */
9
- export declare function nonOpinionatedProcess(schematic: string, target: string, method: string, expressoConfig: ExpressoConfig): Promise<string>;
1
+ import { ExpressoConfig } from "../../@types";
2
+ /**
3
+ * Process the non-opinionated command
4
+ * @param schematic - The schematic
5
+ * @param target - The target
6
+ * @param method - The method
7
+ * @param expressoConfig - The expresso config
8
+ */
9
+ export declare function nonOpinionatedProcess(schematic: string, target: string, method: string, expressoConfig: ExpressoConfig): Promise<string>;