@expressots/cli 1.12.0 → 3.0.0-beta.2

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.
Files changed (45) hide show
  1. package/bin/cli.d.ts +5 -1
  2. package/bin/cli.js +7 -0
  3. package/bin/commands/project.commands.js +26 -22
  4. package/bin/generate/templates/nonopinionated/module.tpl +1 -2
  5. package/bin/generate/templates/opinionated/controller-service-delete.tpl +6 -14
  6. package/bin/generate/templates/opinionated/controller-service-get.tpl +7 -15
  7. package/bin/generate/templates/opinionated/controller-service-patch.tpl +7 -17
  8. package/bin/generate/templates/opinionated/controller-service-post.tpl +7 -14
  9. package/bin/generate/templates/opinionated/controller-service-put.tpl +7 -17
  10. package/bin/generate/templates/opinionated/controller-service.tpl +1 -2
  11. package/bin/generate/templates/opinionated/module-service.tpl +1 -2
  12. package/bin/generate/templates/opinionated/module.tpl +1 -2
  13. package/bin/generate/utils/command-utils.d.ts +1 -1
  14. package/bin/generate/utils/command-utils.js +12 -12
  15. package/bin/generate/utils/nonopininated-cmd.d.ts +1 -1
  16. package/bin/generate/utils/nonopininated-cmd.js +12 -12
  17. package/bin/generate/utils/opinionated-cmd.d.ts +1 -1
  18. package/bin/generate/utils/opinionated-cmd.js +12 -12
  19. package/bin/generate/utils/string-utils.d.ts +36 -0
  20. package/bin/generate/utils/string-utils.js +71 -0
  21. package/bin/help/form.js +5 -1
  22. package/bin/index.d.ts +0 -1
  23. package/bin/index.js +0 -1
  24. package/bin/info/form.js +3 -13
  25. package/bin/new/cli.js +1 -1
  26. package/bin/new/form.d.ts +3 -2
  27. package/bin/new/form.js +42 -23
  28. package/bin/providers/add/cli.d.ts +1 -0
  29. package/bin/providers/add/cli.js +27 -4
  30. package/bin/providers/add/form.d.ts +2 -1
  31. package/bin/providers/add/form.js +72 -39
  32. package/bin/providers/create/form.js +1 -1
  33. package/bin/utils/add-module-to-container.js +16 -11
  34. package/bin/utils/compiler.d.ts +1 -1
  35. package/package.json +19 -20
  36. package/bin/@types/config.d.ts +0 -39
  37. package/bin/@types/config.js +0 -2
  38. package/bin/@types/index.d.ts +0 -1
  39. package/bin/@types/index.js +0 -17
  40. package/bin/app.container.d.ts +0 -1
  41. package/bin/app.container.js +0 -8
  42. package/bin/commands/__tests__/project.commands.spec.d.ts +0 -1
  43. package/bin/commands/__tests__/project.commands.spec.js +0 -8
  44. package/bin/types.d.ts +0 -1
  45. package/bin/types.js +0 -17
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.anyCaseToLowerCase = exports.anyCaseToUpperCase = exports.anyCaseToSnakeCase = exports.anyCaseToPascalCase = exports.anyCaseToKebabCase = exports.anyCaseToCamelCase = void 0;
4
+ /**
5
+ * Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to camelCase.
6
+ * @param str - The input string to be converted.
7
+ * @returns The converted string in camelCase.
8
+ */
9
+ function anyCaseToCamelCase(str) {
10
+ return str
11
+ .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
12
+ .replace(/^[A-Z]/, (char) => char.toLowerCase());
13
+ }
14
+ exports.anyCaseToCamelCase = anyCaseToCamelCase;
15
+ /**
16
+ * Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to kebab-case.
17
+ * @param str - The input string to be converted.
18
+ * @returns The converted string in kebab-case.
19
+ */
20
+ function anyCaseToKebabCase(str) {
21
+ return str
22
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2") // Convert camelCase and PascalCase to kebab-case
23
+ .replace(/_/g, "-") // Convert snake_case to kebab-case
24
+ .toLowerCase(); // Ensure all characters are lowercase
25
+ }
26
+ exports.anyCaseToKebabCase = anyCaseToKebabCase;
27
+ /**
28
+ * Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to PascalCase.
29
+ * @param str - The input string to be converted.
30
+ * @returns The converted string in PascalCase.
31
+ */
32
+ function anyCaseToPascalCase(str) {
33
+ return str
34
+ .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
35
+ .replace(/^[a-z]/, (char) => char.toUpperCase());
36
+ }
37
+ exports.anyCaseToPascalCase = anyCaseToPascalCase;
38
+ /**
39
+ * Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to snake_case.
40
+ * @param str - The input string to be converted.
41
+ * @returns The converted string in snake_case.
42
+ */
43
+ function anyCaseToSnakeCase(str) {
44
+ return str
45
+ .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
46
+ .replace(/[-]+/g, "_")
47
+ .toLowerCase();
48
+ }
49
+ exports.anyCaseToSnakeCase = anyCaseToSnakeCase;
50
+ /**
51
+ * Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to UPPER CASE.
52
+ * @param str - The input string to be converted.
53
+ * @returns The converted string in UPPER CASE.
54
+ */
55
+ function anyCaseToUpperCase(str) {
56
+ return str
57
+ .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
58
+ .toUpperCase();
59
+ }
60
+ exports.anyCaseToUpperCase = anyCaseToUpperCase;
61
+ /**
62
+ * Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to lower case.
63
+ * @param str - The input string to be converted.
64
+ * @returns The converted string in lower case.
65
+ */
66
+ function anyCaseToLowerCase(str) {
67
+ return str
68
+ .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toLowerCase() : ""))
69
+ .toLowerCase();
70
+ }
71
+ exports.anyCaseToLowerCase = anyCaseToLowerCase;
package/bin/help/form.js CHANGED
@@ -19,7 +19,11 @@ const helpForm = async () => {
19
19
  "service",
20
20
  "g s",
21
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 internal provider"], ["provider", "add", "Add external provider to the project"], ["provider", "create", "Create external provider"], ["module", "g mo", "Generate a module"], ["middleware", "g mi", "Generate a middleware"]);
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 internal provider"], [
23
+ "provider",
24
+ "add",
25
+ "Add provider to the project. Use -d to add as dev dependency",
26
+ ], ["provider", "remove", "Remove provider from the project"], ["provider", "create", "Create external provider"], ["module", "g mo", "Generate a module"], ["middleware", "g mi", "Generate a middleware"]);
23
27
  console.log(chalk_1.default.bold.white("ExpressoTS:", `${chalk_1.default.green("Resources List")}`));
