@expressots/cli 1.8.2 → 1.10.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/cli.js CHANGED
@@ -11,24 +11,24 @@ const generate_1 = require("./generate");
11
11
  const cli_1 = require("./help/cli");
12
12
  const info_1 = require("./info");
13
13
  const new_1 = require("./new");
14
+ const cli_2 = require("./providers/create/cli");
14
15
  const providers_1 = require("./providers");
15
- console.log(`\n[🐎 Expressots]\n`);
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const process_1 = require("process");
18
+ process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n`);
16
19
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
17
20
  .scriptName("expressots")
18
- .command(project_commands_1.runCommandModule)
19
21
  .command((0, new_1.createProject)())
20
- .command((0, providers_1.generateProviders)())
22
+ .command(project_commands_1.devCommand)
23
+ .command(project_commands_1.buildCommand)
24
+ .command(project_commands_1.prodCommand)
25
+ .command((0, cli_2.createExternalProviderCMD)())
26
+ .command((0, providers_1.addProviderCMD)())
21
27
  .command((0, generate_1.generateProject)())
22
28
  .command((0, info_1.infoProject)())
23
29
  .command((0, cli_1.helpCommand)())
24
- .example("$0 new expressots-demo", "Create interactively")
25
- .example("$0 new expressots-demo -d ./", "Create interactively with path")
26
- .example("$0 new expressots-demo -p yarn -t opinionated", "Create silently")
27
- .example("$0 new expressots-demo -p yarn -t opinionated -d ./", "Create silently with path")
28
- .example("$0 generate service user-create", "Scaffold a service")
29
- .example("$0 info", "Show CLI details")
30
30
  .demandCommand(1, "You need at least one command before moving on")
31
- .epilog("For more information: \n" +
31
+ .epilog(`${chalk_1.default.bold.green("For more information:")} \n\n` +
32
32
  "🌐 visit:\t https://expresso-ts.com\n" +
33
33
  "💖 Sponsor:\t https://github.com/sponsors/expressots")
34
34
  .help("help", "Show command help")
@@ -1,8 +1,7 @@
1
1
  import { CommandModule } from "yargs";
2
- export declare const runCommandModule: CommandModule<{}, {
3
- command: string;
4
- }>;
5
- declare const runCommand: ({ command }: {
2
+ export declare const devCommand: CommandModule<object, object>;
3
+ export declare const buildCommand: CommandModule<object, object>;
4
+ export declare const prodCommand: CommandModule<object, object>;
5
+ export declare const runCommand: ({ command, }: {
6
6
  command: string;
7
7
  }) => Promise<void>;
8
- export { runCommand };
@@ -3,11 +3,13 @@ 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.runCommand = exports.runCommandModule = void 0;
6
+ exports.runCommand = exports.prodCommand = exports.buildCommand = exports.devCommand = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_1 = require("fs");
9
9
  const path_1 = __importDefault(require("path"));
10
+ const cli_ui_1 = require("../utils/cli-ui");
10
11
  const compiler_1 = __importDefault(require("../utils/compiler"));
12
+ const os_1 = __importDefault(require("os"));
11
13
  /**
12
14
  * Load the configuration from the compiler
13
15
  * @param compiler The compiler to load the configuration from
@@ -15,6 +17,7 @@ const compiler_1 = __importDefault(require("../utils/compiler"));
15
17
  */
16
18
  const opinionatedConfig = [
17
19
  "--transpile-only",
20
+ "--clear",
18
21
  "-r",
19
22
  "dotenv/config",
20
23
  "-r",
@@ -23,6 +26,7 @@ const opinionatedConfig = [
23
26
  ];
24
27
  const nonOpinionatedConfig = [
25
28
  "--transpile-only",
29
+ "--clear",
26
30
  "-r",
27
31
  "dotenv/config",
28
32
  "./src/main.ts",
@@ -54,10 +58,12 @@ function execCmd(command, args, cwd = process.cwd()) {
54
58
  // Helper to delete the dist directory
55
59
  const cleanDist = async () => {
56
60
  await fs_1.promises.rm("./dist", { recursive: true, force: true });
61
+ (0, cli_ui_1.printSuccess)("Deleted dist directory", "clean-dist");
57
62
  };
58
63
  // Helper to compile TypeScript
59
64
  const compileTypescript = async () => {
60
65
  await execCmd("npx", ["tsc", "-p", "tsconfig.build.json"]);
66
+ (0, cli_ui_1.printSuccess)("Built successfully", "compile-typescript");
61
67
  };
62
68
  // Helper to copy files
63
69
  const copyFiles = async () => {
@@ -77,30 +83,38 @@ const copyFiles = async () => {
77
83
  fs_1.promises.copyFile(file, path_1.default.join("./dist", path_1.default.basename(file)));
78
84
  });
79
85
  };
80
- // eslint-disable-next-line @typescript-eslint/ban-types
81
- exports.runCommandModule = {
82
- command: "run <command>",
83
- describe: "Runs a specified command (dev, build, prod)",
84
- builder: (yargs) => {
85
- return yargs.positional("command", {
86
- describe: "The command to run",
87
- type: "string",
88
- choices: ["dev", "build", "prod"],
89
- });
86
+ // Helper clear screen
87
+ const clearScreen = () => {
88
+ const platform = os_1.default.platform();
89
+ const command = platform === "win32" ? "cls" : "clear";
90
+ (0, child_process_1.spawn)(command, { stdio: "inherit", shell: true });
91
+ };
92
+ exports.devCommand = {
93
+ command: "dev",
94
+ describe: "Start development server.",
95
+ handler: async () => {
96
+ await (0, exports.runCommand)({ command: "dev" });
97
+ },
98
+ };
99
+ exports.buildCommand = {
100
+ command: "build",
101
+ describe: "Build the project.",
102
+ handler: async () => {
103
+ await (0, exports.runCommand)({ command: "build" });
90
104
  },
91
- handler: async (argv) => {
92
- const { command } = argv;
93
- // Now call your original runCommand function with the command
94
- // Ensure runCommand is properly defined to handle these commands
95
- await runCommand({ command });
105
+ };
106
+ exports.prodCommand = {
107
+ command: "prod",
108
+ describe: "Run in production mode.",
109
+ handler: async () => {
110
+ await (0, exports.runCommand)({ command: "prod" });
96
111
  },
97
112
  };
98
- const runCommand = async ({ command }) => {
113
+ const runCommand = async ({ command, }) => {
99
114
  const { opinionated } = await compiler_1.default.loadConfig();
100
115
  try {
101
116
  switch (command) {
102
117
  case "dev":
103
- // Use execSync or spawn to run ts-node-dev programmatically
104
118
  execCmd("tsnd", opinionated ? opinionatedConfig : nonOpinionatedConfig);
105
119
  break;
106
120
  case "build":
@@ -122,16 +136,17 @@ const runCommand = async ({ command }) => {
122
136
  else {
123
137
  config = ["-r", "dotenv/config", "./dist/main.js"];
124
138
  }
125
- // Ensure environment variables are set
139
+ clearScreen();
126
140
  execCmd("node", config);
127
141
  break;
128
142
  }
129
143
  default:
130
- console.log(`Unknown command: ${command}`);
144
+ (0, cli_ui_1.printError)(`Unknown command: `, command);
145
+ break;
131
146
  }
132
147
  }
133
148
  catch (error) {
134
- console.error("Error executing command:", error);
149
+ (0, cli_ui_1.printError)("Error executing command:", error.message);
135
150
  }
136
151
  };
137
152
  exports.runCommand = runCommand;
@@ -27,7 +27,7 @@ const coerceSchematicAliases = (arg) => {
27
27
  const generateProject = () => {
28
28
  return {
29
29
  command: "generate [schematic] [path] [method]",
30
- describe: "Scaffold a new resource",
30
+ describe: "Generate ExpressoTS resource.",
31
31
  aliases: ["g"],
32
32
  builder: (yargs) => {
33
33
  yargs.positional("schematic", {
@@ -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/help/cli.js CHANGED
@@ -5,7 +5,7 @@ const form_1 = require("./form");
5
5
  const helpCommand = () => {
6
6
  return {
7
7
  command: "resources",
8
- describe: "Resource list",
8
+ describe: "Resource list.",
9
9
  aliases: ["r"],
10
10
  handler: async () => {
11
11
  await (0, form_1.helpForm)();
package/bin/help/form.js CHANGED
@@ -19,7 +19,7 @@ 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 a provider"], ["provider external", "a provider", "Generate an 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", "add", "Add provider to the project"], ["provider", "create", "Create a provider"], ["module", "g mo", "Generate a module"], ["middleware", "g mi", "Generate a middleware"]);
23
23
  console.log(chalk_1.default.bold.white("ExpressoTS:", `${chalk_1.default.green("Resources List")}`));
24
24
  console.log(chalk_1.default.whiteBright(table.toString()));
25
25
  console.log(chalk_1.default.bold.white(`📝 More info: ${chalk_1.default.green("https://doc.expresso-ts.com/docs/category/cli")}`));
package/bin/info/cli.js CHANGED
@@ -5,7 +5,7 @@ const form_1 = require("./form");
5
5
  const infoProject = () => {
6
6
  return {
7
7
  command: "info",
8
- describe: "Displays project details",
8
+ describe: "Displays project info.",
9
9
  aliases: ["i"],
10
10
  handler: async () => {
11
11
  await (0, form_1.infoForm)();
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,17 +42,17 @@ 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 = () => {
51
53
  return {
52
54
  command: "new <project-name> [package-manager] [template] [directory]",
53
- describe: "Create a new project",
55
+ describe: "Create ExpressoTS application.",
54
56
  builder: commandOptions,
55
57
  handler: async ({ projectName, packageManager, template, directory, }) => {
56
58
  checkNodeVersion();
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
@@ -13,16 +13,22 @@ const node_fs_1 = __importDefault(require("node:fs"));
13
13
  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
+ const change_package_info_1 = require("../utils/change-package-info");
16
17
  async function packageManagerInstall({ packageManager, directory, progressBar, }) {
17
18
  return new Promise((resolve, reject) => {
18
19
  const isWindows = process.platform === "win32";
19
20
  const command = isWindows
20
21
  ? `${packageManager}.cmd`
21
22
  : packageManager;
22
- const installProcess = (0, node_child_process_1.spawn)(command, ["install"], {
23
+ const installProcess = (0, node_child_process_1.spawn)(command, ["install", "--prefer-offline"], {
23
24
  cwd: directory,
25
+ shell: true,
26
+ timeout: 600000,
24
27
  });
28
+ // eslint-disable-next-line prefer-const
29
+ let installTimeout;
25
30
  installProcess.on("error", (error) => {
31
+ clearTimeout(installTimeout);
26
32
  reject(new Error(`Failed to start subprocess: ${error.message}`));
27
33
  });
28
34
  installProcess.stdout?.on("data", (data) => {
@@ -38,6 +44,7 @@ async function packageManagerInstall({ packageManager, directory, progressBar, }
38
44
  }
39
45
  });
40
46
  installProcess.on("close", (code) => {
47
+ clearTimeout(installTimeout);
41
48
  if (code === 0) {
42
49
  resolve("Installation Done!");
43
50
  }
@@ -45,6 +52,10 @@ async function packageManagerInstall({ packageManager, directory, progressBar, }
45
52
  reject(new Error(`${packageManager} install exited with code ${code}`));
46
53
  }
47
54
  });
55
+ installTimeout = setTimeout(() => {
56
+ installProcess.kill("SIGKILL");
57
+ reject(new Error("Installation took too long. Aborted!"));
58
+ }, 600000);
48
59
  });
49
60
  }
50
61
  async function checkIfPackageManagerExists(packageManager) {
@@ -57,18 +68,6 @@ async function checkIfPackageManagerExists(packageManager) {
57
68
  process.exit(1);
58
69
  }
59
70
  }
60
- function changePackageName({ directory, name, }) {
61
- // Get the absolute path of the input directory parameter
62
- const absDirPath = node_path_1.default.resolve(directory);
63
- // Load the package.json file
64
- const packageJsonPath = node_path_1.default.join(absDirPath, "package.json");
65
- const fileContents = node_fs_1.default.readFileSync(packageJsonPath, "utf-8");
66
- const packageJson = JSON.parse(fileContents);
67
- // Change the name
68
- packageJson.name = name;
69
- // Save the package.json file
70
- node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
71
- }
72
71
  function renameEnvFile(directory) {
73
72
  try {
74
73
  const envExamplePath = node_path_1.default.join(directory, ".env.example");
@@ -90,27 +89,7 @@ var Template;
90
89
  })(Template || (Template = {}));
91
90
  const projectForm = async (projectName, args) => {
92
91
  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
- }
92
+ const [packageManager, template, directory] = args;
114
93
  if (packageManager && template) {
115
94
  answer = {
116
95
  name: projectName,
@@ -203,9 +182,9 @@ const projectForm = async (projectName, args) => {
203
182
  progressBar,
204
183
  });
205
184
  progressBar.update(90);
206
- changePackageName({
185
+ (0, change_package_info_1.changePackageName)({
207
186
  directory: answer.name,
208
- name: projName,
187
+ name: projectName,
209
188
  });
210
189
  renameEnvFile(answer.name);
211
190
  progressBar.update(100);
@@ -0,0 +1,4 @@
1
+ import { CommandModule } from "yargs";
2
+ type CommandModuleArgs = {};
3
+ export declare const addProviderCMD: () => CommandModule<CommandModuleArgs, any>;
4
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProviderCMD = void 0;
4
+ const form_1 = require("./form");
5
+ const addProviderCMD = () => {
6
+ return {
7
+ command: "add <provider> [version]",
8
+ describe: "Add provider to the project.",
9
+ builder: (yargs) => {
10
+ yargs
11
+ .positional("provider", {
12
+ describe: "The provider to be added to the project",
13
+ type: "string",
14
+ })
15
+ .option("version", {
16
+ describe: "The provider version to be installed",
17
+ type: "string",
18
+ default: "latest",
19
+ alias: "v",
20
+ });
21
+ return yargs;
22
+ },
23
+ handler: async ({ provider, version }) => {
24
+ await (0, form_1.addExternalProvider)(provider, version);
25
+ },
26
+ };
27
+ };
28
+ exports.addProviderCMD = addProviderCMD;
@@ -0,0 +1 @@
1
+ export declare const addExternalProvider: (provider: string, version: string) => Promise<void>;
@@ -0,0 +1,68 @@
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.addExternalProvider = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const node_child_process_1 = require("node:child_process");
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const node_process_1 = require("node:process");
11
+ const cli_ui_1 = require("../../utils/cli-ui");
12
+ const addExternalProvider = async (provider, version) => {
13
+ await installProvider(provider, version);
14
+ };
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;
36
+ }
37
+ }
38
+ async function execProcess({ commandArg, args, directory, }) {
39
+ return new Promise((resolve, reject) => {
40
+ const isWindows = process.platform === "win32";
41
+ const command = isWindows ? `${commandArg}.cmd` : commandArg;
42
+ const installProcess = (0, node_child_process_1.spawn)(command, args, {
43
+ cwd: directory,
44
+ shell: true,
45
+ });
46
+ console.log(chalk_1.default.bold.blue(`Executing: ${commandArg} ${args.join(" ")}`));
47
+ 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
50
+ });
51
+ installProcess.stderr.on("data", (data) => {
52
+ console.error(chalk_1.default.red(data.toString().trim())); // Display error messages in red
53
+ });
54
+ installProcess.on("close", (code) => {
55
+ 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!");
59
+ }
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}`));
64
+ (0, node_process_1.exit)(1);
65
+ }
66
+ });
67
+ });
68
+ }
@@ -0,0 +1,4 @@
1
+ import { CommandModule } from "yargs";
2
+ type CommandModuleArgs = {};
3
+ export declare const createExternalProviderCMD: () => CommandModule<CommandModuleArgs, any>;
4
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createExternalProviderCMD = void 0;
4
+ const form_1 = require("./form");
5
+ const createExternalProviderCMD = () => {
6
+ return {
7
+ command: "create [provider]",
8
+ describe: "Create a provider.",
9
+ builder: (yargs) => {
10
+ yargs.option("provider", {
11
+ describe: "Provider name",
12
+ type: "string",
13
+ });
14
+ return yargs;
15
+ },
16
+ handler: async ({ provider }) => {
17
+ await (0, form_1.createExternalProvider)(provider);
18
+ },
19
+ };
20
+ };
21
+ exports.createExternalProviderCMD = createExternalProviderCMD;
@@ -0,0 +1 @@
1
+ export declare const createExternalProvider: (provider: string) => Promise<void>;
@@ -3,11 +3,12 @@ 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.externalProvider = void 0;
6
+ exports.createExternalProvider = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const degit_1 = __importDefault(require("degit"));
9
9
  const inquirer_1 = __importDefault(require("inquirer"));
