@expressots/cli 1.11.1 → 1.12.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
@@ -16,6 +16,7 @@ const new_1 = require("./new");
16
16
  const providers_1 = require("./providers");
17
17
  const cli_2 = require("./providers/create/cli");
18
18
  const cli_ui_1 = require("./utils/cli-ui");
19
+ const scripts_1 = require("./scripts");
19
20
  process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n`);
20
21
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
21
22
  .scriptName("expressots")
@@ -26,6 +27,7 @@ process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n
26
27
  .command((0, cli_2.createExternalProviderCMD)())
27
28
  .command((0, providers_1.addProviderCMD)())
28
29
  .command((0, generate_1.generateProject)())
30
+ .command((0, scripts_1.scriptsCommand)())
29
31
  .command((0, info_1.infoProject)())
30
32
  .command((0, cli_1.helpCommand)())
31
33
  .demandCommand(1, "You need at least one command before moving on")
@@ -33,7 +35,6 @@ process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n
33
35
  .fail((msg, err, yargs) => {
34
36
  if (msg) {
35
37
  if (msg.includes("Unknown argument")) {
36
- // Get the command name
37
38
  const command = process.argv[2];
38
39
  if (command === "run") {
39
40
  (0, cli_ui_1.printError)(`The "run" command has been removed. Use "dev", "prod" or "build" instead.`, "expressots help");
package/bin/help/form.js CHANGED
@@ -15,7 +15,7 @@ const helpForm = async () => {
15
15
  ],
16
16
  colWidths: [15, 15, 60],
17
17
  });
18
- table.push(["new project", "new", "Generate a new project"], ["info", "i", "Provides project information"], ["resources", "r", "Displays cli commands and resources"], ["help", "h", "Show command help"], [
18
+ table.push(["new project", "new", "Generate a new project"], ["info", "i", "Provides project information"], ["resources", "r", "Displays cli commands and resources"], ["scripts", "scripts", "Run scripts list or specific scripts"], ["help", "h", "Show command help"], [
19
19
  "service",
20
20
  "g s",
21
21
  "Generate a service [controller, usecase, dto, module]",
@@ -0,0 +1,3 @@
1
+ import { CommandModule } from "yargs";
2
+ declare const scriptsCommand: () => CommandModule;
3
+ export { scriptsCommand };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scriptsCommand = void 0;
4
+ const form_1 = require("./form");
5
+ const scriptsCommand = () => {
6
+ return {
7
+ command: "scripts [scripts..]",
8
+ describe: "Run scripts list or specific scripts",
9
+ builder: (yargs) => {
10
+ return yargs.positional("scripts", {
11
+ describe: "The names of the scripts to run",
12
+ type: "string",
13
+ array: true,
14
+ });
15
+ },
16
+ handler: async (argv) => {
17
+ const scripts = Array.isArray(argv.scripts)
18
+ ? argv.scripts.filter((script) => typeof script === "string")
19
+ : [];
20
+ await (0, form_1.scriptsForm)(scripts);
21
+ },
22
+ };
23
+ };
24
+ exports.scriptsCommand = scriptsCommand;
@@ -0,0 +1 @@
1
+ export declare const scriptsForm: (scriptArgs?: string[]) => Promise<void>;
@@ -0,0 +1,107 @@
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.scriptsForm = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const inquirer_1 = __importDefault(require("inquirer"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const cli_ui_1 = require("../utils/cli-ui");
12
+ const cwd = process.cwd();
13
+ const packageJsonPath = path_1.default.join(cwd, "package.json");
14
+ function readPackageJson() {
15
+ try {
16
+ return JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf8"));
17
+ }
18
+ catch (e) {
19
+ (0, cli_ui_1.printError)(`Error reading package.json`, "scripts-command");
20
+ process.exit(1);
21
+ }
22
+ }
23
+ function listScripts(packageJson) {
24
+ const scripts = packageJson.scripts || {};
25
+ if (Object.keys(scripts).length === 0) {
26
+ (0, cli_ui_1.printWarning)("No scripts found in package.json", "scripts-command");
27
+ process.exit(0);
28
+ }
29
+ return scripts;
30
+ }
31
+ async function promptUserToSelectScripts(scripts) {
32
+ const scriptChoices = Object.keys(scripts).map((key) => ({
33
+ name: `${key}`,
34
+ value: key,
35
+ }));
36
+ let selectionOrder = [];
37
+ const answers = await inquirer_1.default.prompt([
38
+ {
39
+ type: "checkbox",
40
+ name: "selectedScripts",
41
+ message: "Select scripts to run:",
42
+ choices: scriptChoices,
43
+ filter: (selected) => {
44
+ selectionOrder = selected;
45
+ return selected;
46
+ },
47
+ loop: false,
48
+ },
49
+ ]);
50
+ return answers;
51
+ }
52
+ function executeScripts(scripts, selectedScripts, runner) {
53
+ selectedScripts.forEach((script) => {
54
+ console.log(`Running ${script}...`);
55
+ try {
56
+ const command = `${runner} run ${script}`;
57
+ const options = {
58
+ stdio: "inherit",
59
+ env: { ...process.env },
60
+ };
61
+ (0, child_process_1.execSync)(command, options);
62
+ }
63
+ catch (e) {
64
+ (0, cli_ui_1.printWarning)(`Command ${script} cancelled or failed - ${e}`, "scripts-command");
65
+ }
66
+ });
67
+ }
68
+ process.stdin.on("keypress", (ch, key) => {
69
+ if (key && key.name === "escape") {
70
+ console.log("Exiting...");
71
+ process.exit(0);
72
+ }
73
+ });
74
+ const scriptsForm = async (scriptArgs = []) => {
75
+ const packageJson = readPackageJson();
76
+ const scripts = listScripts(packageJson);
77
+ const runner = fs_1.default.existsSync("package-lock.json")
78
+ ? "npm"
79
+ : fs_1.default.existsSync("yarn.lock")
80
+ ? "yarn"
81
+ : fs_1.default.existsSync("pnpm-lock.yaml")
82
+ ? "pnpm"
83
+ : null;
84
+ if (!runner) {
85
+ (0, cli_ui_1.printError)("No package manager found! Please ensure you have npm, yarn, or pnpm installed.", "scripts-command");
86
+ process.exit(1);
87
+ }
88
+ if (scriptArgs.length > 0) {
89
+ const validScripts = scriptArgs.filter((script) => scripts[script]);
90
+ const invalidScripts = scriptArgs.filter((script) => !scripts[script]);
91
+ if (invalidScripts.length > 0) {
92
+ console.error(`Scripts not found in package.json: ${invalidScripts.join(", ")}`);
93
+ }
94
+ if (validScripts.length > 0) {
95
+ executeScripts(scripts, validScripts, runner);
96
+ }
97
+ }
98
+ else {
99
+ const { selectedScripts } = await promptUserToSelectScripts(scripts);
100
+ if (selectedScripts.length === 0) {
101
+ console.log("No scripts selected.");
102
+ process.exit(0);
103
+ }
104
+ executeScripts(scripts, selectedScripts, runner);
105
+ }
106
+ };
107
+ exports.scriptsForm = scriptsForm;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/cli",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
5
5
  "author": "Richard Zampieri",
6
6
  "license": "MIT",