24
28
  console.log(chalk_1.default.whiteBright(table.toString()));
25
29
  console.log(chalk_1.default.bold.white(`📝 More info: ${chalk_1.default.green("https://doc.expresso-ts.com/docs/category/cli")}`));
package/bin/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./types";
2
1
  export * from "./generate";
3
2
  export * from "./utils";
4
3
  export * from "./new";
package/bin/index.js CHANGED
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
17
  __exportStar(require("./generate"), exports);
19
18
  __exportStar(require("./utils"), exports);
20
19
  __exportStar(require("./new"), exports);
package/bin/info/form.js CHANGED
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.infoForm = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const path_1 = __importDefault(require("path"));
9
8
  const fs_1 = __importDefault(require("fs"));
10
9
  const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const cli_1 = require("../cli");
11
12
  const cli_ui_1 = require("../utils/cli-ui");
12
- const axios_1 = __importDefault(require("axios"));
13
13
  function getInfosFromPackage() {
14
14
  try {
15
15
  // Get the absolute path of the input directory parameter
@@ -33,16 +33,6 @@ const infoForm = () => {
33
33
  console.log(chalk_1.default.green("System information:"));
34
34
  console.log(chalk_1.default.white(`\tOS Version: ${os_1.default.version()}`));
35
35
  console.log(chalk_1.default.white(`\tNodeJS version: ${process.version}`));
36
- currentCLIVersion();
36
+ (0, cli_ui_1.printSuccess)("CLI version:", cli_1.BUNDLE_VERSION);
37
37
  };
38
38
  exports.infoForm = infoForm;
39
- async function currentCLIVersion() {
40
- try {
41
- const response = await axios_1.default.get("https://api.github.com/repos/expressots/expressots-cli/releases");
42
- const latestRelease = `v${response.data[0].tag_name}`;
43
- (0, cli_ui_1.printSuccess)("CLI version:", latestRelease);
44
- }
45
- catch (error) {
46
- (0, cli_ui_1.printError)("Error:", error.message);
47
- }
48
- }
package/bin/new/cli.js CHANGED
@@ -23,7 +23,7 @@ const commandOptions = (yargs) => {
23
23
  .option("template", {
24
24
  describe: "The project template to use",
25
25
  type: "string",
26
- choices: ["opinionated", "non-opinionated"],
26
+ choices: ["opinionated", "non-opinionated", "micro"],
27
27
  alias: "t",
28
28
  })
29
29
  .option("package-manager", {
package/bin/new/form.d.ts CHANGED
@@ -1,6 +1,7 @@
1
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)"
2
+ nonopinionated = "Non-Opinionated :: Start with a clean slate and build your project from scratch.",
3
+ opinionated = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)",
4
+ micro = "Micro :: A minimalistic template for building micro api's."
4
5
  }
5
6
  declare const enum PackageManager {
6
7
  npm = "npm",
package/bin/new/form.js CHANGED
@@ -14,48 +14,64 @@ const node_path_1 = __importDefault(require("node:path"));
14
14
  const center_text_1 = require("../utils/center-text");
15
15
  const cli_ui_1 = require("../utils/cli-ui");
16
16
  const change_package_info_1 = require("../utils/change-package-info");
17
+ const cli_1 = require("../cli");
17
18
  async function packageManagerInstall({ packageManager, directory, progressBar, }) {
19
+ const command = process.platform === "win32" ? `${packageManager}.cmd` : packageManager;
20
+ const args = ["install", "--prefer-offline", "--silent"];
21
+ if (packageManager === "yarn") {
22
+ args.push("--ignore-engines");
23
+ args.splice(args.indexOf("--prefer-offline"), 1);
24
+ }
18
25
  return new Promise((resolve, reject) => {
19
- const isWindows = process.platform === "win32";
20
- const command = isWindows
21
- ? `${packageManager}.cmd`
22
- : packageManager;
23
- const installProcess = (0, node_child_process_1.spawn)(command, ["install", "--prefer-offline"], {
26
+ const installProcess = (0, node_child_process_1.spawn)(command, args, {
24
27
  cwd: directory,
25
28
  shell: true,
26
29
  timeout: 600000,
27
30
  });
28
- // eslint-disable-next-line prefer-const
29
- let installTimeout;
30
- installProcess.on("error", (error) => {
31
- clearTimeout(installTimeout);
32
- reject(new Error(`Failed to start subprocess: ${error.message}`));
33
- });
31
+ // Simulate incremental progress
32
+ let progress = 0;
33
+ const interval = setInterval(() => {
34
+ if (progress < 90) {
35
+ progress += 5;
36
+ progressBar.update(progress);
37
+ }
38
+ }, 1000);
39
+ // Handle stdout for meaningful output or progress feedback
34
40
  installProcess.stdout?.on("data", (data) => {
35
41
  const output = data.toString().trim();
36
- const npmProgressMatch = output.match(/\[(\d+)\/(\d+)\] (?:npm )?([\w\s]+)\.{3}/);
42
+ // Remove all data from || to the end of the line
43
+ const cleanedOutput = output.replace(/\|\|.*$/g, "");
44
+ // Match and handle npm-specific progress
45
+ const npmProgressMatch = cleanedOutput.match(/\[(\d+)\/(\d+)\] (?:npm )?([\w\s]+)\.{3}/);
37
46
  if (npmProgressMatch) {
38
47
  const [, current, total, task] = npmProgressMatch;
39
- const progress = Math.round((parseInt(current) / parseInt(total)) * 100);
48
+ progress = Math.round((parseInt(current) / parseInt(total)) * 100);
40
49
  progressBar.update(progress, { doing: task });
41
50
  }
42
51
  else {
43
- progressBar.increment(5, { doing: output });
52
+ // Update "task" without changing the progress
53
+ progressBar.update(progress, { doing: cleanedOutput });
44
54
  }
45
55
  });
56
+ // Handle errors
57
+ installProcess.on("error", (error) => {
58
+ clearInterval(interval); // Stop interval on error
59
+ progressBar.stop();
60
+ reject(new Error(`Failed to start subprocess: ${error.message}`));
61
+ });
62
+ // Finalize progress on close
46
63
  installProcess.on("close", (code) => {
47
- clearTimeout(installTimeout);
64
+ clearInterval(interval); // Stop interval when the process ends
48
65
  if (code === 0) {
66
+ progressBar.update(100, { doing: "Complete!" }); // Finalize progress
67
+ progressBar.stop();
49
68
  resolve("Installation Done!");
50
69
  }
51
70
  else {
71
+ progressBar.stop();
52
72
  reject(new Error(`${packageManager} install exited with code ${code}`));
53
73
  }
54
74
  });
55
- installTimeout = setTimeout(() => {
56
- installProcess.kill("SIGKILL");
57
- reject(new Error("Installation took too long. Aborted!"));
58
- }, 600000);
59
75
  });
60
76
  }
61
77
  async function checkIfPackageManagerExists(packageManager) {
@@ -84,8 +100,9 @@ function renameEnvFile(directory) {
84
100
  }
85
101
  var Template;
86
102
  (function (Template) {
87
- Template["non-opinionated"] = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.";
103
+ Template["nonopinionated"] = "Non-Opinionated :: Start with a clean slate and build your project from scratch.";
88
104
  Template["opinionated"] = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)";
105
+ Template["micro"] = "Micro :: A minimalistic template for building micro api's.";
89
106
  })(Template || (Template = {}));
90
107
  const projectForm = async (projectName, args) => {
91
108
  let answer;
@@ -122,6 +139,7 @@ const projectForm = async (projectName, args) => {
122
139
  choices: [
123
140
  `Opinionated :: Automatically scaffolds resources into a preset project structure. (${chalk_1.default.yellow("Recommended")})`,
124
141
  "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
142
+ "Micro :: A minimalistic template for building micro api's.",
125
143
  ],
126
144
  },
127
145
  {
@@ -143,8 +161,9 @@ const projectForm = async (projectName, args) => {
143
161
  }
144
162
  // Hashmap of templates and their directories
145
163
  const templates = {
146
- "Non-Opinionated": "non_opinionated",
164
+ NonOpinionated: "non_opinionated",
147
165
  Opinionated: "opinionated",
166
+ Micro: "micro",
148
167
  };
149
168
  if (answer.confirm) {
150
169
  // Check if package manager is bun and OS is Windows
@@ -164,8 +183,9 @@ const projectForm = async (projectName, args) => {
164
183
  doing: "Cloning project",
165
184
  });
166
185
  const [_, template] = answer.template.match(/(.*) ::/);
186
+ const repo = `expressots/templates/${templates[template]}#${cli_1.BUNDLE_VERSION}`;
167
187
  try {
168
- const emitter = (0, degit_1.default)(`expressots/expressots/templates/${templates[template]}`);
188
+ const emitter = (0, degit_1.default)(`expressots/templates/${templates[template]}`);
169
189
  await emitter.clone(answer.name);
170
190
  }
171
191
  catch (err) {
@@ -186,7 +206,6 @@ const projectForm = async (projectName, args) => {
186
206
  directory: answer.name,
187
207
  name: projectName,
188
208
  });
189
- renameEnvFile(answer.name);
190
209
  progressBar.update(100);
191
210
  progressBar.stop();
192
211
  console.log("\n");
@@ -1,4 +1,5 @@
1
1
  import { CommandModule } from "yargs";
2
2
  type CommandModuleArgs = {};
3
3
  export declare const addProviderCMD: () => CommandModule<CommandModuleArgs, any>;
4
+ export declare const removeProviderCMD: () => CommandModule<CommandModuleArgs, any>;
4
5
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addProviderCMD = void 0;
3
+ exports.removeProviderCMD = exports.addProviderCMD = void 0;
4
4
  const form_1 = require("./form");
5
5
  const addProviderCMD = () => {
6
6
  return {
@@ -15,14 +15,37 @@ const addProviderCMD = () => {
15
15
  .option("version", {
16
16
  describe: "The provider version to be installed",
17
17
  type: "string",
18
- default: "latest",
18
+ default: false,
19
19
  alias: "v",
20
+ })
21
+ .option("dev", {
22
+ describe: "Add provider as a dev dependency",
23
+ type: "boolean",
24
+ default: false,
25
+ alias: "d",
20
26
  });
21
27
  return yargs;
22
28
  },
23
- handler: async ({ provider, version }) => {
24
- await (0, form_1.addExternalProvider)(provider, version);
29
+ handler: async ({ provider, version, dev }) => {
30
+ await (0, form_1.addProvider)(provider, version, dev);
25
31
  },
26
32
  };
27
33
  };
28
34
  exports.addProviderCMD = addProviderCMD;
35
+ const removeProviderCMD = () => {
36
+ return {
37
+ command: "remove <provider>",
38
+ describe: "Remove provider from the project.",
39
+ builder: (yargs) => {
40
+ yargs.positional("provider", {
41
+ describe: "The provider to be removed from the project",
42
+ type: "string",
43
+ });
44
+ return yargs;
45
+ },
46
+ handler: async ({ provider: packageName }) => {
47
+ await (0, form_1.removeProvider)(packageName);
48
+ },
49
+ };
50
+ };
51
+ exports.removeProviderCMD = removeProviderCMD;
@@ -1 +1,2 @@
1
- export declare const addExternalProvider: (provider: string, version: string) => Promise<void>;
1
+ export declare function addProvider(packageName: string, version?: string, isDevDependency?: boolean): Promise<void>;
2
+ export declare function removeProvider(packageName: string): Promise<void>;
@@ -3,66 +3,99 @@ 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.addExternalProvider = void 0;
6
+ exports.removeProvider = exports.addProvider = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const node_child_process_1 = require("node:child_process");
9
9
  const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const node_process_1 = require("node:process");
11
11
  const cli_ui_1 = require("../../utils/cli-ui");
12
- const addExternalProvider = async (provider, version) => {
13
- await installProvider(provider, version);
12
+ const PACKAGE_MANAGERS = {
13
+ npm: {
14
+ install: "install",
15
+ addDev: "install --save-dev",
16
+ remove: "uninstall",
17
+ },
18
+ yarn: {
19
+ install: "add",
20
+ addDev: "add --dev",
21
+ remove: "remove",
22
+ },
23
+ pnpm: {
24
+ install: "add",
25
+ addDev: "add --save-dev",
26
+ remove: "remove",
27
+ },
14
28
  };
15
- exports.addExternalProvider = addExternalProvider;
16
- async function installProvider(provider, version) {
17
- const packageManager = node_fs_1.default.existsSync("package-lock.json" || "yarn.lock" || "pnpm-lock.yaml")
18
- ? "npm"
19
- : node_fs_1.default.existsSync("yarn.lock")
20
- ? "yarn"
21
- : node_fs_1.default.existsSync("pnpm-lock.yaml")
22
- ? "pnpm"
23
- : null;
24
- if (packageManager) {
25
- console.log(`Installing ${provider} provider ...`);
26
- const currentVersion = version === "latest" ? "" : `@${version}`;
27
- await execProcess({
28
- commandArg: packageManager,
29
- args: ["add", `${provider}${currentVersion}`, "--prefer-offline"],
30
- directory: process.cwd(),
31
- });
32
- }
33
- else {
34
- (0, cli_ui_1.printError)("No package manager found in the project", "install-provider");
35
- return;
29
+ function detectPackageManager() {
30
+ const lockFiles = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
31
+ const managers = Object.keys(PACKAGE_MANAGERS);
32
+ for (let i = 0; i < lockFiles.length; i++) {
33
+ if (node_fs_1.default.existsSync(lockFiles[i])) {
34
+ return managers[i];
35
+ }
36
36
  }
37
+ return null;
37
38
  }
38
- async function execProcess({ commandArg, args, directory, }) {
39
+ async function execProcess({ command, args, directory, }) {
39
40
  return new Promise((resolve, reject) => {
40
41
  const isWindows = process.platform === "win32";
41
- const command = isWindows ? `${commandArg}.cmd` : commandArg;
42
- const installProcess = (0, node_child_process_1.spawn)(command, args, {
42
+ const execCommand = isWindows ? `${command}.cmd` : command;
43
+ const processRunner = (0, node_child_process_1.spawn)(execCommand, args, {
43
44
  cwd: directory,
44
45
  shell: true,
45
46
  });
46
- console.log(chalk_1.default.bold.blue(`Executing: ${commandArg} ${args.join(" ")}`));
47
+ console.log(chalk_1.default.bold.blue(`Executing: ${command} ${args.join(" ")}`));
47
48
  console.log(chalk_1.default.yellow("-------------------------------------------------"));
48
- installProcess.stdout.on("data", (data) => {
49
- console.log(chalk_1.default.green(data.toString().trim())); // Display regular messages in green
49
+ processRunner.stdout.on("data", (data) => {
50
+ console.log(chalk_1.default.green(data.toString().trim()));
50
51
  });
51
- installProcess.stderr.on("data", (data) => {
52
- console.error(chalk_1.default.red(data.toString().trim())); // Display error messages in red
52
+ processRunner.stderr.on("data", (data) => {
53
+ console.error(chalk_1.default.red(data.toString().trim()));
53
54
  });
54
- installProcess.on("close", (code) => {
55
+ processRunner.on("close", (code) => {
55
56
  if (code === 0) {
56
- console.log(chalk_1.default.bold.green("-------------------------------------------------"));
57
- console.log(chalk_1.default.bold.green("Installation Done!\n"));
58
- resolve("Installation Done!");
57
+ console.log(chalk_1.default.bold.green("Operation completed successfully!\n"));
58
+ resolve();
59
59
  }
60
60
  else {
61
- console.error(chalk_1.default.bold.red("---------------------------------------"));
62
- console.error(chalk_1.default.bold.red(`Command ${command} ${args.join(" ")} exited with code ${code}`));
63
- reject(new Error(`Command ${command} ${args.join(" ")} exited with code ${code}`));
61
+ console.error(chalk_1.default.bold.red(`Command failed with exit code ${code}`));
62
+ reject(new Error(`Command failed with exit code ${code}`));
64
63
  (0, node_process_1.exit)(1);
65
64
  }
66
65
  });
67
66
  });
68
67
  }
68
+ async function addProvider(packageName, version, isDevDependency = false) {
69
+ const packageManager = detectPackageManager();
70
+ if (!packageManager) {
71
+ (0, cli_ui_1.printError)("No package manager found in the project", "add-package");
72
+ return;
73
+ }
74
+ const pkgManagerConfig = PACKAGE_MANAGERS[packageManager];
75
+ const command = isDevDependency
76
+ ? pkgManagerConfig.addDev
77
+ : pkgManagerConfig.install;
78
+ const versionSuffix = version && version !== "latest" ? `@${version}` : "";
79
+ console.log(`${isDevDependency ? "Adding devDependency" : "Installing"} ${packageName}...`);
80
+ await execProcess({
81
+ command: packageManager,
82
+ args: [...command.split(" "), `${packageName}${versionSuffix}`],
83
+ directory: process.cwd(),
84
+ });
85
+ }
86
+ exports.addProvider = addProvider;
87
+ async function removeProvider(packageName) {
88
+ const packageManager = detectPackageManager();
89
+ if (!packageManager) {
90
+ (0, cli_ui_1.printError)("No package manager found in the project", "remove-package");
91
+ return;
92
+ }
93
+ const command = PACKAGE_MANAGERS[packageManager].remove;
94
+ console.log(`Removing ${packageName}...`);
95
+ await execProcess({
96
+ command: packageManager,
97
+ args: [...command.split(" "), packageName],
98
+ directory: process.cwd(),
99
+ });
100
+ }
101
+ exports.removeProvider = removeProvider;
@@ -39,7 +39,7 @@ const createExternalProvider = async (provider) => {
39
39
  ]);
40
40
  }
41
41
  try {
42
- const emitter = (0, degit_1.default)(`expressots/expressots-provider-template`);
42
+ const emitter = (0, degit_1.default)(`expressots/templates/provider`);
43
43
  await emitter.clone(providerInfo.providerName);
44
44
  (0, change_package_info_1.changePackageName)({
45
45
  directory: providerInfo.providerName,
@@ -9,11 +9,12 @@ const glob_1 = require("glob");
9
9
  const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const cli_ui_1 = require("./cli-ui");
11
11
  const compiler_1 = __importDefault(require("./compiler"));
12
- const APP_CONTAINER = "app.container.ts";
12
+ const APP_CONTAINER = "app.ts";
13
13
  async function validateAppContainer() {
14
14
  const { sourceRoot } = await compiler_1.default.loadConfig();
15
15
  const imports = [];
16
16
  const notImports = [];
17
+ // Locate the container file
17
18
  const path = (0, glob_1.globSync)(`./${sourceRoot}/${APP_CONTAINER}`, {
18
19
  absolute: true,
19
20
  ignore: "**/node_modules/**",
@@ -22,7 +23,9 @@ async function validateAppContainer() {
22
23
  (0, cli_ui_1.printError)("Module not added to Container. Container file not found!", APP_CONTAINER);
23
24
  process.exit(1);
24
25
  }
26
+ // Read the container file
25
27
  const fileContent = await node_fs_1.default.promises.readFile(path[0], "utf8");
28
+ // Collect imports and other lines
26
29
  fileContent.split("\n").forEach((line) => {
27
30
  if (line.startsWith("import")) {
28
31
  imports.push(line);
@@ -31,28 +34,30 @@ async function validateAppContainer() {
31
34
  notImports.push(line);
32
35
  }
33
36
  });
34
- // Validate the file content
35
- const moduleDeclarationRegex = /.create\(\s*\[([\s\S]*?)]/;
36
- const moduleDeclarationMatch = fileContent.match(moduleDeclarationRegex);
37
- if (!moduleDeclarationMatch) {
38
- (0, cli_ui_1.printError)("Container format incorrect!", APP_CONTAINER);
37
+ // Regex to detect and extract modules from configContainer
38
+ const moduleRegex = /this\.configContainer\(\s*\[\s*([\s\S]*?)\s*]\s*\)/;
39
+ const moduleMatch = fileContent.match(moduleRegex);
40
+ if (!moduleMatch) {
41
+ (0, cli_ui_1.printError)("The App class does not contain a valid configContainer([]) declaration!", APP_CONTAINER);
39
42
  process.exit(1);
40
43
  }
41
- const modules = moduleDeclarationMatch[1]
44
+ // Extract modules if present
45
+ const modules = moduleMatch[1]
42
46
  .trim()
43
47
  .split(",")
44
48
  .filter((m) => m.trim() !== "")
45
49
  .map((m) => m.trim());
46
50
  return {
47
- regex: moduleDeclarationRegex,
51
+ regex: moduleRegex,
48
52
  path: path[0],
49
- content: moduleDeclarationMatch,
53
+ content: fileContent,
50
54
  modules,
51
55
  imports,
52
56
  notImports,
53
57
  };
54
58
  }
55
59
  async function addModuleToContainer(name, modulePath, path) {
60
+ console.log("To chamando esse cara");
56
61
  const containerData = await validateAppContainer();
57
62
  const moduleName = (name[0].toUpperCase() + name.slice(1)).trimStart();
58
63
  const { opinionated } = await compiler_1.default.loadConfig();
@@ -83,7 +88,7 @@ async function addModuleToContainer(name, modulePath, path) {
83
88
  containerData.imports.push(newImport);
84
89
  containerData.modules.push(`${moduleName}Module`);
85
90
  const newModule = containerData.modules.join(", ");
86
- const newModuleDeclaration = `.create([${newModule}]`;
91
+ const newModuleDeclaration = `this.configContainer([${newModule}])`;
87
92
  const newFileContent = [
88
93
  ...containerData.imports,
89
94
  ...containerData.notImports,
@@ -116,7 +121,7 @@ async function addModuleToContainerNestedPath(name, path) {
116
121
  containerData.imports.push(newImport);
117
122
  containerData.modules.push(`${moduleName}Module`);
118
123
  const newModule = containerData.modules.join(", ");
119
- const newModuleDeclaration = `.create([${newModule}]`;
124
+ const newModuleDeclaration = `this.configContainer([${newModule}])`;
120
125
  const newFileContent = [
121
126
  ...containerData.imports,
122
127
  ...containerData.notImports,
@@ -1,5 +1,5 @@
1
1
  import { Service } from "ts-node";
2
- import { ExpressoConfig } from "../types";
2
+ import { ExpressoConfig } from "@expressots/shared";
3
3
  /**
4
4
  * Singleton compiler class
5
5
  */