@stacksjs/cli 0.53.1 → 0.56.23

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/dist/index.d.ts CHANGED
@@ -33,40 +33,21 @@ declare function installPackage(pkg: string, options?: InstallPackageOptions): P
33
33
  */
34
34
  declare function installStack(name: string, options?: InstallPackageOptions): Promise<CommandReturnValue>;
35
35
 
36
- declare const prompt: <T extends {
37
- type?: "text" | undefined;
38
- default?: string | undefined;
39
- placeholder?: string | undefined;
40
- initial?: string | undefined;
41
- } | {
42
- type: "confirm";
43
- initial?: boolean | undefined;
44
- } | {
45
- type: "select";
46
- initial?: string | undefined;
47
- options: (string | {
48
- label: string;
49
- value: string;
50
- hint?: string | undefined;
51
- })[];
52
- } | {
53
- type: "multiselect";
54
- initial?: string | undefined;
55
- options: string[] | {
56
- label: string;
57
- value: string;
58
- hint?: string | undefined;
59
- }[];
60
- required?: boolean | undefined;
61
- }>(message: string, opts?: T | undefined) => Promise<T extends {
62
- type?: "text" | undefined;
63
- default?: string | undefined;
64
- placeholder?: string | undefined;
65
- initial?: string | undefined;
66
- } ? string : T extends {
67
- type: "confirm";
68
- initial?: boolean | undefined;
69
- } ? boolean : string[]>;
36
+ declare class Prompt {
37
+ private required;
38
+ constructor();
39
+ require(): this;
40
+ isRequired(): boolean;
41
+ select(message: string, options: any): Promise<any>;
42
+ checkbox(message: string, options: any): Promise<any>;
43
+ confirm(message: string, options: any): Promise<any>;
44
+ input(message: string, options: any): Promise<any>;
45
+ password(message: string, options: any): Promise<any>;
46
+ number(message: string, options: any): Promise<any>;
47
+ multiselect(message: string, options: any): Promise<any>;
48
+ autocomplete(message: string, options: any): Promise<any>;
49
+ }
50
+ declare const prompt: Prompt;
70
51
 
