@expressots/cli 1.2.1 → 1.3.0-rc-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 +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 -72
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseController, StatusCode } from "@expressots/core";
|
|
2
|
-
import { controller,
|
|
2
|
+
import { controller, {{method}}, response } from "inversify-express-utils";
|
|
3
|
+
import { Response } from "express";
|
|
3
4
|
import { {{className}}UseCase } from "./{{fileName}}.usecase";
|
|
4
5
|
import { I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
5
6
|
|
|
@@ -10,13 +11,13 @@ class {{className}}Controller extends BaseController {
|
|
|
10
11
|
super("{{construct}}-controller")
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
@
|
|
14
|
-
execute(@response() res:
|
|
14
|
+
@{{method}}("/")
|
|
15
|
+
execute(@response() res: Response): I{{className}}ResponseDTO {
|
|
15
16
|
return this.callUseCase(
|
|
16
17
|
this.{{useCase}}UseCase.execute(),
|
|
17
18
|
res,
|
|
18
19
|
StatusCode.OK,
|
|
19
|
-
|
|
20
|
+
);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseController } from "@expressots/core";
|
|
2
|
-
import { controller,
|
|
2
|
+
import { controller, {{method}}, response } from "inversify-express-utils";
|
|
3
|
+
import { Response } from "express";
|
|
3
4
|
|
|
4
5
|
@controller("/{{{route}}}")
|
|
5
6
|
class {{className}}Controller extends BaseController {
|
|
@@ -8,8 +9,8 @@ class {{className}}Controller extends BaseController {
|
|
|
8
9
|
super("{{construct}}-controller")
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
@
|
|
12
|
-
execute(@response() res:
|
|
12
|
+
@{{method}}("/")
|
|
13
|
+
execute(@response() res: Response) {
|
|
13
14
|
return res.send("Hello Expresso TS");
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { provide } from "inversify-binding-decorators";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
@provide({{className}})
|
|
5
|
+
class {{className}} {
|
|
6
|
+
public id: string;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.id = randomUUID();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { {{className}} };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { provide } from "inversify-binding-decorators";
|
|
2
|
+
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
3
|
+
|
|
4
|
+
@provide({{className}}UseCase)
|
|
5
|
+
class {{className}}UseCase {
|
|
6
|
+
|
|
7
|
+
constructor() {}
|
|
8
|
+
|
|
9
|
+
execute(id: string, payload: I{{className}}RequestDTO): I{{className}}ResponseDTO {
|
|
10
|
+
return "your use case";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { {{className}}UseCase };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { provide } from "inversify-binding-decorators";
|
|
2
|
+
import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
|
|
3
|
+
|
|
4
|
+
@provide({{className}}UseCase)
|
|
5
|
+
class {{className}}UseCase {
|
|
6
|
+
|
|
7
|
+
constructor() {}
|
|
8
|
+
|
|
9
|
+
execute(payload: I{{className}}RequestDTO): I{{className}}ResponseDTO {
|
|
10
|
+
return "your use case";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { {{className}}UseCase };
|
package/bin/info/cli.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.infoProject = void 0;
|
|
4
|
+
const form_1 = require("./form");
|
|
5
|
+
const infoProject = () => {
|
|
6
|
+
return {
|
|
7
|
+
command: "info",
|
|
8
|
+
describe: "Displays project details",
|
|
9
|
+
aliases: ["i"],
|
|
10
|
+
handler: async () => {
|
|
11
|
+
await (0, form_1.infoForm)();
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.infoProject = infoProject;
|
package/bin/info/form.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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.infoForm = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
const cli_1 = require("../cli");
|
|
12
|
+
const cli_ui_1 = require("../utils/cli-ui");
|
|
13
|
+
function getInfosFromPackage() {
|
|
14
|
+
try {
|
|
15
|
+
// Get the absolute path of the input directory parameter
|
|
16
|
+
const absDirPath = path_1.default.resolve();
|
|
17
|
+
// Load the package.json file
|
|
18
|
+
const packageJsonPath = path_1.default.join(absDirPath, "package.json");
|
|
19
|
+
const fileContents = fs_1.default.readFileSync(packageJsonPath, "utf-8");
|
|
20
|
+
const packageJson = JSON.parse(fileContents);
|
|
21
|
+
console.log(chalk_1.default.green("ExpressoTS Project:"));
|
|
22
|
+
console.log(chalk_1.default.bold(`\tName: ${packageJson.name}`));
|
|
23
|
+
console.log(chalk_1.default.bold(`\tDescription: ${packageJson.description}`));
|
|
24
|
+
console.log(chalk_1.default.bold(`\tVersion: ${packageJson.version}`));
|
|
25
|
+
console.log(chalk_1.default.bold(`\tAuthor: ${packageJson.author}`));
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
(0, cli_ui_1.printError)("No project information available.", "package.json not found!");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const infoForm = async () => {
|
|
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}`));
|
|
37
|
+
getInfosFromPackage();
|
|
38
|
+
};
|
|
39
|
+
exports.infoForm = infoForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cli";
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cli"), exports);
|
package/bin/new/cli.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.createProject = void 0;
|
|
|
4
4
|
const form_1 = require("./form");
|
|
5
5
|
const createProject = () => {
|
|
6
6
|
return {
|
|
7
|
-
command: "new <project-name> [package-manager] [template]",
|
|
8
|
-
describe: "Create a new
|
|
7
|
+
command: "new <project-name> [package-manager] [template] [directory]",
|
|
8
|
+
describe: "Create a new project",
|
|
9
9
|
builder: (yargs) => {
|
|
10
10
|
yargs
|
|
11
11
|
.positional("project-name", {
|
|
@@ -23,11 +23,18 @@ const createProject = () => {
|
|
|
23
23
|
type: "string",
|
|
24
24
|
choices: ["npm", "yarn", "pnpm"],
|
|
25
25
|
alias: "p",
|
|
26
|
-
})
|
|
26
|
+
})
|
|
27
|
+
.option("directory", {
|
|
28
|
+
describe: "The directory for new project",
|
|
29
|
+
type: "string",
|
|
30
|
+
alias: "d",
|
|
31
|
+
})
|
|
32
|
+
.implies("package-manager", "template")
|
|
33
|
+
.implies("template", "package-manager");
|
|
27
34
|
return yargs;
|
|
28
35
|
},
|
|
29
|
-
handler: async ({ projectName, packageManager, template }) => {
|
|
30
|
-
return await (0, form_1.projectForm)(projectName, packageManager, template);
|
|
36
|
+
handler: async ({ projectName, packageManager, template, directory }) => {
|
|
37
|
+
return await (0, form_1.projectForm)(projectName, [packageManager, template, directory]);
|
|
31
38
|
},
|
|
32
39
|
};
|
|
33
40
|
};
|
package/bin/new/form.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
declare
|
|
2
|
-
"non-opinionated" = "Non-Opinionated :: A simple ExpressoTS project.",
|
|
3
|
-
opinionated = "Opinionated :: A complete ExpressoTS project with an opinionated structure and features."
|
|
4
|
-
}
|
|
5
|
-
declare const enum PackageManager {
|
|
6
|
-
npm = 0,
|
|
7
|
-
yarn = 1,
|
|
8
|
-
pnpm = 2
|
|
9
|
-
}
|
|
10
|
-
declare const projectForm: (projectName: string, packageManager: PackageManager, template: keyof typeof Template) => Promise<void>;
|
|
1
|
+
declare const projectForm: (projectName: string, args: any[]) => Promise<void>;
|
|
11
2
|
export { projectForm };
|
package/bin/new/form.js
CHANGED
|
@@ -4,13 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.projectForm = void 0;
|
|
7
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const degit_1 = __importDefault(require("degit"));
|
|
10
8
|
const child_process_1 = require("child_process");
|
|
11
9
|
const cli_progress_1 = require("cli-progress");
|
|
10
|
+
const degit_1 = __importDefault(require("degit"));
|
|
11
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
12
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
13
|
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const center_text_1 = require("../utils/center-text");
|
|
15
|
+
const cli_ui_1 = require("../utils/cli-ui");
|
|
14
16
|
async function packageManagerInstall({ packageManager, directory, progressBar, }) {
|
|
15
17
|
return new Promise((resolve, reject) => {
|
|
16
18
|
const isWindows = process.platform === "win32";
|
|
@@ -30,7 +32,7 @@ async function packageManagerInstall({ packageManager, directory, progressBar, }
|
|
|
30
32
|
resolve("Installation Done!");
|
|
31
33
|
}
|
|
32
34
|
else {
|
|
33
|
-
reject(new Error(
|
|
35
|
+
reject(new Error(`${packageManager} install exited with code ${code}`));
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
38
|
});
|
|
@@ -40,11 +42,11 @@ async function checkIfPackageManagerExists(packageManager) {
|
|
|
40
42
|
(0, child_process_1.execSync)(`${packageManager} --version`);
|
|
41
43
|
return true;
|
|
42
44
|
}
|
|
43
|
-
catch (
|
|
44
|
-
|
|
45
|
+
catch (error) {
|
|
46
|
+
(0, cli_ui_1.printError)("Package manager not found!", packageManager);
|
|
47
|
+
process.exit(1);
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
|
-
// Change the package.json name to the user's project name
|
|
48
50
|
function changePackageName({ directory, name, }) {
|
|
49
51
|
// Get the absolute path of the input directory parameter
|
|
50
52
|
const absDirPath = node_path_1.default.resolve(directory);
|
|
@@ -62,8 +64,26 @@ var Template;
|
|
|
62
64
|
Template["non-opinionated"] = "Non-Opinionated :: A simple ExpressoTS project.";
|
|
63
65
|
Template["opinionated"] = "Opinionated :: A complete ExpressoTS project with an opinionated structure and features.";
|
|
64
66
|
})(Template || (Template = {}));
|
|
65
|
-
const projectForm = async (projectName,
|
|
67
|
+
const projectForm = async (projectName, args) => {
|
|
66
68
|
let answer;
|
|
69
|
+
const projName = projectName;
|
|
70
|
+
let packageManager;
|
|
71
|
+
let template;
|
|
72
|
+
let directory;
|
|
73
|
+
// Resolving the argument order problem
|
|
74
|
+
for (const arg of args) {
|
|
75
|
+
if (args.length >= 3) {
|
|
76
|
+
if (arg === "npm" || arg === "yarn" || arg === "pnpm") {
|
|
77
|
+
packageManager = arg;
|
|
78
|
+
}
|
|
79
|
+
else if (arg === "non-opinionated" || arg === "opinionated") {
|
|
80
|
+
template = arg;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
directory = arg;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
67
87
|
if (packageManager && template) {
|
|
68
88
|
answer = {
|
|
69
89
|
name: projectName,
|
|
@@ -106,17 +126,23 @@ const projectForm = async (projectName, packageManager, template) => {
|
|
|
106
126
|
},
|
|
107
127
|
]);
|
|
108
128
|
}
|
|
129
|
+
if (directory) {
|
|
130
|
+
if (!node_fs_1.default.existsSync(node_path_1.default.join(directory, answer.name))) {
|
|
131
|
+
answer.name = node_path_1.default.join(directory, answer.name);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
(0, cli_ui_1.printError)("Directory already exists", directory);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
109
138
|
// Hashmap of templates and their directories
|
|
110
139
|
const templates = {
|
|
111
140
|
"Non-Opinionated": "non_opinionated",
|
|
112
141
|
Opinionated: "opinionated",
|
|
113
142
|
};
|
|
114
143
|
if (answer.confirm) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
console.log(chalk_1.default.red(err.message));
|
|
118
|
-
process.exit(1);
|
|
119
|
-
});
|
|
144
|
+
await checkIfPackageManagerExists(answer.packageManager);
|
|
145
|
+
console.log("\n");
|
|
120
146
|
const progressBar = new cli_progress_1.SingleBar({
|
|
121
147
|
format: "Progress |" + chalk_1.default.green("{bar}") + "| {percentage}% || {doing}",
|
|
122
148
|
hideCursor: true,
|
|
@@ -125,12 +151,17 @@ const projectForm = async (projectName, packageManager, template) => {
|
|
|
125
151
|
doing: "Cloning project",
|
|
126
152
|
});
|
|
127
153
|
const [_, template] = answer.template.match(/(.*) ::/);
|
|
128
|
-
|
|
129
|
-
|
|
154
|
+
try {
|
|
155
|
+
const emitter = (0, degit_1.default)(`expressots/expressots/templates/${templates[template]}`);
|
|
156
|
+
await emitter.clone(answer.name);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
(0, cli_ui_1.printError)("Project already exists or Folder is not empty", answer.name);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
130
162
|
progressBar.update(50, {
|
|
131
163
|
doing: "Installing dependencies",
|
|
132
164
|
});
|
|
133
|
-
// Run the package manager install in the directory
|
|
134
165
|
await packageManagerInstall({
|
|
135
166
|
packageManager: answer.packageManager,
|
|
136
167
|
directory: answer.name,
|
|
@@ -139,14 +170,29 @@ const projectForm = async (projectName, packageManager, template) => {
|
|
|
139
170
|
progressBar.update(90);
|
|
140
171
|
changePackageName({
|
|
141
172
|
directory: answer.name,
|
|
142
|
-
name:
|
|
173
|
+
name: projName,
|
|
143
174
|
});
|
|
144
175
|
progressBar.update(100);
|
|
145
176
|
progressBar.stop();
|
|
146
|
-
console.log(
|
|
147
|
-
console.log("
|
|
148
|
-
console.log(
|
|
149
|
-
console.log(chalk_1.default.bold(`${answer.
|
|
177
|
+
console.log("\n");
|
|
178
|
+
console.log("🐎 Project ", chalk_1.default.green(projName), "created successfully!");
|
|
179
|
+
console.log("🤙 Run the following commands to start the project:\n");
|
|
180
|
+
console.log(chalk_1.default.bold.gray(`$ cd ${answer.name}`));
|
|
181
|
+
switch (answer.packageManager) {
|
|
182
|
+
case "npm":
|
|
183
|
+
console.log(chalk_1.default.bold.gray("$ npm run dev"));
|
|
184
|
+
break;
|
|
185
|
+
case "yarn":
|
|
186
|
+
console.log(chalk_1.default.bold.gray("$ yarn dev"));
|
|
187
|
+
break;
|
|
188
|
+
case "pnpm":
|
|
189
|
+
console.log(chalk_1.default.bold.gray("$ pnpm run dev"));
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
console.log("\n");
|
|
193
|
+
console.log(chalk_1.default.bold.green((0, center_text_1.centerText)("Happy coding!")));
|
|
194
|
+
console.log(chalk_1.default.bold.gray((0, center_text_1.centerText)("Please consider donating to support the project.\n")));
|
|
195
|
+
console.log(chalk_1.default.bold.white((0, center_text_1.centerText)("💖 Sponsor: https://github.com/sponsors/expressots")));
|
|
150
196
|
}
|
|
151
197
|
};
|
|
152
198
|
exports.projectForm = projectForm;
|
|
@@ -22,7 +22,7 @@ async function addControllerToModule(filePath, controllerName, controllerPath) {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
imports.push(newImport);
|
|
25
|
-
const moduleDeclarationRegex = /CreateModule\(\[(
|
|
25
|
+
const moduleDeclarationRegex = /CreateModule\(\s*\[([\s\S]*?)]/;
|
|
26
26
|
const moduleDeclarationMatch = fileContent.match(moduleDeclarationRegex);
|
|
27
27
|
if (!moduleDeclarationMatch) {
|
|
28
28
|
return;
|
|
@@ -33,7 +33,7 @@ async function addControllerToModule(filePath, controllerName, controllerPath) {
|
|
|
33
33
|
}
|
|
34
34
|
controllers.push(controllerName);
|
|
35
35
|
const newControllers = controllers.join(', ');
|
|
36
|
-
const newModuleDeclaration = `CreateModule([${newControllers}]
|
|
36
|
+
const newModuleDeclaration = `CreateModule([${newControllers}]`;
|
|
37
37
|
const newFileContent = [...imports, ...notImports].join('\n').replace(moduleDeclarationRegex, newModuleDeclaration);
|
|
38
38
|
await node_fs_1.default.promises.writeFile(filePath, newFileContent, 'utf8');
|
|
39
39
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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.addModuleToContainer = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const glob_1 = require("glob");
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const cli_ui_1 = require("./cli-ui");
|
|
11
|
+
const compiler_1 = __importDefault(require("./compiler"));
|
|
12
|
+
const APP_CONTAINER = "app.container.ts";
|
|
13
|
+
async function validateAppContainer() {
|
|
14
|
+
const { sourceRoot } = await compiler_1.default.loadConfig();
|
|
15
|
+
const imports = [];
|
|
16
|
+
const notImports = [];
|
|
17
|
+
const path = (0, glob_1.globSync)(`./${sourceRoot}/${APP_CONTAINER}`, { absolute: true, ignore: '**/node_modules/**' });
|
|
18
|
+
if (!path.length) {
|
|
19
|
+
(0, cli_ui_1.printError)('Module not added to Container. Container file not found!', APP_CONTAINER);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
const fileContent = await node_fs_1.default.promises.readFile(path[0], 'utf8');
|
|
23
|
+
fileContent.split('\n').forEach((line) => {
|
|
24
|
+
if (line.startsWith('import')) {
|
|
25
|
+
imports.push(line);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
notImports.push(line);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// Validate the file content
|
|
32
|
+
const moduleDeclarationRegex = /.create\(\s*\[([\s\S]*?)]/;
|
|
33
|
+
const moduleDeclarationMatch = fileContent.match(moduleDeclarationRegex);
|
|
34
|
+
if (!moduleDeclarationMatch) {
|
|
35
|
+
(0, cli_ui_1.printError)('Container format incorrect!', APP_CONTAINER);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const modules = moduleDeclarationMatch[1].trim().split(',').filter((m) => m.trim() !== "").map((m) => m.trim());
|
|
39
|
+
return {
|
|
40
|
+
regex: moduleDeclarationRegex,
|
|
41
|
+
path: path[0],
|
|
42
|
+
content: moduleDeclarationMatch,
|
|
43
|
+
modules,
|
|
44
|
+
imports,
|
|
45
|
+
notImports
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function addModuleToContainer(name, modulePath, path) {
|
|
49
|
+
const containerData = await validateAppContainer();
|
|
50
|
+
const moduleName = (name[0].toUpperCase() + name.slice(1)).trimStart();
|
|
51
|
+
const { opinionated } = await compiler_1.default.loadConfig();
|
|
52
|
+
let usecaseDir;
|
|
53
|
+
if (opinionated) {
|
|
54
|
+
usecaseDir = `@useCases/`;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
usecaseDir = `./`;
|
|
58
|
+
}
|
|
59
|
+
let newImport = "";
|
|
60
|
+
const modulePathRegex = /^[^/]=$/;
|
|
61
|
+
if (!modulePathRegex.test(modulePath)) {
|
|
62
|
+
if (path.split('/').length > 1) {
|
|
63
|
+
newImport = `import { ${moduleName}Module } from "${usecaseDir}${modulePath}/${name}.module";`;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name}.module";`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
newImport = `import { ${moduleName}Module } from "${usecaseDir}${name}/${name}.module";`;
|
|
71
|
+
}
|
|
72
|
+
if (containerData.imports.includes(newImport) && containerData.modules.includes(`${moduleName}Module`)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
containerData.imports.push(newImport);
|
|
76
|
+
containerData.modules.push(`${moduleName}Module`);
|
|
77
|
+
const newModule = containerData.modules.join(', ');
|
|
78
|
+
const newModuleDeclaration = `.create([${newModule}]`;
|
|
79
|
+
const newFileContent = [...containerData.imports, ...containerData.notImports]
|
|
80
|
+
.join('\n').replace(containerData.regex, newModuleDeclaration);
|
|
81
|
+
console.log(" ", chalk_1.default.greenBright(`[container]`.padEnd(14)), chalk_1.default.bold.white(`${moduleName}Module added to ${APP_CONTAINER}! ✔️`));
|
|
82
|
+
await node_fs_1.default.promises.writeFile(containerData.path, newFileContent, 'utf8');
|
|
83
|
+
}
|
|
84
|
+
exports.addModuleToContainer = addModuleToContainer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.centerText = void 0;
|
|
4
|
+
function centerText(text) {
|
|
5
|
+
const terminalWidth = process.stdout.columns;
|
|
6
|
+
const padding = Math.floor((terminalWidth - text.length) / 2);
|
|
7
|
+
const centeredText = ' '.repeat(padding) + text;
|
|
8
|
+
return centeredText;
|
|
9
|
+
}
|
|
10
|
+
exports.centerText = centerText;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printError(message: string, component: string): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
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.printError = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
function printError(message, component) {
|
|
9
|
+
console.error(chalk_1.default.red(`\n\n😞 ${message}:`, chalk_1.default.white(`[${component}]`)));
|
|
10
|
+
}
|
|
11
|
+
exports.printError = printError;
|
package/bin/utils/compiler.js
CHANGED
|
@@ -28,9 +28,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const node_fs_1 = require("node:fs");
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const cli_ui_1 = require("./cli-ui");
|
|
31
32
|
/**
|
|
32
33
|
* The path to the expressots.config.ts file
|
|
33
34
|
*/
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
36
|
const EXPRESSOTS_CONFIG = path_1.default.join(process.cwd(), "expressots.config.ts");
|
|
35
37
|
/**
|
|
36
38
|
* The config object
|
|
@@ -64,6 +66,7 @@ class Compiler {
|
|
|
64
66
|
return compiler;
|
|
65
67
|
}
|
|
66
68
|
static interopRequireDefault(obj) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
67
70
|
const module = require(obj);
|
|
68
71
|
return module && module.__esModule ? module : { default: module };
|
|
69
72
|
}
|
|
@@ -73,8 +76,10 @@ class Compiler {
|
|
|
73
76
|
if (exists)
|
|
74
77
|
return configPath;
|
|
75
78
|
const parentDir = path_1.default.join(dir, "..");
|
|
76
|
-
if (parentDir === dir)
|
|
77
|
-
|
|
79
|
+
if (parentDir === dir) {
|
|
80
|
+
(0, cli_ui_1.printError)("No config file found!", "expressots.config.ts");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
78
83
|
return Compiler.findConfig(parentDir);
|
|
79
84
|
}
|
|
80
85
|
static async loadConfig() {
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.verifyIfFileExists = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const cli_ui_1 = require("./cli-ui");
|
|
10
10
|
async function verifyIfFileExists(path) {
|
|
11
11
|
const fileExists = node_fs_1.default.existsSync(path);
|
|
12
12
|
if (fileExists) {
|
|
@@ -18,8 +18,9 @@ async function verifyIfFileExists(path) {
|
|
|
18
18
|
default: true,
|
|
19
19
|
},
|
|
20
20
|
]);
|
|
21
|
+
const fileName = path.split('/').pop();
|
|
21
22
|
if (!answer.confirm) {
|
|
22
|
-
|
|
23
|
+
(0, cli_ui_1.printError)('File not created!', fileName);
|
|
23
24
|
process.exit(1);
|
|
24
25
|
}
|
|
25
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-rc-1",
|
|
4
4
|
"description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=18.10.0"
|
|
15
15
|
},
|
|
16
16
|
"funding": {
|
|
17
|
-
"type": "",
|
|
18
|
-
"url": ""
|
|
17
|
+
"type": "github",
|
|
18
|
+
"url": "https://github.com/sponsors/expressots"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"chalk-animation": "^1",
|
|
47
47
|
"cli-progress": "^3.11.2",
|
|
48
48
|
"degit": "^2.8.4",
|
|
49
|
+
"glob": "^10.2.6",
|
|
49
50
|
"inquirer": "^8.0.0",
|
|
50
51
|
"mustache": "^4.2.0",
|
|
51
52
|
"ts-node": "^10.9.1",
|