@expressots/cli 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/@types/config.d.ts +9 -0
- package/bin/app.container.js +4 -5
- package/bin/cli.d.ts +1 -1
- package/bin/cli.js +4 -2
- package/bin/commands/project.commands.d.ts +8 -0
- package/bin/commands/project.commands.js +136 -0
- package/bin/generate/cli.js +5 -2
- package/bin/generate/form.d.ts +13 -0
- package/bin/generate/form.js +17 -374
- package/bin/generate/templates/nonopinionated/controller.tpl +10 -0
- package/bin/generate/templates/nonopinionated/dto.tpl +3 -0
- package/bin/generate/templates/nonopinionated/entity.tpl +4 -0
- package/bin/generate/templates/nonopinionated/middleware.tpl +10 -0
- package/bin/generate/templates/nonopinionated/module.tpl +4 -0
- package/bin/generate/templates/nonopinionated/provider.tpl +4 -0
- package/bin/generate/templates/nonopinionated/usecase.tpl +8 -0
- package/bin/generate/templates/{controller-service-delete.tpl → opinionated/controller-service-delete.tpl} +2 -2
- package/bin/generate/templates/{controller-service.tpl → opinionated/controller-service-get.tpl} +2 -2
- package/bin/generate/templates/{controller-service-patch.tpl → opinionated/controller-service-patch.tpl} +2 -2
- package/bin/generate/templates/{controller-service-post.tpl → opinionated/controller-service-post.tpl} +2 -2
- package/bin/generate/templates/{controller-service-put.tpl → opinionated/controller-service-put.tpl} +2 -2
- package/bin/generate/templates/{entity.tpl → opinionated/entity.tpl} +2 -2
- package/bin/generate/templates/opinionated/middleware.tpl +10 -0
- package/bin/generate/templates/opinionated/module-service.tpl +5 -0
- package/bin/generate/templates/opinionated/module.tpl +4 -0
- package/bin/generate/templates/opinionated/usecase-service-delete.tpl +8 -0
- package/bin/generate/utils/command-utils.d.ts +123 -0
- package/bin/generate/utils/command-utils.js +310 -0
- package/bin/generate/utils/nonopininated-cmd.d.ts +9 -0
- package/bin/generate/utils/nonopininated-cmd.js +248 -0
- package/bin/generate/utils/opinionated-cmd.d.ts +11 -0
- package/bin/generate/utils/opinionated-cmd.js +480 -0
- package/bin/help/cli.d.ts +4 -0
- package/bin/help/cli.js +15 -0
- package/bin/help/form.d.ts +2 -0
- package/bin/help/form.js +28 -0
- package/bin/help/index.d.ts +1 -0
- package/bin/help/index.js +2 -0
- package/bin/info/form.d.ts +1 -1
- package/bin/info/form.js +8 -11
- package/bin/new/cli.d.ts +1 -1
- package/bin/new/cli.js +33 -31
- package/bin/new/form.js +7 -5
- package/bin/utils/add-controller-to-module.d.ts +1 -2
- package/bin/utils/add-module-to-container.d.ts +2 -1
- package/bin/utils/add-module-to-container.js +37 -4
- package/bin/utils/cli-ui.d.ts +2 -0
- package/bin/utils/cli-ui.js +10 -2
- package/bin/utils/verify-file-exists.d.ts +1 -1
- package/bin/utils/verify-file-exists.js +6 -4
- package/package.json +5 -2
- package/bin/generate/templates/dto-op.tpl +0 -7
- package/bin/generate/templates/module-default.tpl +0 -3
- package/bin/generate/templates/module.tpl +0 -4
- package/bin/generate/templates/usecase-post.tpl +0 -9
- /package/bin/generate/templates/{controller.tpl → opinionated/controller-service.tpl} +0 -0
- /package/bin/generate/templates/{dto.tpl → opinionated/dto.tpl} +0 -0
- /package/bin/generate/templates/{provider.tpl → opinionated/provider.tpl} +0 -0
- /package/bin/generate/templates/{usecase-op.tpl → opinionated/usecase-service.tpl} +0 -0
- /package/bin/generate/templates/{usecase.tpl → opinionated/usecase.tpl} +0 -0
|
@@ -0,0 +1,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
|
+
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
|
+
}
|
package/bin/help/cli.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.helpCommand = void 0;
|
|
4
|
+
const form_1 = require("./form");
|
|
5
|
+
const helpCommand = () => {
|
|
6
|
+
return {
|
|
7
|
+
command: "resources",
|
|
8
|
+
describe: "Resource list",
|
|
9
|
+
aliases: ["r"],
|
|
10
|
+
handler: async () => {
|
|
11
|
+
await (0, form_1.helpForm)();
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.helpCommand = helpCommand;
|
package/bin/help/form.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.helpForm = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
+
const helpForm = async () => {
|
|
10
|
+
const table = new cli_table3_1.default({
|
|
11
|
+
head: [
|
|
12
|
+
chalk_1.default.green("Name"),
|
|
13
|
+
chalk_1.default.green("Alias"),
|
|
14
|
+
chalk_1.default.green("Description"),
|
|
15
|
+
],
|
|
16
|
+
colWidths: [15, 10, 60],
|
|
17
|
+
});
|
|
18
|
+
table.push(["new project", "new", "Generate a new project"], ["info", "i", "Provides project information"], ["resources", "r", "Displays cli commands and resources"], ["help", "h", "Show command help"], [
|
|
19
|
+
"service",
|
|
20
|
+
"g s",
|
|
21
|
+
"Generate a service [controller, usecase, dto, module]",
|
|
22
|
+
], ["controller", "g c", "Generate a controller"], ["usecase", "g u", "Generate a usecase"], ["dto", "g d", "Generate a dto"], ["entity", "g e", "Generate an entity"], ["provider", "g p", "Generate a provider"], ["module", "g mo", "Generate a module"], ["middleware", "g mi", "Generate a middleware"]);
|
|
23
|
+
console.log(chalk_1.default.bold.white("ExpressoTS:", `${chalk_1.default.green("Resources List")}`));
|
|
24
|
+
console.log(chalk_1.default.whiteBright(table.toString()));
|
|
25
|
+
console.log(chalk_1.default.bold.white(`📝 More info: ${chalk_1.default.green("https://doc.expresso-ts.com/docs/category/cli")}`));
|
|
26
|
+
console.log("\n");
|
|
27
|
+
};
|
|
28
|
+
exports.helpForm = helpForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/bin/info/form.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const infoForm: () =>
|
|
1
|
+
declare const infoForm: () => void;
|
|
2
2
|
export { infoForm };
|
package/bin/info/form.js
CHANGED
|
@@ -8,7 +8,6 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const os_1 = __importDefault(require("os"));
|
|
11
|
-
const cli_1 = require("../cli");
|
|
12
11
|
const cli_ui_1 = require("../utils/cli-ui");
|
|
13
12
|
function getInfosFromPackage() {
|
|
14
13
|
try {
|
|
@@ -19,21 +18,19 @@ function getInfosFromPackage() {
|
|
|
19
18
|
const fileContents = fs_1.default.readFileSync(packageJsonPath, "utf-8");
|
|
20
19
|
const packageJson = JSON.parse(fileContents);
|
|
21
20
|
console.log(chalk_1.default.green("ExpressoTS Project:"));
|
|
22
|
-
console.log(chalk_1.default.
|
|
23
|
-
console.log(chalk_1.default.
|
|
24
|
-
console.log(chalk_1.default.
|
|
25
|
-
console.log(chalk_1.default.
|
|
21
|
+
console.log(chalk_1.default.white(`\tName: ${packageJson.name}`));
|
|
22
|
+
console.log(chalk_1.default.white(`\tDescription: ${packageJson.description}`));
|
|
23
|
+
console.log(chalk_1.default.white(`\tVersion: ${packageJson.version}`));
|
|
24
|
+
console.log(chalk_1.default.white(`\tAuthor: ${packageJson.author}`));
|
|
26
25
|
}
|
|
27
26
|
catch (error) {
|
|
28
27
|
(0, cli_ui_1.printError)("No project information available.", "package.json not found!");
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
const infoForm =
|
|
32
|
-
console.log(chalk_1.default.green("System informations:"));
|
|
33
|
-
console.log(chalk_1.default.bold(`\tOS Version: ${os_1.default.version()}`));
|
|
34
|
-
console.log(chalk_1.default.bold(`\tNodeJS version: ${process.version}`));
|
|
35
|
-
console.log(chalk_1.default.green("CLI Version:"));
|
|
36
|
-
console.log(chalk_1.default.bold(`\tCurrent version: v${cli_1.CLI_VERSION}`));
|
|
30
|
+
const infoForm = () => {
|
|
37
31
|
getInfosFromPackage();
|
|
32
|
+
console.log(chalk_1.default.green("System information:"));
|
|
33
|
+
console.log(chalk_1.default.white(`\tOS Version: ${os_1.default.version()}`));
|
|
34
|
+
console.log(chalk_1.default.white(`\tNodeJS version: ${process.version}`));
|
|
38
35
|
};
|
|
39
36
|
exports.infoForm = infoForm;
|
package/bin/new/cli.d.ts
CHANGED
package/bin/new/cli.js
CHANGED
|
@@ -2,41 +2,43 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createProject = void 0;
|
|
4
4
|
const form_1 = require("./form");
|
|
5
|
+
const packageManagers = [
|
|
6
|
+
"npm",
|
|
7
|
+
"yarn",
|
|
8
|
+
"pnpm",
|
|
9
|
+
...(process.platform !== "win32" ? ["bun"] : []),
|
|
10
|
+
];
|
|
11
|
+
const commandOptions = (yargs) => {
|
|
12
|
+
return yargs
|
|
13
|
+
.positional("project-name", {
|
|
14
|
+
describe: "The name of the project",
|
|
15
|
+
type: "string",
|
|
16
|
+
})
|
|
17
|
+
.option("template", {
|
|
18
|
+
describe: "The project template to use",
|
|
19
|
+
type: "string",
|
|
20
|
+
choices: ["opinionated", "non-opinionated"],
|
|
21
|
+
alias: "t",
|
|
22
|
+
})
|
|
23
|
+
.option("package-manager", {
|
|
24
|
+
describe: "The package manager to use",
|
|
25
|
+
type: "string",
|
|
26
|
+
choices: packageManagers,
|
|
27
|
+
alias: "p",
|
|
28
|
+
})
|
|
29
|
+
.option("directory", {
|
|
30
|
+
describe: "The directory for new project",
|
|
31
|
+
type: "string",
|
|
32
|
+
alias: "d",
|
|
33
|
+
})
|
|
34
|
+
.implies("package-manager", "template")
|
|
35
|
+
.implies("template", "package-manager");
|
|
36
|
+
};
|
|
5
37
|
const createProject = () => {
|
|
6
|
-
const packageManagers = ["npm", "yarn", "pnpm"];
|
|
7
|
-
if (process.platform !== "win32") {
|
|
8
|
-
packageManagers.push("bun");
|
|
9
|
-
}
|
|
10
38
|
return {
|
|
11
39
|
command: "new <project-name> [package-manager] [template] [directory]",
|
|
12
40
|
describe: "Create a new project",
|
|
13
|
-
builder:
|
|
14
|
-
yargs
|
|
15
|
-
.positional("project-name", {
|
|
16
|
-
describe: "The name of the project",
|
|
17
|
-
type: "string",
|
|
18
|
-
})
|
|
19
|
-
.option("template", {
|
|
20
|
-
describe: "The project template to use",
|
|
21
|
-
type: "string",
|
|
22
|
-
choices: ["non-opinionated", "opinionated"],
|
|
23
|
-
alias: "t",
|
|
24
|
-
})
|
|
25
|
-
.option("package-manager", {
|
|
26
|
-
describe: "The package manager to use",
|
|
27
|
-
type: "string",
|
|
28
|
-
choices: packageManagers,
|
|
29
|
-
alias: "p",
|
|
30
|
-
})
|
|
31
|
-
.option("directory", {
|
|
32
|
-
describe: "The directory for new project",
|
|
33
|
-
type: "string",
|
|
34
|
-
alias: "d",
|
|
35
|
-
})
|
|
36
|
-
.implies("package-manager", "template")
|
|
37
|
-
.implies("template", "package-manager");
|
|
38
|
-
return yargs;
|
|
39
|
-
},
|
|
41
|
+
builder: commandOptions,
|
|
40
42
|
handler: async ({ projectName, packageManager, template, directory, }) => {
|
|
41
43
|
return await (0, form_1.projectForm)(projectName, [
|
|
42
44
|
packageManager,
|