71
52
  /**
72
53
  * Prints the intro message.
@@ -125,4 +106,4 @@ declare function runCommands(commands: string[], options?: CliOptions): Promise<
125
106
 
126
107
  declare const spinner: typeof ora;
127
108
 
128
- export { exec, execSync, installPackage, installStack, intro, outro, parseArgs, parseArgv, parseOptions, prompt, runCommand, runCommands, spinner, startSpinner };
109
+ export { Prompt, exec, execSync, installPackage, installStack, intro, outro, parseArgs, parseArgv, parseOptions, prompt, runCommand, runCommands, spinner, startSpinner };
package/dist/index.mjs CHANGED
@@ -25,7 +25,59 @@ async function installStack(name, options) {
25
25
  return await installPackage$1(`@stacksjs/${name}`, { silent: true });
26
26
  }
27
27
 
28
- const prompt = log.prompt;
28
+ class Prompt {
29
+ constructor() {
30
+ this.required = false;
31
+ }
32
+ require() {
33
+ this.required = true;
34
+ return this;
35
+ }
36
+ isRequired() {
37
+ return this.required;
38
+ }
39
+ async select(message, options) {
40
+ if (this.isRequired())
41
+ return log.prompt(message, { ...options, type: "select", required: true });
42
+ return log.prompt(message, { ...options, type: "select" });
43
+ }
44
+ async checkbox(message, options) {
45
+ if (this.isRequired())
46
+ return log.prompt(message, { ...options, type: "multiselect", required: true });
47
+ return log.prompt(message, { ...options, type: "multiselect" });
48
+ }
49
+ async confirm(message, options) {
50
+ if (this.isRequired())
51
+ return log.prompt(message, { ...options, type: "confirm", required: true });
52
+ return log.prompt(message, { ...options, type: "confirm" });
53
+ }
54
+ async input(message, options) {
55
+ if (this.isRequired())
56
+ return log.prompt(message, { ...options, type: "text", required: true });
57
+ return log.prompt(message, { ...options, type: "text" });
58
+ }
59
+ async password(message, options) {
60
+ if (this.isRequired())
61
+ return log.prompt(message, { ...options, type: "password", required: true });
62
+ return log.prompt(message, { ...options, type: "password" });
63
+ }
64
+ async number(message, options) {
65
+ if (this.isRequired())
66
+ return log.prompt(message, { ...options, type: "numeral", required: true });
67
+ return log.prompt(message, { ...options, type: "numeral" });
68
+ }
69
+ async multiselect(message, options) {
70
+ if (this.isRequired())
71
+ return log.prompt(message, { ...options, type: "multiselect", required: true });
72
+ return log.prompt(message, { ...options, type: "multiselect" });
73
+ }
74
+ async autocomplete(message, options) {
75
+ if (this.isRequired())
76
+ return log.prompt(message, { ...options, type: "autocomplete", required: true });
77
+ return log.prompt(message, { ...options, type: "autocomplete" });
78
+ }
79
+ }
80
+ const prompt = new Prompt();
29
81
 
30
82
  const spinner = ora;
31
83
 
@@ -44,7 +96,7 @@ async function intro(command, options) {
44
96
  function outro(text, options, error) {
45
97
  if (options.isError) {
46
98
  if (error)
47
- log.error(error);
99
+ log.error(isString(error) ? new Error(error) : error);
48
100
  } else {
49
101
  if (options?.type === "info")
50
102
  log.info(text);
@@ -88,8 +140,8 @@ function parseValue(value) {
88
140
  return true;
89
141
  if (value === "false")
90
142
  return false;
91
- const numberValue = parseFloat(value);
92
- if (!isNaN(numberValue))
143
+ const numberValue = Number.parseFloat(value);
144
+ if (!Number.isNaN(numberValue))
93
145
  return numberValue;
94
146
  return value.replace(/"/g, "");
95
147
  }
@@ -169,7 +221,7 @@ async function runCommands(commands, options) {
169
221
  const numberOfCommands = commands.length;
170
222
  if (!numberOfCommands) {
171
223
  log.error(new Error("No commands were specified"));
172
- process.exit();
224
+ process.exit(ExitCode.FatalError);
173
225
  }
174
226
  const spinner = determineSpinner(options);
175
227
  for (const command of commands) {
@@ -177,11 +229,8 @@ async function runCommands(commands, options) {
177
229
  if (result.isOk()) {
178
230
  results.push(result);
179
231
  } else if (result.isErr()) {
180
- if (spinner) {
181
- log.error(new Error(`Failed to run command ${italic(command)}`));
182
- process.exit(ExitCode.FatalError);
183
- }
184
- results.push(result);
232
+ log.error(new Error(`Failed to run command ${italic(command)}`));
233
+ process.exit(ExitCode.FatalError);
185
234
  break;
186
235
  }
187
236
  }
@@ -197,4 +246,4 @@ function determineSpinner(options) {
197
246
  return void 0;
198
247
  }
199
248
 
200
- export { exec, execSync, installPackage, installStack, intro, outro, parseArgs, parseArgv, parseOptions, prompt, runCommand, runCommands, spinner, startSpinner };
249
+ export { Prompt, exec, execSync, installPackage, installStack, intro, outro, parseArgs, parseArgv, parseOptions, prompt, runCommand, runCommands, spinner, startSpinner };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stacksjs/cli",
3
3
  "type": "module",
4
- "version": "0.53.1",
5
- "packageManager": "pnpm@8.5.1",
4
+ "version": "0.56.23",
5
+ "packageManager": "pnpm@8.6.5",
6
6
  "description": "The simple way to create beautiful CLIs.",
7
7
  "author": "Chris Breuer",
8
8
  "license": "MIT",
@@ -50,18 +50,18 @@
50
50
  "cac": "^6.7.14",
51
51
  "execa": "^7.1.1",
52
52
  "ora": "^6.3.1",
53
- "@stacksjs/config": "0.53.1",
54
- "@stacksjs/error-handling": "0.53.1",
55
- "@stacksjs/logging": "0.53.1",
56
- "@stacksjs/path": "0.53.1",
57
- "@stacksjs/types": "0.53.1",
58
- "@stacksjs/utils": "0.53.1"
53
+ "@stacksjs/config": "0.56.23",
54
+ "@stacksjs/error-handling": "0.56.23",
55
+ "@stacksjs/logging": "0.56.23",
56
+ "@stacksjs/path": "0.56.23",
57
+ "@stacksjs/types": "0.56.23",
58
+ "@stacksjs/utils": "0.56.23"
59
59
  },
60
60
  "dependencies": {
61
61
  "kolorist": "1.8.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@stacksjs/development": "0.53.1"
64
+ "@stacksjs/development": "0.56.23"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "unbuild",