@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.
- package/README.md +8 -0
- package/bin/@types/config.d.ts +39 -39
- package/bin/@types/config.js +2 -2
- package/bin/@types/index.d.ts +1 -1
- package/bin/@types/index.js +17 -17
- package/bin/app.container.d.ts +1 -1
- package/bin/app.container.js +8 -8
- package/bin/cli.d.ts +2 -2
- package/bin/cli.js +38 -38
- package/bin/commands/__tests__/project.commands.spec.d.ts +1 -0
- package/bin/commands/__tests__/project.commands.spec.js +8 -0
- package/bin/commands/project.commands.d.ts +8 -8
- package/bin/commands/project.commands.js +137 -136
- package/bin/generate/cli.d.ts +4 -4
- package/bin/generate/cli.js +66 -66
- package/bin/generate/form.d.ts +20 -20
- package/bin/generate/form.js +30 -30
- package/bin/generate/index.d.ts +1 -1
- package/bin/generate/index.js +17 -17
- package/bin/generate/utils/command-utils.d.ts +123 -123
- package/bin/generate/utils/command-utils.js +314 -310
- package/bin/generate/utils/nonopininated-cmd.d.ts +9 -9
- package/bin/generate/utils/nonopininated-cmd.js +248 -248
- package/bin/generate/utils/opinionated-cmd.d.ts +11 -11
- package/bin/generate/utils/opinionated-cmd.js +481 -480
- package/bin/help/cli.d.ts +4 -4
- package/bin/help/cli.js +15 -15
- package/bin/help/form.d.ts +2 -2
- package/bin/help/form.js +28 -28
- package/bin/help/index.d.ts +1 -1
- package/bin/help/index.js +17 -2
- package/bin/index.d.ts +6 -4
- package/bin/index.js +22 -20
- package/bin/info/cli.d.ts +4 -4
- package/bin/info/cli.js +15 -15
- package/bin/info/form.d.ts +2 -2
- package/bin/info/form.js +36 -36
- package/bin/info/index.d.ts +1 -1
- package/bin/info/index.js +17 -17
- package/bin/new/cli.d.ts +4 -4
- package/bin/new/cli.js +65 -51
- package/bin/new/form.d.ts +2 -2
- package/bin/new/form.js +238 -213
- package/bin/new/index.d.ts +1 -1
- package/bin/new/index.js +17 -17
- package/bin/providers/cli.d.ts +4 -4
- package/bin/providers/cli.js +43 -38
- package/bin/providers/external/external.provider.d.ts +2 -0
- package/bin/providers/external/external.provider.js +49 -0
- package/bin/providers/index.d.ts +1 -1
- package/bin/providers/index.js +17 -17
- package/bin/providers/prisma/prisma.provider.d.ts +2 -2
- package/bin/providers/prisma/prisma.provider.js +272 -270
- package/bin/types.d.ts +1 -1
- package/bin/types.js +17 -17
- package/bin/utils/add-controller-to-module.d.ts +1 -1
- package/bin/utils/add-controller-to-module.js +46 -46
- package/bin/utils/add-module-to-container.d.ts +3 -3
- package/bin/utils/add-module-to-container.js +129 -129
- package/bin/utils/center-text.d.ts +2 -2
- package/bin/utils/center-text.js +10 -10
- package/bin/utils/cli-ui.d.ts +3 -3
- package/bin/utils/cli-ui.js +19 -19
- package/bin/utils/compiler.d.ts +15 -15
- package/bin/utils/compiler.js +93 -93
- package/bin/utils/find-folder.d.ts +5 -5
- package/bin/utils/find-folder.js +37 -37
- package/bin/utils/index.d.ts +1 -1
- package/bin/utils/index.js +17 -17
- package/bin/utils/verify-file-exists.d.ts +2 -2
- package/bin/utils/verify-file-exists.js +30 -30
- 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
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
case "
|
|
199
|
-
return "
|
|
200
|
-
case "
|
|
201
|
-
return "
|
|
202
|
-
|
|
203
|
-
return "
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
case "
|
|
228
|
-
return "useCases";
|
|
229
|
-
case "
|
|
230
|
-
return "useCases";
|
|
231
|
-
case "
|
|
232
|
-
return "
|
|
233
|
-
case "
|
|
234
|
-
return "
|
|
235
|
-
case "
|
|
236
|
-
return "providers
|
|
237
|
-
case "
|
|
238
|
-
return "
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
case "
|
|
256
|
-
return (0, boost_ts_1.
|
|
257
|
-
case "
|
|
258
|
-
return (0, boost_ts_1.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
case "
|
|
286
|
-
return (0, boost_ts_1.
|
|
287
|
-
case "
|
|
288
|
-
return (0, boost_ts_1.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
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>;
|