@expressots/cli 1.2.2 → 1.3.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/README.md +10 -5
- package/bin/app.container.d.ts +1 -0
- package/bin/app.container.js +14 -0
- package/bin/cli.d.ts +1 -1
- package/bin/cli.js +19 -3
- package/bin/generate/cli.js +35 -24
- package/bin/generate/form.d.ts +2 -1
- package/bin/generate/form.js +213 -71
- package/bin/generate/templates/controller-service-delete.tpl +24 -0
- package/bin/generate/templates/controller-service-patch.tpl +28 -0
- package/bin/generate/templates/controller-service-post.tpl +24 -0
- package/bin/generate/templates/controller-service-put.tpl +28 -0
- package/bin/generate/templates/controller-service.tpl +5 -4
- package/bin/generate/templates/controller.tpl +4 -3
- package/bin/generate/templates/dto-op.tpl +7 -0
- package/bin/generate/templates/entity.tpl +13 -0
- package/bin/generate/templates/usecase-op.tpl +14 -0
- package/bin/generate/templates/usecase-post.tpl +14 -0
- package/bin/info/cli.d.ts +4 -0
- package/bin/info/cli.js +15 -0
- package/bin/info/form.d.ts +2 -0
- package/bin/info/form.js +39 -0
- package/bin/info/index.d.ts +1 -0
- package/bin/info/index.js +17 -0
- package/bin/new/cli.js +12 -5
- package/bin/new/form.d.ts +1 -10
- package/bin/new/form.js +66 -20
- package/bin/utils/add-controller-to-module.js +2 -2
- package/bin/utils/add-module-to-container.d.ts +2 -0
- package/bin/utils/add-module-to-container.js +84 -0
- package/bin/utils/center-text.d.ts +2 -0
- package/bin/utils/center-text.js +10 -0
- package/bin/utils/cli-ui.d.ts +1 -0
- package/bin/utils/cli-ui.js +11 -0
- package/bin/utils/compiler.js +7 -2
- package/bin/utils/verify-file-exists.js +3 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/
|
|
2
|
+
<a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
+
# Expresso TS
|
|
6
|
+
|
|
7
|
+
A Typescript + [Node.js]("https://nodejs.org/en/") lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🚀
|
|
8
|
+
|
|
5
9
|
# <h1 align="left">Expresso TS CLI Tool</h1>
|
|
6
10
|
|
|
7
11
|
## Description
|
|
8
12
|
|
|
9
|
-
The
|
|
13
|
+
The ExpressoTS CLI is a command-line interface tool that helps you to create `ExpressoTS` projects, develop, and maintain your applications and resources created. It assists in multiple ways, including creating the project as well as scaffolding services offered by the application such as use cases, controllers, providers and more.
|
|
10
14
|
|
|
11
15
|
## Installation 💻
|
|
12
16
|
|
|
13
|
-
```
|
|
14
|
-
npm
|
|
17
|
+
```bash
|
|
18
|
+
npm i -g @expressots/cli
|
|
15
19
|
```
|
|
16
20
|
|
|
17
21
|
## Usage
|
|
@@ -20,9 +24,10 @@ Learn more in the [official documentation](https://expresso-ts.com/docs/category
|
|
|
20
24
|
|
|
21
25
|
## Stay in touch
|
|
22
26
|
|
|
27
|
+
- Author: Daniel Boll | Richard Zampieri
|
|
23
28
|
- Website: [https://expresso-ts.com](https://expresso-ts.com)
|
|
24
29
|
- Twitch: [@expressots Development](https://www.twitch.tv/richardzampieri)
|
|
25
30
|
|
|
26
31
|
## License
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
ExpressoTS is [MIT Licensed](https://github.com/expressots/expressots-cli/blob/main/LICENSE.md)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* import { AppContainer } from "@expressots/core";
|
|
4
|
+
import { AppModule } from "./app.module";
|
|
5
|
+
import { UserModule } from "@useCases/user/user.module";
|
|
6
|
+
|
|
7
|
+
const appContainer = new AppContainer();
|
|
8
|
+
|
|
9
|
+
const container = appContainer.create([// Add your modules here
|
|
10
|
+
AppModule, UserModule]);
|
|
11
|
+
|
|
12
|
+
export { container };
|
|
13
|
+
|
|
14
|
+
*/
|
package/bin/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export
|
|
2
|
+
export declare const CLI_VERSION = "1.3.0";
|
package/bin/cli.js
CHANGED
|
@@ -4,15 +4,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CLI_VERSION = void 0;
|
|
7
8
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
9
|
const helpers_1 = require("yargs/helpers");
|
|
9
10
|
const generate_1 = require("./generate");
|
|
11
|
+
const info_1 = require("./info");
|
|
10
12
|
const new_1 = require("./new");
|
|
13
|
+
exports.CLI_VERSION = "1.3.0";
|
|
14
|
+
console.log(`\n[🐎 Expressots]\n`);
|
|
11
15
|
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
12
|
-
.
|
|
16
|
+
.scriptName("expressots")
|
|
13
17
|
.command((0, new_1.createProject)())
|
|
14
18
|
.command((0, generate_1.generateProject)())
|
|
19
|
+
.command((0, info_1.infoProject)())
|
|
20
|
+
.example("$0 new expressots-demo", "Create interactively")
|
|
21
|
+
.example("$0 new expressots-demo -d ./", "Create interactively with path")
|
|
22
|
+
.example("$0 new expressots-demo -p yarn -t opinionated", "Create silently")
|
|
23
|
+
.example("$0 new expressots-demo -p yarn -t opinionated -d ./", "Create silently with path")
|
|
24
|
+
.example("$0 generate service user-create", "Scaffold a service")
|
|
25
|
+
.example("$0 info", "Show CLI details")
|
|
15
26
|
.demandCommand(1, "You need at least one command before moving on")
|
|
16
|
-
.epilog("For more information
|
|
17
|
-
.
|
|
27
|
+
.epilog("For more information: \n" +
|
|
28
|
+
"🌐 visit:\t https://expresso-ts.com\n" +
|
|
29
|
+
"💖 Sponsor:\t https://github.com/sponsors/expressots")
|
|
30
|
+
.help("help", "Show command help")
|
|
31
|
+
.alias("h", "help")
|
|
32
|
+
.version(false)
|
|
33
|
+
.wrap(140)
|
|
18
34
|
.parse();
|
package/bin/generate/cli.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.generateProject = void 0;
|
|
7
4
|
const form_1 = require("./form");
|
|
8
|
-
const
|
|
5
|
+
const coerceSchematicAliases = (arg) => {
|
|
6
|
+
switch (arg) {
|
|
7
|
+
case "u":
|
|
8
|
+
return "usecase";
|
|
9
|
+
case "c":
|
|
10
|
+
return "controller";
|
|
11
|
+
case "d":
|
|
12
|
+
return "dto";
|
|
13
|
+
case "s":
|
|
14
|
+
return "service";
|
|
15
|
+
case "p":
|
|
16
|
+
return "provider";
|
|
17
|
+
case "e":
|
|
18
|
+
return "entity";
|
|
19
|
+
default:
|
|
20
|
+
return arg;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
9
23
|
const generateProject = () => {
|
|
10
24
|
return {
|
|
11
25
|
command: "generate [schematic] [path]",
|
|
12
|
-
describe: "
|
|
26
|
+
describe: "Scaffold a new resource",
|
|
13
27
|
aliases: ["g"],
|
|
14
28
|
builder: (yargs) => {
|
|
15
29
|
yargs.positional("schematic", {
|
|
@@ -19,6 +33,7 @@ const generateProject = () => {
|
|
|
19
33
|
"dto",
|
|
20
34
|
"service",
|
|
21
35
|
"provider",
|
|
36
|
+
"entity",
|
|
22
37
|
],
|
|
23
38
|
describe: "The schematic to generate",
|
|
24
39
|
type: "string",
|
|
@@ -27,29 +42,25 @@ const generateProject = () => {
|
|
|
27
42
|
yargs.positional("path", {
|
|
28
43
|
describe: "The path to generate the schematic",
|
|
29
44
|
type: "string",
|
|
45
|
+
alias: "d",
|
|
46
|
+
});
|
|
47
|
+
yargs.positional("method", {
|
|
48
|
+
choices: [
|
|
49
|
+
"get",
|
|
50
|
+
"post",
|
|
51
|
+
"put",
|
|
52
|
+
"patch",
|
|
53
|
+
"delete",
|
|
54
|
+
],
|
|
55
|
+
describe: "HTTP method",
|
|
56
|
+
type: "string",
|
|
57
|
+
alias: "m",
|
|
30
58
|
});
|
|
31
59
|
return yargs;
|
|
32
60
|
},
|
|
33
|
-
handler: async ({ schematic, path }) => {
|
|
34
|
-
|
|
35
|
-
console.log(chalk_1.default.green(`> ${file.split(".")[0]} ${schematic} created! 🚀`));
|
|
61
|
+
handler: async ({ schematic, path, method }) => {
|
|
62
|
+
await (0, form_1.createTemplate)({ schematic, path, method });
|
|
36
63
|
},
|
|
37
64
|
};
|
|
38
65
|
};
|
|
39
66
|
exports.generateProject = generateProject;
|
|
40
|
-
const coerceSchematicAliases = (arg) => {
|
|
41
|
-
switch (arg) {
|
|
42
|
-
case "u":
|
|
43
|
-
return "usecase";
|
|
44
|
-
case "c":
|
|
45
|
-
return "controller";
|
|
46
|
-
case "d":
|
|
47
|
-
return "dto";
|
|
48
|
-
case "s":
|
|
49
|
-
return "service";
|
|
50
|
-
case "p":
|
|
51
|
-
return "provider";
|
|
52
|
-
default:
|
|
53
|
-
return arg;
|
|
54
|
-
}
|
|
55
|
-
};
|
package/bin/generate/form.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type CreateTemplateProps = {
|
|
2
2
|
schematic: string;
|
|
3
3
|
path: string;
|
|
4
|
+
method: string;
|
|
4
5
|
};
|
|
5
|
-
export declare const createTemplate: ({ schematic, path: target, }: CreateTemplateProps) => Promise<string>;
|
|
6
|
+
export declare const createTemplate: ({ schematic, path: target, method, }: CreateTemplateProps) => Promise<string>;
|
|
6
7
|
export {};
|
package/bin/generate/form.js
CHANGED
|
@@ -43,36 +43,47 @@ const boost_ts_1 = require("@expressots/boost-ts");
|
|
|
43
43
|
const compiler_1 = __importDefault(require("../utils/compiler"));
|
|
44
44
|
const add_controller_to_module_1 = require("../utils/add-controller-to-module");
|
|
45
45
|
const verify_file_exists_1 = require("../utils/verify-file-exists");
|
|
46
|
+
const add_module_to_container_1 = require("../utils/add-module-to-container");
|
|
47
|
+
const cli_ui_1 = require("../utils/cli-ui");
|
|
46
48
|
function getFileNameWithoutExtension(filePath) {
|
|
47
49
|
return filePath.split('.')[0];
|
|
48
50
|
}
|
|
49
|
-
const
|
|
50
|
-
usecase: (text) => chalk_1.default.cyan(text),
|
|
51
|
-
controller: (text) => chalk_1.default.magenta(text),
|
|
52
|
-
dto: (text) => chalk_1.default.blue(text),
|
|
53
|
-
provider: (text) => chalk_1.default.yellow(text),
|
|
54
|
-
module: (text) => chalk_1.default.red(text),
|
|
55
|
-
};
|
|
56
|
-
const createTemplate = async ({ schematic, path: target, }) => {
|
|
51
|
+
const createTemplate = async ({ schematic, path: target, method, }) => {
|
|
57
52
|
var _a, e_1, _b, _c;
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
const { opinionated, sourceRoot } = await compiler_1.default.loadConfig();
|
|
54
|
+
if (sourceRoot === "") {
|
|
55
|
+
(0, cli_ui_1.printError)("You must specify a source root in your expressots.config.ts", "sourceRoot");
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
let folderMatch = "";
|
|
59
|
+
if (opinionated) {
|
|
60
|
+
folderMatch = schematicFolder(schematic);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
folderMatch = "";
|
|
64
|
+
}
|
|
65
|
+
const { path, file, className, moduleName, modulePath } = await splitTarget({ target, schematic });
|
|
66
|
+
const usecaseDir = `${sourceRoot}/${folderMatch}`;
|
|
67
|
+
await (0, verify_file_exists_1.verifyIfFileExists)(`${usecaseDir}/${path}/${file}`);
|
|
65
68
|
(0, node_fs_1.mkdirSync)(`${usecaseDir}/${path}`, { recursive: true });
|
|
66
69
|
if (schematic !== "service") {
|
|
67
|
-
|
|
70
|
+
// add to guarantee that the routing will always be the last part of the path
|
|
71
|
+
let routeSchema = "";
|
|
72
|
+
if (target.includes("/") || target.includes("\\") || target.includes("//")) {
|
|
73
|
+
routeSchema = path.split("/").pop();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
routeSchema = path.replace(/\/$/, '');
|
|
77
|
+
}
|
|
68
78
|
writeTemplate({
|
|
69
|
-
outputPath: `${usecaseDir}/${path}
|
|
79
|
+
outputPath: `${usecaseDir}/${path}/${file}`,
|
|
70
80
|
template: {
|
|
71
81
|
path: `./templates/${schematic}.tpl`,
|
|
72
82
|
data: {
|
|
73
83
|
className,
|
|
74
|
-
route:
|
|
84
|
+
route: routeSchema,
|
|
75
85
|
construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
|
|
86
|
+
method: getHttpMethod(method),
|
|
76
87
|
},
|
|
77
88
|
},
|
|
78
89
|
});
|
|
@@ -86,17 +97,50 @@ const createTemplate = async ({ schematic, path: target, }) => {
|
|
|
86
97
|
const resource = _c;
|
|
87
98
|
const currentSchematic = resource.replace("controller-service", "controller");
|
|
88
99
|
const schematicFile = file.replace(`controller.ts`, `${currentSchematic}.ts`);
|
|
89
|
-
console.log(
|
|
100
|
+
console.log(" ", chalk_1.default.greenBright(`[${currentSchematic}]`.padEnd(14)), chalk_1.default.bold.white(`${schematicFile} created! ✔️`));
|
|
101
|
+
let templateBasedMethod = "";
|
|
102
|
+
if (method) {
|
|
103
|
+
if (resource === "controller-service" || resource === "controller") {
|
|
104
|
+
if (method === "get")
|
|
105
|
+
templateBasedMethod = `./templates/${resource}.tpl`;
|
|
106
|
+
else
|
|
107
|
+
templateBasedMethod = `./templates/${resource}-${method}.tpl`;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
templateBasedMethod = `./templates/${resource}.tpl`;
|
|
111
|
+
}
|
|
112
|
+
if (resource === "usecase") {
|
|
113
|
+
templateBasedMethod = `./templates/${resource}-op.tpl`;
|
|
114
|
+
}
|
|
115
|
+
if (resource === "usecase") {
|
|
116
|
+
if (method === "get")
|
|
117
|
+
templateBasedMethod = `./templates/${resource}.tpl`;
|
|
118
|
+
if (method === "post")
|
|
119
|
+
templateBasedMethod = `./templates/${resource}-${method}.tpl`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
templateBasedMethod = `./templates/${resource}.tpl`;
|
|
124
|
+
}
|
|
125
|
+
// add to guarantee that the routing will always be the last part of the path
|
|
126
|
+
let routeSchema = "";
|
|
127
|
+
if (target.includes("/") || target.includes("\\") || target.includes("//")) {
|
|
128
|
+
routeSchema = path.split("/").pop();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
routeSchema = path.replace(/\/$/, '');
|
|
132
|
+
}
|
|
90
133
|
writeTemplate({
|
|
91
|
-
outputPath: `${usecaseDir}/${path}
|
|
134
|
+
outputPath: `${usecaseDir}/${path}/${schematicFile}`,
|
|
92
135
|
template: {
|
|
93
|
-
path:
|
|
136
|
+
path: templateBasedMethod,
|
|
94
137
|
data: {
|
|
95
138
|
className,
|
|
96
139
|
fileName: getFileNameWithoutExtension(file),
|
|
97
140
|
useCase: (0, boost_ts_1.anyCaseToCamelCase)(className),
|
|
98
|
-
route:
|
|
141
|
+
route: routeSchema,
|
|
99
142
|
construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
|
|
143
|
+
method: getHttpMethod(method),
|
|
100
144
|
},
|
|
101
145
|
},
|
|
102
146
|
});
|
|
@@ -114,31 +158,168 @@ const createTemplate = async ({ schematic, path: target, }) => {
|
|
|
114
158
|
finally { if (e_1) throw e_1.error; }
|
|
115
159
|
}
|
|
116
160
|
}
|
|
117
|
-
|
|
161
|
+
// Module generation
|
|
118
162
|
if (["controller", "service"].includes(schematic)) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
163
|
+
let moduleExist = false;
|
|
164
|
+
let moduleOutPath = "";
|
|
165
|
+
if (target.includes("/") || target.includes("\\") || target.includes("//")) {
|
|
166
|
+
if (modulePath === "") {
|
|
167
|
+
moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}.module.ts`);
|
|
168
|
+
moduleOutPath = `${usecaseDir}/${moduleName}.module.ts`;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${modulePath}/${moduleName}.module.ts`);
|
|
172
|
+
moduleOutPath = `${usecaseDir}/${modulePath}/${moduleName}.module.ts`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}/${moduleName}.module.ts`);
|
|
177
|
+
if (modulePath === "") {
|
|
178
|
+
moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}.module.ts`);
|
|
179
|
+
moduleOutPath = `${usecaseDir}/${moduleName}.module.ts`;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}/${moduleName}.module.ts`);
|
|
183
|
+
moduleOutPath = `${usecaseDir}/${moduleName}/${moduleName}.module.ts`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
let controllerPath = "";
|
|
187
|
+
const pathCount = (path.split("/")).length;
|
|
188
|
+
if (path === "") {
|
|
189
|
+
controllerPath = `${file.slice(0, file.lastIndexOf('.'))}`;
|
|
190
|
+
}
|
|
191
|
+
else if (pathCount === 1) {
|
|
192
|
+
controllerPath = `${path}/${file.slice(0, file.lastIndexOf('.'))}`;
|
|
193
|
+
}
|
|
194
|
+
else if (pathCount === 2) {
|
|
195
|
+
controllerPath = `${path.split("/")[1]}/${file.slice(0, file.lastIndexOf('.'))}`;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const segments = path.split("/");
|
|
199
|
+
controllerPath = `${segments[segments.length - 1]}/${file.slice(0, file.lastIndexOf('.'))}`;
|
|
200
|
+
}
|
|
201
|
+
if (moduleExist) {
|
|
202
|
+
if (target.includes("/") || target.includes("\\") || target.includes("//")) {
|
|
203
|
+
await (0, add_controller_to_module_1.addControllerToModule)(`${usecaseDir}/${modulePath}/${moduleName}.module.ts`, `${className}Controller`, controllerPath);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
if (modulePath === "") {
|
|
207
|
+
await (0, add_controller_to_module_1.addControllerToModule)(`${usecaseDir}/${moduleName}.module.ts`, `${className}Controller`, controllerPath);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
await (0, add_controller_to_module_1.addControllerToModule)(`${usecaseDir}/${moduleName}/${moduleName}.module.ts`, `${className}Controller`, controllerPath);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
123
213
|
}
|
|
124
214
|
else {
|
|
125
|
-
console.log(messageColors.module(`> [module] Creating ${moduleName}.module.ts...`));
|
|
126
215
|
writeTemplate({
|
|
127
|
-
outputPath:
|
|
216
|
+
outputPath: moduleOutPath,
|
|
128
217
|
template: {
|
|
129
218
|
path: `./templates/module.tpl`,
|
|
130
219
|
data: {
|
|
131
220
|
moduleName: moduleName[0].toUpperCase() + moduleName.slice(1),
|
|
132
221
|
className,
|
|
133
|
-
path:
|
|
222
|
+
path: controllerPath
|
|
134
223
|
},
|
|
135
224
|
},
|
|
136
225
|
});
|
|
226
|
+
console.log(" ", chalk_1.default.greenBright(`[module]`.padEnd(14)), chalk_1.default.bold.white(`${moduleName}.module created! ✔️`));
|
|
227
|
+
if (target.includes("/") || target.includes("\\") || target.includes("//")) {
|
|
228
|
+
await (0, add_module_to_container_1.addModuleToContainer)(moduleName, modulePath, path);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
await (0, add_module_to_container_1.addModuleToContainer)(moduleName, moduleName, path);
|
|
232
|
+
}
|
|
137
233
|
}
|
|
138
234
|
}
|
|
235
|
+
if (schematic === "service") {
|
|
236
|
+
console.log(" ", chalk_1.default.greenBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.yellow(`${file.split(".")[0]} created! ✔️`));
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
console.log(" ", chalk_1.default.greenBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.white(`${file.split(".")[0]} ${schematic} created! ✔️`));
|
|
240
|
+
}
|
|
139
241
|
return file;
|
|
140
242
|
};
|
|
141
243
|
exports.createTemplate = createTemplate;
|
|
244
|
+
const splitTarget = async ({ target, schematic, }) => {
|
|
245
|
+
const pathContent = target.split("/").filter((item) => item !== "");
|
|
246
|
+
const endsWithSlash = target.endsWith("/");
|
|
247
|
+
let path = "";
|
|
248
|
+
let fileName = "";
|
|
249
|
+
let module = "";
|
|
250
|
+
let modulePath = "";
|
|
251
|
+
if (target.includes("/") || target.includes("\\") || target.includes("//")) {
|
|
252
|
+
//pathContent = target.split("/").filter((item) => item !== "");
|
|
253
|
+
if (schematic === "service")
|
|
254
|
+
schematic = "controller";
|
|
255
|
+
if (schematic === "service" || schematic === "controller" && pathContent.length > 4) {
|
|
256
|
+
(0, cli_ui_1.printError)("Max path depth is 4.", pathContent.join("/"));
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
if (endsWithSlash) {
|
|
260
|
+
fileName = pathContent[pathContent.length - 1];
|
|
261
|
+
path = pathContent.join("/");
|
|
262
|
+
module = (pathContent.length == 1) ? pathContent[pathContent.length - 1] : pathContent[pathContent.length - 2];
|
|
263
|
+
modulePath = pathContent.slice(0, -1).join("/");
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
fileName = pathContent[pathContent.length - 1];
|
|
267
|
+
path = pathContent.slice(0, -1).join("/");
|
|
268
|
+
module = (pathContent.length == 2) ? pathContent[pathContent.length - 2] : pathContent[pathContent.length - 3];
|
|
269
|
+
modulePath = pathContent.slice(0, -2).join("/");
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
path,
|
|
273
|
+
file: `${await getNameWithScaffoldPattern(fileName)}.${schematic}.ts`,
|
|
274
|
+
className: (0, boost_ts_1.anyCaseToPascalCase)(fileName),
|
|
275
|
+
moduleName: module,
|
|
276
|
+
modulePath
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
if (schematic === "service")
|
|
281
|
+
schematic = "controller";
|
|
282
|
+
// 1. Extract the name (first part of the target)
|
|
283
|
+
const [name, ...remainingPath] = target.split("/");
|
|
284
|
+
// 2. Check if the name is camelCase or kebab-case
|
|
285
|
+
const camelCaseRegex = /[A-Z]/;
|
|
286
|
+
const kebabCaseRegex = /[_\-\s]+/;
|
|
287
|
+
const isCamelCase = camelCaseRegex.test(name);
|
|
288
|
+
const isKebabCase = kebabCaseRegex.test(name);
|
|
289
|
+
if (isCamelCase || isKebabCase) {
|
|
290
|
+
const [wordName, ...path] = name === null || name === void 0 ? void 0 : name.split(isCamelCase ? /(?=[A-Z])/ : kebabCaseRegex).map((word) => word.toLowerCase());
|
|
291
|
+
return {
|
|
292
|
+
path: `${wordName}/${pathEdgeCase(path)}${pathEdgeCase(remainingPath)}`,
|
|
293
|
+
file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
|
|
294
|
+
className: (0, boost_ts_1.anyCaseToPascalCase)(name),
|
|
295
|
+
moduleName: wordName,
|
|
296
|
+
modulePath: (pathContent[0].split("-")[1])
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
// 3. Return the base case
|
|
300
|
+
return {
|
|
301
|
+
path: "",
|
|
302
|
+
file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
|
|
303
|
+
className: (0, boost_ts_1.anyCaseToPascalCase)(name),
|
|
304
|
+
moduleName: name,
|
|
305
|
+
modulePath: ""
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const getHttpMethod = (method) => {
|
|
310
|
+
switch (method) {
|
|
311
|
+
case "put":
|
|
312
|
+
return "httpPut";
|
|
313
|
+
case "post":
|
|
314
|
+
return "httpPost";
|
|
315
|
+
case "patch":
|
|
316
|
+
return "httpPatch";
|
|
317
|
+
case "delete":
|
|
318
|
+
return "httpDelete";
|
|
319
|
+
default:
|
|
320
|
+
return "httpGet";
|
|
321
|
+
}
|
|
322
|
+
};
|
|
142
323
|
const writeTemplate = ({ outputPath, template: { path, data }, }) => {
|
|
143
324
|
(0, fs_1.writeFileSync)(outputPath, (0, mustache_1.render)((0, node_fs_1.readFileSync)(nodePath.join(__dirname, path), "utf8"), data));
|
|
144
325
|
};
|
|
@@ -154,50 +335,11 @@ const schematicFolder = (schematic) => {
|
|
|
154
335
|
return "useCases";
|
|
155
336
|
case "provider":
|
|
156
337
|
return "providers";
|
|
338
|
+
case "entity":
|
|
339
|
+
return "entities";
|
|
157
340
|
}
|
|
158
341
|
return undefined;
|
|
159
342
|
};
|
|
160
|
-
const splitTarget = async ({ target, schematic, }) => {
|
|
161
|
-
if (schematic === "provider")
|
|
162
|
-
return await splitTargetProviderEdgeCase({ target, schematic });
|
|
163
|
-
if (schematic === "service")
|
|
164
|
-
schematic = "controller"; // Anything just to generate
|
|
165
|
-
// 1. Extract the name (first part of the target)
|
|
166
|
-
const [name, ...remainingPath] = target.split("/");
|
|
167
|
-
// 2. Check if the name is camelCase or kebab-case
|
|
168
|
-
const camelCaseRegex = /[A-Z]/;
|
|
169
|
-
const kebabCaseRegex = /[_\-\s]+/;
|
|
170
|
-
const isCamelCase = camelCaseRegex.test(name);
|
|
171
|
-
const isKebabCase = kebabCaseRegex.test(name);
|
|
172
|
-
if (isCamelCase || isKebabCase) {
|
|
173
|
-
const [wordName, ...path] = name === null || name === void 0 ? void 0 : name.split(isCamelCase ? /(?=[A-Z])/ : kebabCaseRegex).map((word) => word.toLowerCase());
|
|
174
|
-
return {
|
|
175
|
-
path: `${wordName}/${pathEdgeCase(path)}${pathEdgeCase(remainingPath)}`,
|
|
176
|
-
file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
|
|
177
|
-
className: (0, boost_ts_1.anyCaseToPascalCase)(name),
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
// 3. Return the base case
|
|
181
|
-
return {
|
|
182
|
-
path: `${name}/${pathEdgeCase(remainingPath)}`,
|
|
183
|
-
file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
|
|
184
|
-
className: (0, boost_ts_1.anyCaseToPascalCase)(name),
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
const splitTargetProviderEdgeCase = async ({ target, schematic, }) => {
|
|
188
|
-
// Check if the last path ends with a slash, if it does it's supposed to be a folder
|
|
189
|
-
// and the name of the file will be the same as the folder
|
|
190
|
-
const isFolder = target.endsWith("/");
|
|
191
|
-
const path = target.split("/").slice(0, -1);
|
|
192
|
-
const name = isFolder
|
|
193
|
-
? path[path.length - 1]
|
|
194
|
-
: target.split("/")[target.split("/").length - 1];
|
|
195
|
-
return {
|
|
196
|
-
path: pathEdgeCase(path),
|
|
197
|
-
file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
|
|
198
|
-
className: (0, boost_ts_1.anyCaseToPascalCase)(name),
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
343
|
const getNameWithScaffoldPattern = async (name) => {
|
|
202
344
|
const configObject = await compiler_1.default.loadConfig();
|
|
203
345
|
switch (configObject.scaffoldPattern) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseController, StatusCode } from "@expressots/core";
|
|
2
|
+
import { controller, {{method}}, requestParam, response } from "inversify-express-utils";
|
|
3
|
+
import { Response } from "express";
|
|
4
|
+
import { {{className}}UseCase } from "./{{fileName}}.usecase";
|
|
5
|
+
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
6
|
+
|
|
7
|
+
@controller("/{{{route}}}")
|
|
8
|
+
class {{className}}Controller extends BaseController {
|
|
9
|
+
|
|
10
|
+
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
|
|
11
|
+
super("{{construct}}-controller")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@{{method}}("/:id")
|
|
15
|
+
execute(@requestParam() payload: I{{className}}RequestDTO, @response() res: Response): I{{className}}ResponseDTO {
|
|
16
|
+
return this.callUseCase(
|
|
17
|
+
this.{{useCase}}UseCase.execute(payload),
|
|
18
|
+
res,
|
|
19
|
+
StatusCode.OK,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { {{className}}Controller };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseController, StatusCode } from "@expressots/core";
|
|
2
|
+
import { controller, {{method}}, requestBody, requestParam, response } from "inversify-express-utils";
|
|
3
|
+
import { Response } from "express";
|
|
4
|
+
import { {{className}}UseCase } from "./{{fileName}}.usecase";
|
|
5
|
+
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
6
|
+
|
|
7
|
+
@controller("/{{{route}}}")
|
|
8
|
+
class {{className}}Controller extends BaseController {
|
|
9
|
+
|
|
10
|
+
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
|
|
11
|
+
super("{{construct}}-controller")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@{{method}}("/:id")
|
|
15
|
+
execute(
|
|
16
|
+
@requestParam("id") id: string,
|
|
17
|
+
@requestBody() payload: I{{className}}RequestDTO,
|
|
18
|
+
@response() res: Response,
|
|
19
|
+
): I{{className}}ResponseDTO {
|
|
20
|
+
return this.callUseCase(
|
|
21
|
+
this.{{useCase}}UseCase.execute(id, payload),
|
|
22
|
+
res,
|
|
23
|
+
StatusCode.OK,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { {{className}}Controller };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseController, StatusCode } from "@expressots/core";
|
|
2
|
+
import { controller, {{method}}, requestBody, response } from "inversify-express-utils";
|
|
3
|
+
import { Response } from "express";
|
|
4
|
+
import { {{className}}UseCase } from "./{{fileName}}.usecase";
|
|
5
|
+
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
6
|
+
|
|
7
|
+
@controller("/{{{route}}}")
|
|
8
|
+
class {{className}}Controller extends BaseController {
|
|
9
|
+
|
|
10
|
+
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
|
|
11
|
+
super("{{construct}}-controller")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@{{method}}("/")
|
|
15
|
+
execute(@requestBody() payload: I{{className}}RequestDTO, @response() res: Response): I{{className}}ResponseDTO {
|
|
16
|
+
return this.callUseCase(
|
|
17
|
+
this.{{useCase}}UseCase.execute(payload),
|
|
18
|
+
res,
|
|
19
|
+
StatusCode.Created,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { {{className}}Controller };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseController, StatusCode } from "@expressots/core";
|
|
2
|
+
import { controller, {{method}}, requestBody, requestParam, response } from "inversify-express-utils";
|
|
3
|
+
import { Response } from "express";
|
|
4
|
+
import { {{className}}UseCase } from "./{{fileName}}.usecase";
|
|
5
|
+
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
6
|
+
|
|
7
|
+
@controller("/{{{route}}}")
|
|
8
|
+
class {{className}}Controller extends BaseController {
|
|
9
|
+
|
|
10
|
+
constructor(private {{useCase}}UseCase: {{className}}UseCase) {
|
|
11
|
+
super("{{construct}}-controller")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@{{method}}("/:id")
|
|
15
|
+
execute(
|
|
16
|
+
@requestParam("id") id: string,
|
|
17
|
+
@requestBody() payload: I{{className}}RequestDTO,
|
|
18
|
+
@response() res: Response,
|
|
19
|
+
): I{{className}}ResponseDTO {
|
|
20
|
+
return this.callUseCase(
|
|
21
|
+
this.{{useCase}}UseCase.execute(id, payload),
|
|
22
|
+
res,
|
|
23
|
+
StatusCode.OK,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { {{className}}Controller };
|