10
10
  const center_text_1 = require("../../utils/center-text");
11
+ const change_package_info_1 = require("../../utils/change-package-info");
11
12
  const cli_ui_1 = require("../../utils/cli-ui");
12
13
  async function printInfo(providerName) {
13
14
  console.log("\n");
@@ -20,30 +21,38 @@ async function printInfo(providerName) {
20
21
  console.log(chalk_1.default.bold.white((0, center_text_1.centerText)("💖 Sponsor: https://github.com/sponsors/expressots")));
21
22
  console.log("\n");
22
23
  }
23
- const externalProvider = async () => {
24
+ const createExternalProvider = async (provider) => {
24
25
  return new Promise(async (resolve, reject) => {
25
- const providerInfo = await inquirer_1.default.prompt([
26
- {
27
- type: "input",
28
- name: "providerName",
29
- message: "Type the name of your provider:",
30
- default: "expressots-provider",
31
- transformer: (input) => {
32
- return chalk_1.default.yellow(chalk_1.default.bold(input));
26
+ let providerInfo = {};
27
+ providerInfo.providerName = provider;
28
+ if (!provider) {
29
+ providerInfo = await inquirer_1.default.prompt([
30
+ {
31
+ type: "input",
32
+ name: "providerName",
33
+ message: "Provider name",
34
+ default: "expressots-provider",
35
+ transformer: (input) => {
36
+ return chalk_1.default.yellow(chalk_1.default.bold(input));
37
+ },
33
38
  },
34
- },
35
- ]);
39
+ ]);
40
+ }
36
41
  try {
37
42
  const emitter = (0, degit_1.default)(`expressots/expressots-provider-template`);
38
43
  await emitter.clone(providerInfo.providerName);
44
+ (0, change_package_info_1.changePackageName)({
45
+ directory: providerInfo.providerName,
46
+ name: providerInfo.providerName,
47
+ });
39
48
  await printInfo(providerInfo.providerName);
40
49
  resolve();
41
50
  }
42
51
  catch (err) {
43
52
  console.log("\n");
44
- (0, cli_ui_1.printError)("Project already exists or Folder is not empty", "generate-external-provider");
53
+ (0, cli_ui_1.printError)("Project already exists or Folder is not empty", "");
45
54
  reject(err);
46
55
  }
47
56
  });
48
57
  };
49
- exports.externalProvider = externalProvider;
58
+ exports.createExternalProvider = createExternalProvider;
@@ -1 +1,2 @@
1
- export * from "./cli";
1
+ export * from "./add/cli";
2
+ export * from "./create/cli";
@@ -14,4 +14,5 @@ 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("./cli"), exports);
17
+ __exportStar(require("./add/cli"), exports);
18
+ __exportStar(require("./create/cli"), exports);
@@ -0,0 +1,4 @@
1
+ export declare function changePackageName({ directory, name, }: {
2
+ directory: string;
3
+ name: string;
4
+ }): void;
@@ -0,0 +1,17 @@
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.changePackageName = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ function changePackageName({ directory, name, }) {
10
+ const absDirPath = node_path_1.default.resolve(directory);
11
+ const packageJsonPath = node_path_1.default.join(absDirPath, "package.json");
12
+ const fileContents = node_fs_1.default.readFileSync(packageJsonPath, "utf-8");
13
+ const packageJson = JSON.parse(fileContents);
14
+ packageJson.name = name;
15
+ node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
16
+ }
17
+ exports.changePackageName = changePackageName;
@@ -1,3 +1,5 @@
1
1
  export declare function printError(message: string, component: string): void;
2
+ export declare function printSuccess(message: string, component: string): void;
3
+ export declare function printWarning(message: string, component?: string): void;
2
4
  export declare function printGenerateError(schematic: string, file: string): Promise<void>;
3
5
  export declare function printGenerateSuccess(schematic: string, file: string): Promise<void>;
@@ -3,12 +3,25 @@ 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.printSuccess = 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 printSuccess(message, component) {
14
+ process_1.stdout.write(chalk_1.default.green(`${message}:`, chalk_1.default.bold(chalk_1.default.white(`[${component}] ✔️\n`))));
15
+ }
16
+ exports.printSuccess = printSuccess;
17
+ function printWarning(message, component) {
18
+ if (component === undefined) {
19
+ process_1.stdout.write(chalk_1.default.yellow(`${message} ⚠️\n`));
20
+ return;
21
+ }
22
+ process_1.stdout.write(chalk_1.default.yellow(`${message}:`, chalk_1.default.bold(chalk_1.default.white(`[${component}] ⚠️\n`))));
23
+ }
24
+ exports.printWarning = printWarning;
12
25
  async function printGenerateError(schematic, file) {
13
26
  console.error(" ", chalk_1.default.redBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.white(`${file.split(".")[0]} not created! ❌`));
14
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/cli",
3
- "version": "1.8.2",
3
+ "version": "1.10.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
- "glob": "10.4.1",
58
- "inquirer": "8.0.0",
57
+ "glob": "10.4.5",
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",
@@ -1,4 +0,0 @@
1
- import { CommandModule } from "yargs";
2
- type CommandModuleArgs = {};
3
- declare const generateProviders: () => CommandModule<CommandModuleArgs, any>;
4
- export { generateProviders };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateProviders = void 0;
4
- const external_provider_1 = require("./external/external.provider");
5
- const prisma_provider_1 = require("./prisma/prisma.provider");
6
- const generateProviders = () => {
7
- return {
8
- command: "add <provider> [library-version] [provider-version]",
9
- describe: "Scaffold a new provider",
10
- aliases: ["a"],
11
- builder: (yargs) => {
12
- yargs
13
- .positional("provider", {
14
- choices: ["prisma", "provider"],
15
- describe: "The provider to add to the project",
16
- type: "string",
17
- alias: "p",
18
- })
19
- .option("library-version", {
20
- describe: "The library version to install",
21
- type: "string",
22
- default: "latest",
23
- alias: "v",
24
- })
25
- .option("provider-version", {
26
- describe: "The version of the provider to install",
27
- type: "string",
28
- default: "latest",
29
- alias: "vp",
30
- });
31
- return yargs;
32
- },
33
- handler: async ({ provider, libraryVersion, providerVersion }) => {
34
- if (provider === "prisma") {
35
- await (0, prisma_provider_1.prismaProvider)(libraryVersion, providerVersion);
36
- }
37
- else if (provider === "provider") {
38
- await (0, external_provider_1.externalProvider)();
39
- }
40
- },
41
- };
42
- };
43
- exports.generateProviders = generateProviders;
@@ -1,2 +0,0 @@
1
- declare const externalProvider: () => Promise<void>;
2
- export { externalProvider };