@expressots/cli 1.8.1 → 1.9.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.
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
 
3
3
  @provide({{className}}{{schematic}})
4
4
  export class {{className}}{{schematic}} {}
@@ -1,6 +1,5 @@
1
- import { ExpressoMiddleware } from "@expressots/core";
1
+ import { ExpressoMiddleware, provide } from "@expressots/core";
2
2
  import { NextFunction, Request, Response } from "express";
3
- import { provide } from "inversify-binding-decorators";
4
3
 
5
4
  @provide({{className}}{{schematic}})
6
5
  export class {{className}}{{schematic}} extends ExpressoMiddleware {
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
 
3
3
  @provide({{className}}{{schematic}})
4
4
  export class {{className}}{{schematic}} {}
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
 
3
3
  @provide({{className}}{{schematic}})
4
4
  export class {{className}}{{schematic}} {}
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
  import { randomUUID } from "node:crypto";
3
3
 
4
4
  @provide({{className}}Entity)
@@ -1,6 +1,5 @@
1
- import { ExpressoMiddleware } from "@expressots/core";
1
+ import { ExpressoMiddleware, provide } from "@expressots/core";
2
2
  import { NextFunction, Request, Response } from "express";
3
- import { provide } from "inversify-binding-decorators";
4
3
 
5
4
  @provide({{className}}Middleware)
6
5
  export class {{className}}Middleware extends ExpressoMiddleware {
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
 
3
3
  @provide({{className}}Provider)
4
4
  export class {{className}}Provider {}
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
 
3
3
  @provide({{className}}UseCase)
4
4
  export class {{className}}UseCase {
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
  import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
3
3
 
4
4
  @provide({{className}}UseCase)
@@ -1,4 +1,4 @@
1
- import { provide } from "inversify-binding-decorators";
1
+ import { provide } from "@expressots/core";
2
2
 
3
3
  @provide({{className}}UseCase)
4
4
  export class {{className}}UseCase {
@@ -106,7 +106,9 @@ async function generateUseCase(outputPath, className, moduleName, path, fileName
106
106
  moduleName,
107
107
  path,
108
108
  fileName,
109
- schematic: (0, boost_ts_1.anyCaseToPascalCase)(schematic),
109
+ schematic: schematic === "usecase"
110
+ ? "UseCase"
111
+ : (0, boost_ts_1.anyCaseToPascalCase)(schematic),
110
112
  },
111
113
  },
112
114
  });
package/bin/new/cli.js CHANGED
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createProject = void 0;
7
7
  const form_1 = require("./form");
8
8
  const semver_1 = __importDefault(require("semver"));
9
+ const cli_ui_1 = require("../utils/cli-ui");
10
+ const chalk_1 = __importDefault(require("chalk"));
9
11
  const packageManagers = [
10
12
  "npm",
11
13
  "yarn",
@@ -40,11 +42,11 @@ const commandOptions = (yargs) => {
40
42
  };
41
43
  const checkNodeVersion = () => {
42
44
  const minVersion = "18.0.0";
43
- const maxVersion = "20.7.0";
45
+ const maxVersion = "22.5.1";
44
46
  const currentVersion = process.version;
45
47
  if (!semver_1.default.satisfies(currentVersion, `>=${minVersion} <=${maxVersion}`)) {
46
- console.error(`Node.js version ${currentVersion} is not supported. Please use a version between ${minVersion} and ${maxVersion}.`);
47
- process.exit(1);
48
+ const msg = `Node.js version [${chalk_1.default.bold(chalk_1.default.white(currentVersion))}] is not tested. Please use a version between ${minVersion} and ${maxVersion}.`;
49
+ (0, cli_ui_1.printWarning)(msg);
48
50
  }
49
51
  };
50
52
  const createProject = () => {
package/bin/new/form.d.ts CHANGED
@@ -1,2 +1,14 @@
1
- declare const projectForm: (projectName: string, args: any[]) => Promise<void>;
1
+ declare enum Template {
2
+ "non-opinionated" = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
3
+ opinionated = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)"
4
+ }
5
+ declare const enum PackageManager {
6
+ npm = "npm",
7
+ yarn = "yarn",
8
+ pnpm = "pnpm",
9
+ bun = "bun"
10
+ }
11
+ type TemplateKeys = keyof typeof Template;
12
+ type ProjectFormArgs = [PackageManager, TemplateKeys, string];
13
+ declare const projectForm: (projectName: string, args: ProjectFormArgs) => Promise<void>;
2
14
  export { projectForm };
package/bin/new/form.js CHANGED
@@ -19,10 +19,15 @@ async function packageManagerInstall({ packageManager, directory, progressBar, }
19
19
  const command = isWindows
20
20
  ? `${packageManager}.cmd`
21
21
  : packageManager;
22
- const installProcess = (0, node_child_process_1.spawn)(command, ["install"], {
22
+ const installProcess = (0, node_child_process_1.spawn)(command, ["install", "--prefer-offline"], {
23
23
  cwd: directory,
24
+ shell: true,
25
+ timeout: 600000,
24
26
  });
27
+ // eslint-disable-next-line prefer-const
28
+ let installTimeout;
25
29
  installProcess.on("error", (error) => {
30
+ clearTimeout(installTimeout);
26
31
  reject(new Error(`Failed to start subprocess: ${error.message}`));
27
32
  });
28
33
  installProcess.stdout?.on("data", (data) => {
@@ -38,6 +43,7 @@ async function packageManagerInstall({ packageManager, directory, progressBar, }
38
43
  }
39
44
  });
40
45
  installProcess.on("close", (code) => {
46
+ clearTimeout(installTimeout);
41
47
  if (code === 0) {
42
48
  resolve("Installation Done!");
43
49
  }
@@ -45,6 +51,10 @@ async function packageManagerInstall({ packageManager, directory, progressBar, }
45
51
  reject(new Error(`${packageManager} install exited with code ${code}`));
46
52
  }
47
53
  });
54
+ installTimeout = setTimeout(() => {
55
+ installProcess.kill("SIGKILL");
56
+ reject(new Error("Installation took too long. Aborted!"));
57
+ }, 600000);
48
58
  });
49
59
  }
50
60
  async function checkIfPackageManagerExists(packageManager) {
@@ -58,15 +68,11 @@ async function checkIfPackageManagerExists(packageManager) {
58
68
  }
59
69
  }
60
70
  function changePackageName({ directory, name, }) {
61
- // Get the absolute path of the input directory parameter
62
71
  const absDirPath = node_path_1.default.resolve(directory);
63
- // Load the package.json file
64
72
  const packageJsonPath = node_path_1.default.join(absDirPath, "package.json");
65
73
  const fileContents = node_fs_1.default.readFileSync(packageJsonPath, "utf-8");
66
74
  const packageJson = JSON.parse(fileContents);
67
- // Change the name
68
75
  packageJson.name = name;
69
- // Save the package.json file
70
76
  node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
71
77
  }
72
78
  function renameEnvFile(directory) {
@@ -90,27 +96,7 @@ var Template;
90
96
  })(Template || (Template = {}));
91
97
  const projectForm = async (projectName, args) => {
92
98
  let answer;
93
- const projName = projectName;
94
- let packageManager;
95
- let template;
96
- let directory;
97
- // Resolving the argument order problem
98
- for (const arg of args) {
99
- if (args.length >= 3) {
100
- if (arg === "npm" ||
101
- arg === "yarn" ||
102
- arg === "pnpm" ||
103
- arg === "bun") {
104
- packageManager = arg;
105
- }
106
- else if (arg === "non-opinionated" || arg === "opinionated") {
107
- template = arg;
108
- }
109
- else {
110
- directory = arg;
111
- }
112
- }
113
- }
99
+ const [packageManager, template, directory] = args;
114
100
  if (packageManager && template) {
115
101
  answer = {
116
102
  name: projectName,
@@ -205,7 +191,7 @@ const projectForm = async (projectName, args) => {
205
191
  progressBar.update(90);
206
192
  changePackageName({
207
193
  directory: answer.name,
208
- name: projName,
194
+ name: projectName,
209
195
  });
210
196
  renameEnvFile(answer.name);
211
197
  progressBar.update(100);
@@ -1,3 +1,4 @@
1
1
  export declare function printError(message: string, component: string): void;
2
+ export declare function printWarning(message: string, component?: string): void;
2
3
  export declare function printGenerateError(schematic: string, file: string): Promise<void>;
3
4
  export declare function printGenerateSuccess(schematic: string, file: string): Promise<void>;
@@ -3,12 +3,21 @@ 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.printGenerateSuccess = exports.printGenerateError = exports.printError = void 0;
6
+ exports.printGenerateSuccess = exports.printGenerateError = exports.printWarning = exports.printError = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const process_1 = require("process");
8
9
  function printError(message, component) {
9
10
  console.error(chalk_1.default.red(`${message}:`, chalk_1.default.bold(chalk_1.default.white(`[${component}] ❌`))));
10
11
  }
11
12
  exports.printError = printError;
13
+ function printWarning(message, component) {
14
+ if (component === undefined) {
15
+ process_1.stdout.write(chalk_1.default.yellow(`${message} ⚠️\n`));
16
+ return;
17
+ }
18
+ process_1.stdout.write(chalk_1.default.yellow(`${message}:`, chalk_1.default.bold(chalk_1.default.white(`[${component}] ⚠️\n`))));
19
+ }
20
+ exports.printWarning = printWarning;
12
21
  async function printGenerateError(schematic, file) {
13
22
  console.error(" ", chalk_1.default.redBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.white(`${file.split(".")[0]} not created! ❌`));
14
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/cli",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
5
5
  "author": "Richard Zampieri",
6
6
  "license": "MIT",
@@ -11,7 +11,7 @@
11
11
  "expressots": "bin/cli.js"
12
12
  },
13
13
  "engines": {
14
- "node": ">=18.18.0"
14
+ "node": ">=18.0.0"
15
15
  },
16
16
  "funding": {
17
17
  "type": "github",
@@ -31,7 +31,7 @@
31
31
  "Scaffolding"
32
32
  ],
33
33
  "scripts": {
34
- "prepare": "husky install",
34
+ "prepare": "husky",
35
35
  "start:build": "npm run build && npm run start",
36
36
  "start": "node ./bin/cli.js",
37
37
  "start:dev": "tsnd ./src/cli.ts",
@@ -49,17 +49,17 @@
49
49
  "coverage": "vitest run --coverage"
50
50
  },
51
51
  "dependencies": {
52
- "@expressots/boost-ts": "1.1.1",
52
+ "@expressots/boost-ts": "1.3.0",
53
53
  "chalk-animation": "2.0.3",
54
- "cli-progress": "3.11.2",
55
- "cli-table3": "0.6.4",
54
+ "cli-progress": "3.12.0",
55
+ "cli-table3": "0.6.5",
56
56
  "degit": "2.8.4",
57
57
  "glob": "10.4.1",
58
- "inquirer": "8.0.0",
58
+ "inquirer": "8.2.6",
59
59
  "mustache": "4.2.0",
60
60
  "semver": "7.6.2",
61
- "ts-node": "10.9.1",
62
- "yargs": "17.6.2"
61
+ "ts-node": "10.9.2",
62
+ "yargs": "17.7.2"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@codecov/vite-plugin": "^0.0.1-beta.9",