@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
package/bin/new/form.js
CHANGED
|
@@ -61,8 +61,8 @@ function changePackageName({ directory, name, }) {
|
|
|
61
61
|
}
|
|
62
62
|
var Template;
|
|
63
63
|
(function (Template) {
|
|
64
|
-
Template["non-opinionated"] = "Non-Opinionated ::
|
|
65
|
-
Template["opinionated"] = "Opinionated ::
|
|
64
|
+
Template["non-opinionated"] = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.";
|
|
65
|
+
Template["opinionated"] = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)";
|
|
66
66
|
})(Template || (Template = {}));
|
|
67
67
|
const projectForm = async (projectName, args) => {
|
|
68
68
|
let answer;
|
|
@@ -117,8 +117,8 @@ const projectForm = async (projectName, args) => {
|
|
|
117
117
|
name: "template",
|
|
118
118
|
message: "Select a template",
|
|
119
119
|
choices: [
|
|
120
|
-
|
|
121
|
-
"Opinionated ::
|
|
120
|
+
`Opinionated :: Automatically scaffolds resources into a preset project structure. (${chalk_1.default.yellow("Recommended")})`,
|
|
121
|
+
"Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
|
|
122
122
|
],
|
|
123
123
|
},
|
|
124
124
|
{
|
|
@@ -166,6 +166,7 @@ const projectForm = async (projectName, args) => {
|
|
|
166
166
|
await emitter.clone(answer.name);
|
|
167
167
|
}
|
|
168
168
|
catch (err) {
|
|
169
|
+
console.log("\n");
|
|
169
170
|
(0, cli_ui_1.printError)("Project already exists or Folder is not empty", answer.name);
|
|
170
171
|
process.exit(1);
|
|
171
172
|
}
|
|
@@ -185,7 +186,7 @@ const projectForm = async (projectName, args) => {
|
|
|
185
186
|
progressBar.update(100);
|
|
186
187
|
progressBar.stop();
|
|
187
188
|
console.log("\n");
|
|
188
|
-
console.log("🐎 Project
|
|
189
|
+
console.log("🐎 Project", chalk_1.default.green(answer.name), "created successfully!");
|
|
189
190
|
console.log("🤙 Run the following commands to start the project:\n");
|
|
190
191
|
console.log(chalk_1.default.bold.gray(`$ cd ${answer.name}`));
|
|
191
192
|
switch (answer.packageManager) {
|
|
@@ -206,6 +207,7 @@ const projectForm = async (projectName, args) => {
|
|
|
206
207
|
console.log(chalk_1.default.bold.green((0, center_text_1.centerText)("Happy coding!")));
|
|
207
208
|
console.log(chalk_1.default.bold.gray((0, center_text_1.centerText)("Please consider donating to support the project.\n")));
|
|
208
209
|
console.log(chalk_1.default.bold.white((0, center_text_1.centerText)("💖 Sponsor: https://github.com/sponsors/expressots")));
|
|
210
|
+
console.log("\n");
|
|
209
211
|
}
|
|
210
212
|
};
|
|
211
213
|
exports.projectForm = projectForm;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare function addControllerToModule(filePath: string, controllerName: string, controllerPath: string): Promise<void>;
|
|
2
|
-
export { addControllerToModule };
|
|
1
|
+
export declare function addControllerToModule(filePath: string, controllerName: string, controllerPath: string): Promise<void>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
declare function addModuleToContainer(name: string, modulePath?: string, path?: string): Promise<void>;
|
|
2
|
-
|
|
2
|
+
declare function addModuleToContainerNestedPath(name: string, path?: string): Promise<void>;
|
|
3
|
+
export { addModuleToContainer, addModuleToContainerNestedPath };
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.addModuleToContainer = void 0;
|
|
6
|
+
exports.addModuleToContainerNestedPath = exports.addModuleToContainer = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const glob_1 = require("glob");
|
|
9
9
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
@@ -67,14 +67,14 @@ async function addModuleToContainer(name, modulePath, path) {
|
|
|
67
67
|
const modulePathRegex = /^[^/]=$/;
|
|
68
68
|
if (!modulePathRegex.test(modulePath)) {
|
|
69
69
|
if (path.split("/").length > 1) {
|
|
70
|
-
newImport = `import { ${moduleName}Module } from "${usecaseDir}${
|
|
70
|
+
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name.toLowerCase()}/${name.toLowerCase()}.module";`;
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
|
-
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name}.module";`;
|
|
73
|
+
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name.toLowerCase()}.module";`;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name}/${name}.module";`;
|
|
77
|
+
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name}/${name.toLowerCase()}.module";`;
|
|
78
78
|
}
|
|
79
79
|
if (containerData.imports.includes(newImport) &&
|
|
80
80
|
containerData.modules.includes(`${moduleName}Module`)) {
|
|
@@ -94,3 +94,36 @@ async function addModuleToContainer(name, modulePath, path) {
|
|
|
94
94
|
await node_fs_1.default.promises.writeFile(containerData.path, newFileContent, "utf8");
|
|
95
95
|
}
|
|
96
96
|
exports.addModuleToContainer = addModuleToContainer;
|
|
97
|
+
async function addModuleToContainerNestedPath(name, path) {
|
|
98
|
+
const containerData = await validateAppContainer();
|
|
99
|
+
const moduleName = (name[0].toUpperCase() + name.slice(1)).trimStart();
|
|
100
|
+
const { opinionated } = await compiler_1.default.loadConfig();
|
|
101
|
+
let usecaseDir;
|
|
102
|
+
if (opinionated) {
|
|
103
|
+
usecaseDir = `@useCases/`;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
usecaseDir = `./`;
|
|
107
|
+
}
|
|
108
|
+
if (path.endsWith("/")) {
|
|
109
|
+
path = path.slice(0, -1);
|
|
110
|
+
}
|
|
111
|
+
const newImport = `import { ${moduleName}Module } from "${usecaseDir}${path}.module";`;
|
|
112
|
+
if (containerData.imports.includes(newImport) &&
|
|
113
|
+
containerData.modules.includes(`${moduleName}Module`)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
containerData.imports.push(newImport);
|
|
117
|
+
containerData.modules.push(`${moduleName}Module`);
|
|
118
|
+
const newModule = containerData.modules.join(", ");
|
|
119
|
+
const newModuleDeclaration = `.create([${newModule}]`;
|
|
120
|
+
const newFileContent = [
|
|
121
|
+
...containerData.imports,
|
|
122
|
+
...containerData.notImports,
|
|
123
|
+
]
|
|
124
|
+
.join("\n")
|
|
125
|
+
.replace(containerData.regex, newModuleDeclaration);
|
|
126
|
+
console.log(" ", chalk_1.default.greenBright(`[container]`.padEnd(14)), chalk_1.default.bold.white(`${moduleName}Module added to ${APP_CONTAINER}! ✔️`));
|
|
127
|
+
await node_fs_1.default.promises.writeFile(containerData.path, newFileContent, "utf8");
|
|
128
|
+
}
|
|
129
|
+
exports.addModuleToContainerNestedPath = addModuleToContainerNestedPath;
|
package/bin/utils/cli-ui.d.ts
CHANGED
package/bin/utils/cli-ui.js
CHANGED
|
@@ -3,9 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.printError = void 0;
|
|
6
|
+
exports.printGenerateSuccess = exports.printGenerateError = exports.printError = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
function printError(message, component) {
|
|
9
|
-
console.error(chalk_1.default.red(
|
|
9
|
+
console.error(chalk_1.default.red(`${message}:`, chalk_1.default.bold(chalk_1.default.white(`[${component}] ❌`))));
|
|
10
10
|
}
|
|
11
11
|
exports.printError = printError;
|
|
12
|
+
async function printGenerateError(schematic, file) {
|
|
13
|
+
console.error(" ", chalk_1.default.redBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.white(`${file.split(".")[0]} not created! ❌`));
|
|
14
|
+
}
|
|
15
|
+
exports.printGenerateError = printGenerateError;
|
|
16
|
+
async function printGenerateSuccess(schematic, file) {
|
|
17
|
+
console.log(" ", chalk_1.default.greenBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.white(`${file.split(".")[0]} created! ✔️`));
|
|
18
|
+
}
|
|
19
|
+
exports.printGenerateSuccess = printGenerateSuccess;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function verifyIfFileExists(path: string): Promise<void>;
|
|
1
|
+
declare function verifyIfFileExists(path: string, schematic?: string): Promise<void>;
|
|
2
2
|
export { verifyIfFileExists };
|
|
@@ -7,20 +7,22 @@ exports.verifyIfFileExists = void 0;
|
|
|
7
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const cli_ui_1 = require("./cli-ui");
|
|
10
|
-
async function verifyIfFileExists(path) {
|
|
10
|
+
async function verifyIfFileExists(path, schematic) {
|
|
11
11
|
const fileExists = node_fs_1.default.existsSync(path);
|
|
12
|
+
const fileName = path.split("/").pop();
|
|
12
13
|
if (fileExists) {
|
|
13
14
|
const answer = await inquirer_1.default.prompt([
|
|
14
15
|
{
|
|
15
16
|
type: "confirm",
|
|
16
17
|
name: "confirm",
|
|
17
|
-
message:
|
|
18
|
+
message: `File [${fileName}] exists. Overwrite?`,
|
|
18
19
|
default: true,
|
|
19
20
|
},
|
|
20
21
|
]);
|
|
21
|
-
const fileName = path.split("/").pop();
|
|
22
22
|
if (!answer.confirm) {
|
|
23
|
-
|
|
23
|
+
schematic
|
|
24
|
+
? (0, cli_ui_1.printGenerateError)(schematic, fileName)
|
|
25
|
+
: (0, cli_ui_1.printError)("File not created!", fileName);
|
|
24
26
|
process.exit(1);
|
|
25
27
|
}
|
|
26
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"build": "npm run clean && tsc -p tsconfig.json && yarn cp:templates && chmod +x ./bin/cli.js",
|
|
39
39
|
"cp:templates": "cp -r ./src/generate/templates ./bin/generate/templates && cp -r ./src/providers/prisma/templates ./bin/providers/prisma/templates",
|
|
40
40
|
"clean": "rimraf ./bin",
|
|
41
|
+
"prepublish": "npm run build && npm pack",
|
|
41
42
|
"format": "prettier --write \"./src/**/*.ts\" --cache",
|
|
42
43
|
"lint": "eslint \"./src/**/*.ts\"",
|
|
43
44
|
"lint:fix": "eslint \"./src/**/*.ts\" --fix",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"@expressots/boost-ts": "1.1.1",
|
|
51
52
|
"chalk-animation": "2.0.3",
|
|
52
53
|
"cli-progress": "3.11.2",
|
|
54
|
+
"cli-table3": "^0.6.4",
|
|
53
55
|
"degit": "2.8.4",
|
|
54
56
|
"glob": "10.2.6",
|
|
55
57
|
"inquirer": "8.0.0",
|
|
@@ -77,7 +79,8 @@
|
|
|
77
79
|
"husky": "^8.0.3",
|
|
78
80
|
"prettier": "^2.8.4",
|
|
79
81
|
"release-it": "^16.1.5",
|
|
80
|
-
"rimraf": "^
|
|
82
|
+
"rimraf": "^5.0.5",
|
|
83
|
+
"shx": "^0.3.4",
|
|
81
84
|
"ts-node-dev": "^2.0.0",
|
|
82
85
|
"typescript": "^4.9.5",
|
|
83
86
|
"vite": "^4.4.9",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { provide } from "inversify-binding-decorators";
|
|
2
|
-
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
3
|
-
|
|
4
|
-
@provide({{className}}UseCase)
|
|
5
|
-
export class {{className}}UseCase {
|
|
6
|
-
execute(payload: I{{className}}RequestDTO): I{{className}}ResponseDTO {
|
|
7
|
-
return "Use Case";
|
|
8
|
-
}
|
|
9
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|