@stacksjs/cli 0.56.34 → 0.57.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.
@@ -0,0 +1 @@
1
+ export * from './install';
@@ -0,0 +1 @@
1
+ export * from "./install.mjs";
@@ -0,0 +1,27 @@
1
+ import type { CommandReturnValue } from '@stacksjs/types';
2
+ interface InstallPackageOptions {
3
+ cwd?: string;
4
+ dev?: boolean;
5
+ silent?: boolean;
6
+ packageManager?: string;
7
+ packageManagerVersion?: string;
8
+ preferOffline?: boolean;
9
+ additionalArgs?: string[];
10
+ }
11
+ /**
12
+ * Install an npm package.
13
+ *
14
+ * @param pkg - The package name to install.
15
+ * @param pkg - The options to pass to the install.The options to pass to the install.
16
+ * @returns The result of the install.
17
+ */
18
+ export declare function installPackage(pkg: string, options?: InstallPackageOptions): Promise<CommandReturnValue>;
19
+ /**
20
+ * Install a Stack into your project.
21
+ *
22
+ * @param pkg - The Stack name to install.
23
+ * @param options - The options to pass to the install.
24
+ * @returns The result of the install.
25
+ */
26
+ export declare function installStack(name: string, options?: InstallPackageOptions): Promise<CommandReturnValue>;
27
+ export {};
@@ -0,0 +1,11 @@
1
+ import { installPackage as installPkg } from "@antfu/install-pkg";
2
+ export async function installPackage(pkg, options) {
3
+ if (options)
4
+ return await installPkg(pkg, options);
5
+ return await installPkg(pkg, { silent: true });
6
+ }
7
+ export async function installStack(name, options) {
8
+ if (options)
9
+ return await installPkg(`@stacksjs/${name}`, options);
10
+ return await installPkg(`@stacksjs/${name}`, { silent: true });
11
+ }
@@ -0,0 +1,2 @@
1
+ export { cac as command } from 'cac';
2
+ export { execaCommand as spawn } from 'execa';
@@ -0,0 +1,2 @@
1
+ export { cac as command } from "cac";
2
+ export { execaCommand as spawn } from "execa";
@@ -0,0 +1,17 @@
1
+ import { log } from '@stacksjs/logging';
2
+ export declare class Prompt {
3
+ private required;
4
+ constructor();
5
+ require(): this;
6
+ isRequired(): boolean;
7
+ select(message: string, options: any): Promise<any>;
8
+ checkbox(message: string, options: any): Promise<any>;
9
+ confirm(message: string, options: any): Promise<any>;
10
+ input(message: string, options: any): Promise<any>;
11
+ password(message: string, options: any): Promise<any>;
12
+ number(message: string, options: any): Promise<any>;
13
+ multiselect(message: string, options: any): Promise<any>;
14
+ autocomplete(message: string, options: any): Promise<any>;
15
+ }
16
+ export declare const prompt: Prompt;
17
+ export { log };
@@ -0,0 +1,55 @@
1
+ import { log } from "@stacksjs/logging";
2
+ export class Prompt {
3
+ constructor() {
4
+ this.required = false;
5
+ }
6
+ require() {
7
+ this.required = true;
8
+ return this;
9
+ }
10
+ isRequired() {
11
+ return this.required;
12
+ }
13
+ async select(message, options) {
14
+ if (this.isRequired())
15
+ return log.prompt(message, { ...options, type: "select", required: true });
16
+ return log.prompt(message, { ...options, type: "select" });
17
+ }
18
+ async checkbox(message, options) {
19
+ if (this.isRequired())
20
+ return log.prompt(message, { ...options, type: "multiselect", required: true });
21
+ return log.prompt(message, { ...options, type: "multiselect" });
22
+ }
23
+ async confirm(message, options) {
24
+ if (this.isRequired())
25
+ return log.prompt(message, { ...options, type: "confirm", required: true });
26
+ return log.prompt(message, { ...options, type: "confirm" });
27
+ }
28
+ async input(message, options) {
29
+ if (this.isRequired())
30
+ return log.prompt(message, { ...options, type: "text", required: true });
31
+ return log.prompt(message, { ...options, type: "text" });
32
+ }
33
+ async password(message, options) {
34
+ if (this.isRequired())
35
+ return log.prompt(message, { ...options, type: "password", required: true });
36
+ return log.prompt(message, { ...options, type: "password" });
37
+ }
38
+ async number(message, options) {
39
+ if (this.isRequired())
40
+ return log.prompt(message, { ...options, type: "numeral", required: true });
41
+ return log.prompt(message, { ...options, type: "numeral" });
42
+ }
43
+ async multiselect(message, options) {
44
+ if (this.isRequired())
45
+ return log.prompt(message, { ...options, type: "multiselect", required: true });
46
+ return log.prompt(message, { ...options, type: "multiselect" });
47
+ }
48
+ async autocomplete(message, options) {
49
+ if (this.isRequired())
50
+ return log.prompt(message, { ...options, type: "autocomplete", required: true });
51
+ return log.prompt(message, { ...options, type: "autocomplete" });
52
+ }
53
+ }
54
+ export const prompt = new Prompt();
55
+ export { log };
@@ -0,0 +1,10 @@
1
+ import type { IntroOptions, OutroOptions } from '@stacksjs/types';
2
+ /**
3
+ * Prints the intro message.
4
+ */
5
+ export declare function intro(command: string, options?: IntroOptions): Promise<number | undefined>;
6
+ /**
7
+ * Prints the outro message.
8
+ */
9
+ export declare function outro(text: string, options: OutroOptions, error?: Error | string): void;
10
+ export declare function startSpinner(text?: string): import("ora").Ora;
@@ -0,0 +1,51 @@
1
+ import { frameworkVersion } from "@stacksjs/utils";
2
+ import { log } from "./console.mjs";
3
+ import { spinner } from "./spinner.mjs";
4
+ import { bgCyan, bold, cyan, dim, green, italic, red } from "./utilities.mjs";
5
+ export async function intro(command, options) {
6
+ const version = await frameworkVersion();
7
+ if (options?.quiet === false) {
8
+ console.log();
9
+ console.log(cyan(bold("Stacks CLI")) + dim(` v${version}`));
10
+ console.log();
11
+ }
12
+ log.info(`Preparing to run the ${bgCyan(italic(bold(` ${command} `)))} command`);
13
+ if (options?.showPerformance === false || options?.quiet)
14
+ return;
15
+ return performance.now();
16
+ }
17
+ export function outro(text, options, error) {
18
+ if (options.isError) {
19
+ if (error)
20
+ log.error(isString(error) ? new Error(error) : error);
21
+ } else {
22
+ if (options?.type === "info")
23
+ log.info(text);
24
+ log.success(text);
25
+ }
26
+ if (options.startTime) {
27
+ let time = performance.now() - options.startTime;
28
+ if (options.useSeconds) {
29
+ time = time / 1e3;
30
+ time = Math.round(time * 100) / 100;
31
+ }
32
+ if (options.quiet === true)
33
+ return;
34
+ if (options.isError)
35
+ log.error(red(`in ${time}${options.useSeconds ? "s" : "ms"}`));
36
+ else
37
+ log.success(green(`Done in ${time}${options.useSeconds ? "s" : "ms"}`));
38
+ }
39
+ }
40
+ export function startSpinner(text) {
41
+ if (!text)
42
+ text = "Executing...";
43
+ const spin = spinner({
44
+ text
45
+ }).start();
46
+ setTimeout(() => {
47
+ spin.text = italic("This may take a few moments...");
48
+ spin.spinner = "clock";
49
+ }, 7500);
50
+ return spin;
51
+ }
package/dist/index.d.ts CHANGED
@@ -1,109 +1,9 @@
1
- import * as _stacksjs_types from '@stacksjs/types';
2
- import { CommandReturnValue, IntroOptions, OutroOptions, CliOptions, ResultAsync, CommandResult } from '@stacksjs/types';
1
+ export * from './actions';
2
+ export * from './command';
3
+ export * from './console';
4
+ export * from './helpers';
5
+ export * from './parse';
6
+ export * from './run';
7
+ export * from './spinner';
8
+ export * from './utilities';
3
9
  export { ExitCode } from '@stacksjs/types';
4
- export { cac as command } from 'cac';
5
- export { execaCommand as spawn } from 'execa';
6
- import ora from 'ora';
7
- export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow } from 'kolorist';
8
- export { log } from '@stacksjs/logging';
9
-
10
- interface InstallPackageOptions {
11
- cwd?: string;
12
- dev?: boolean;
13
- silent?: boolean;
14
- packageManager?: string;
15
- packageManagerVersion?: string;
16
- preferOffline?: boolean;
17
- additionalArgs?: string[];
18
- }
19
- /**
20
- * Install an npm package.
21
- *
22
- * @param pkg - The package name to install.
23
- * @param pkg - The options to pass to the install.The options to pass to the install.
24
- * @returns The result of the install.
25
- */
26
- declare function installPackage(pkg: string, options?: InstallPackageOptions): Promise<CommandReturnValue>;
27
- /**
28
- * Install a Stack into your project.
29
- *
30
- * @param pkg - The Stack name to install.
31
- * @param options - The options to pass to the install.
32
- * @returns The result of the install.
33
- */
34
- declare function installStack(name: string, options?: InstallPackageOptions): Promise<CommandReturnValue>;
35
-
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;
51
-
52
- /**
53
- * Prints the intro message.
54
- */
55
- declare function intro(command: string, options?: IntroOptions): Promise<number | undefined>;
56
- /**
57
- * Prints the outro message.
58
- */
59
- declare function outro(text: string, options: OutroOptions, error?: Error | string): void;
60
- declare function startSpinner(text?: string): _stacksjs_types.SpinnerOptions;
61
-
62
- interface ParsedArgv {
63
- args: ReadonlyArray<string>;
64
- options: {
65
- [k: string]: string | boolean | number;
66
- };
67
- }
68
- declare function parseArgv(argv?: ReadonlyArray<string>): ParsedArgv;
69
- declare function parseOptions(argv?: ReadonlyArray<string>): {
70
- [k: string]: string | boolean | number;
71
- };
72
- declare function parseArgs(argv?: ReadonlyArray<string>): ReadonlyArray<string>;
73
-
74
- /**
75
- * Execute a command.
76
- *
77
- * @param command The command to execute.
78
- * @param options The options to pass to the command.
79
- * @param errorMsg The name of the error to throw if the command fails.
80
- * @returns The result of the command.
81
- */
82
- declare function exec(command: string, options?: CliOptions): ResultAsync<CommandReturnValue, Error>;
83
- /**
84
- * Execute a command and return result.
85
- *
86
- * @param command The command to execute.
87
- * @returns The result of the command.
88
- */
89
- declare function execSync(command: string): string;
90
- /**
91
- * Run a command the Stacks way.
92
- *
93
- * @param command The command to run.
94
- * @param options The options to pass to the command.
95
- * @returns The result of the command.
96
- */
97
- declare function runCommand(command: string, options?: CliOptions): Promise<ResultAsync<CommandReturnValue, Error>>;
98
- /**
99
- * Run many commands—the Stacks way.
100
- *
101
- * @param commands The command to run.
102
- * @param options The options to pass to the command.
103
- * @returns The result of the command.
104
- */
105
- declare function runCommands(commands: string[], options?: CliOptions): Promise<CommandResult | CommandResult[]>;
106
-
107
- declare const spinner: typeof ora;
108
-
109
- export { Prompt, exec, execSync, installPackage, installStack, intro, outro, parseArgs, parseArgv, parseOptions, prompt, runCommand, runCommands, spinner, startSpinner };
package/dist/index.mjs CHANGED
@@ -1,249 +1,9 @@
1
- import { installPackage as installPackage$1 } from '@antfu/install-pkg';
2
- export { cac as command } from 'cac';
3
- import { execaCommand } from 'execa';
4
- export { execaCommand as spawn } from 'execa';
5
- import { log } from '@stacksjs/logging';
6
- export { log } from '@stacksjs/logging';
7
- import { frameworkVersion, determineDebugLevel } from '@stacksjs/utils';
8
- import ora from 'ora';
9
- import { cyan, bold, dim, bgCyan, italic, red, green } from 'kolorist';
10
- export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow } from 'kolorist';
11
- import { execSync as execSync$1 } from 'node:child_process';
12
- import { ExitCode } from '@stacksjs/types';
13
- export { ExitCode } from '@stacksjs/types';
14
- import { projectPath } from '@stacksjs/path';
15
- import { ResultAsync } from '@stacksjs/error-handling';
16
-
17
- async function installPackage(pkg, options) {
18
- if (options)
19
- return await installPackage$1(pkg, options);
20
- return await installPackage$1(pkg, { silent: true });
21
- }
22
- async function installStack(name, options) {
23
- if (options)
24
- return await installPackage$1(`@stacksjs/${name}`, options);
25
- return await installPackage$1(`@stacksjs/${name}`, { silent: true });
26
- }
27
-
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();
81
-
82
- const spinner = ora;
83
-
84
- async function intro(command, options) {
85
- const version = await frameworkVersion();
86
- if (options?.quiet === false) {
87
- console.log();
88
- console.log(cyan(bold("Stacks CLI")) + dim(` v${version}`));
89
- console.log();
90
- }
91
- log.info(`Preparing to run the ${bgCyan(italic(bold(` ${command} `)))} command`);
92
- if (options?.showPerformance === false || options?.quiet)
93
- return;
94
- return performance.now();
95
- }
96
- function outro(text, options, error) {
97
- if (options.isError) {
98
- if (error)
99
- log.error(isString(error) ? new Error(error) : error);
100
- } else {
101
- if (options?.type === "info")
102
- log.info(text);
103
- log.success(text);
104
- }
105
- if (options.startTime) {
106
- let time = performance.now() - options.startTime;
107
- if (options.useSeconds) {
108
- time = time / 1e3;
109
- time = Math.round(time * 100) / 100;
110
- }
111
- if (options.quiet === true)
112
- return;
113
- if (options.isError)
114
- log.error(red(`in ${time}${options.useSeconds ? "s" : "ms"}`));
115
- else
116
- log.success(green(`Done in ${time}${options.useSeconds ? "s" : "ms"}`));
117
- }
118
- }
119
- function startSpinner(text) {
120
- if (!text)
121
- text = "Executing...";
122
- const spin = spinner({
123
- text
124
- }).start();
125
- setTimeout(() => {
126
- spin.text = italic("This may take a few moments...");
127
- spin.spinner = "clock";
128
- }, 7500);
129
- return spin;
130
- }
131
-
132
- function isLongOption(arg) {
133
- return arg.startsWith("--");
134
- }
135
- function isShortOption(arg) {
136
- return arg.startsWith("-") && !isLongOption(arg);
137
- }
138
- function parseValue(value) {
139
- if (value === "true")
140
- return true;
141
- if (value === "false")
142
- return false;
143
- const numberValue = Number.parseFloat(value);
144
- if (!Number.isNaN(numberValue))
145
- return numberValue;
146
- return value.replace(/"/g, "");
147
- }
148
- function parseLongOption(arg, argv, index, options) {
149
- const [key, value] = arg.slice(2).split("=");
150
- if (value !== void 0) {
151
- options[key] = parseValue(value);
152
- } else if (index + 1 < argv.length && !argv[index + 1].startsWith("-")) {
153
- options[key] = argv[index + 1];
154
- index++;
155
- } else {
156
- options[key] = true;
157
- }
158
- return index;
159
- }
160
- function parseShortOption(arg, argv, index, options) {
161
- const [key, value] = arg.slice(1).split("=");
162
- if (value !== void 0) {
163
- for (let j = 0; j < key.length; j++)
164
- options[key[j]] = parseValue(value);
165
- } else {
166
- for (let j = 0; j < key.length; j++) {
167
- if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1].startsWith("-")) {
168
- options[key[j]] = parseValue(argv[index + 1]);
169
- index++;
170
- } else {
171
- options[key[j]] = true;
172
- }
173
- }
174
- }
175
- return index;
176
- }
177
- function parseArgv(argv) {
178
- if (argv === void 0)
179
- argv = process.argv.slice(2);
180
- const args = [];
181
- const options = {};
182
- for (let i = 0; i < argv.length; i++) {
183
- const arg = argv[i];
184
- if (isLongOption(arg))
185
- i = parseLongOption(arg, argv, i, options);
186
- else if (isShortOption(arg))
187
- i = parseShortOption(arg, argv, i, options);
188
- else
189
- args.push(arg);
190
- }
191
- return { args, options };
192
- }
193
- function parseOptions(argv) {
194
- if (argv === void 0)
195
- argv = process.argv.slice(2);
196
- return parseArgv(argv).options;
197
- }
198
- function parseArgs(argv) {
199
- if (argv === void 0)
200
- argv = process.argv.slice(2);
201
- return parseArgv(argv).args;
202
- }
203
-
204
- function exec(command, options) {
205
- const cwd = options?.cwd || projectPath();
206
- const stdio = determineDebugLevel(options) ? "inherit" : "ignore";
207
- const shell = options?.shell || false;
208
- return ResultAsync.fromPromise(
209
- execaCommand(command, { stdio, cwd, shell }),
210
- () => new Error(`Failed to run command: ${italic(command)}`)
211
- );
212
- }
213
- function execSync(command) {
214
- return execSync$1(command, { encoding: "utf-8" });
215
- }
216
- async function runCommand(command, options) {
217
- return exec(command, options);
218
- }
219
- async function runCommands(commands, options) {
220
- const results = [];
221
- const numberOfCommands = commands.length;
222
- if (!numberOfCommands) {
223
- log.error(new Error("No commands were specified"));
224
- process.exit(ExitCode.FatalError);
225
- }
226
- const spinner = determineSpinner(options);
227
- for (const command of commands) {
228
- const result = await runCommand(command, options);
229
- if (result.isOk()) {
230
- results.push(result);
231
- } else if (result.isErr()) {
232
- log.error(new Error(`Failed to run command ${italic(command)}`));
233
- process.exit(ExitCode.FatalError);
234
- break;
235
- }
236
- }
237
- if (spinner)
238
- spinner.stop();
239
- if (numberOfCommands === 1)
240
- return results[0];
241
- return results;
242
- }
243
- function determineSpinner(options) {
244
- if (!determineDebugLevel(options))
245
- return startSpinner(options?.spinnerText);
246
- return void 0;
247
- }
248
-
249
- export { Prompt, exec, execSync, installPackage, installStack, intro, outro, parseArgs, parseArgv, parseOptions, prompt, runCommand, runCommands, spinner, startSpinner };
1
+ export * from "./actions/index.mjs";
2
+ export * from "./command.mjs";
3
+ export * from "./console.mjs";
4
+ export * from "./helpers.mjs";
5
+ export * from "./parse.mjs";
6
+ export * from "./run.mjs";
7
+ export * from "./spinner.mjs";
8
+ export * from "./utilities.mjs";
9
+ export { ExitCode } from "@stacksjs/types";
@@ -0,0 +1,12 @@
1
+ interface ParsedArgv {
2
+ args: ReadonlyArray<string>;
3
+ options: {
4
+ [k: string]: string | boolean | number;
5
+ };
6
+ }
7
+ export declare function parseArgv(argv?: ReadonlyArray<string>): ParsedArgv;
8
+ export declare function parseOptions(argv?: ReadonlyArray<string>): {
9
+ [k: string]: string | boolean | number;
10
+ };
11
+ export declare function parseArgs(argv?: ReadonlyArray<string>): ReadonlyArray<string>;
12
+ export {};
package/dist/parse.mjs ADDED
@@ -0,0 +1,71 @@
1
+ function isLongOption(arg) {
2
+ return arg.startsWith("--");
3
+ }
4
+ function isShortOption(arg) {
5
+ return arg.startsWith("-") && !isLongOption(arg);
6
+ }
7
+ function parseValue(value) {
8
+ if (value === "true")
9
+ return true;
10
+ if (value === "false")
11
+ return false;
12
+ const numberValue = Number.parseFloat(value);
13
+ if (!Number.isNaN(numberValue))
14
+ return numberValue;
15
+ return value.replace(/"/g, "");
16
+ }
17
+ function parseLongOption(arg, argv, index, options) {
18
+ const [key, value] = arg.slice(2).split("=");
19
+ if (value !== void 0) {
20
+ options[key] = parseValue(value);
21
+ } else if (index + 1 < argv.length && !argv[index + 1].startsWith("-")) {
22
+ options[key] = argv[index + 1];
23
+ index++;
24
+ } else {
25
+ options[key] = true;
26
+ }
27
+ return index;
28
+ }
29
+ function parseShortOption(arg, argv, index, options) {
30
+ const [key, value] = arg.slice(1).split("=");
31
+ if (value !== void 0) {
32
+ for (let j = 0; j < key.length; j++)
33
+ options[key[j]] = parseValue(value);
34
+ } else {
35
+ for (let j = 0; j < key.length; j++) {
36
+ if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1].startsWith("-")) {
37
+ options[key[j]] = parseValue(argv[index + 1]);
38
+ index++;
39
+ } else {
40
+ options[key[j]] = true;
41
+ }
42
+ }
43
+ }
44
+ return index;
45
+ }
46
+ export function parseArgv(argv) {
47
+ if (argv === void 0)
48
+ argv = process.argv.slice(2);
49
+ const args = [];
50
+ const options = {};
51
+ for (let i = 0; i < argv.length; i++) {
52
+ const arg = argv[i];
53
+ if (isLongOption(arg))
54
+ i = parseLongOption(arg, argv, i, options);
55
+ else if (isShortOption(arg))
56
+ i = parseShortOption(arg, argv, i, options);
57
+ else
58
+ args.push(arg);
59
+ }
60
+ return { args, options };
61
+ }
62
+ export function parseOptions(argv) {
63
+ if (argv === void 0)
64
+ argv = process.argv.slice(2);
65
+ return parseArgv(argv).options;
66
+ }
67
+ export function parseArgs(argv) {
68
+ if (argv === void 0)
69
+ argv = process.argv.slice(2);
70
+ return parseArgv(argv).args;
71
+ }
package/dist/run.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { CliOptions, CommandResult, CommandReturnValue, ResultAsync } from '@stacksjs/types';
2
+ /**
3
+ * Execute a command.
4
+ *
5
+ * @param command The command to execute.
6
+ * @param options The options to pass to the command.
7
+ * @param errorMsg The name of the error to throw if the command fails.
8
+ * @returns The result of the command.
9
+ */
10
+ export declare function exec(command: string, options?: CliOptions): ResultAsync<CommandReturnValue, Error>;
11
+ /**
12
+ * Execute a command and return result.
13
+ *
14
+ * @param command The command to execute.
15
+ * @returns The result of the command.
16
+ */
17
+ export declare function execSync(command: string): string;
18
+ /**
19
+ * Run a command the Stacks way.
20
+ *
21
+ * @param command The command to run.
22
+ * @param options The options to pass to the command.
23
+ * @returns The result of the command.
24
+ */
25
+ export declare function runCommand(command: string, options?: CliOptions): Promise<ResultAsync<CommandReturnValue, Error>>;
26
+ /**
27
+ * Run many commands—the Stacks way.
28
+ *
29
+ * @param commands The command to run.
30
+ * @param options The options to pass to the command.
31
+ * @returns The result of the command.
32
+ */
33
+ export declare function runCommands(commands: string[], options?: CliOptions): Promise<CommandResult | CommandResult[]>;
package/dist/run.mjs ADDED
@@ -0,0 +1,53 @@
1
+ import { execSync as childExec } from "node:child_process";
2
+ import { ExitCode } from "@stacksjs/types";
3
+ import { projectPath } from "@stacksjs/path";
4
+ import { ResultAsync as AsyncResult } from "@stacksjs/error-handling";
5
+ import { determineDebugLevel } from "@stacksjs/utils";
6
+ import { log } from "./console.mjs";
7
+ import { spawn } from "./command.mjs";
8
+ import { startSpinner } from "./helpers.mjs";
9
+ import { italic } from "./index.mjs";
10
+ export function exec(command, options) {
11
+ const cwd = options?.cwd || projectPath();
12
+ const stdio = determineDebugLevel(options) ? "inherit" : "ignore";
13
+ const shell = options?.shell || false;
14
+ return AsyncResult.fromPromise(
15
+ spawn(command, { stdio, cwd, shell }),
16
+ () => new Error(`Failed to run command: ${italic(command)}`)
17
+ );
18
+ }
19
+ export function execSync(command) {
20
+ return childExec(command, { encoding: "utf-8" });
21
+ }
22
+ export async function runCommand(command, options) {
23
+ return exec(command, options);
24
+ }
25
+ export async function runCommands(commands, options) {
26
+ const results = [];
27
+ const numberOfCommands = commands.length;
28
+ if (!numberOfCommands) {
29
+ log.error(new Error("No commands were specified"));
30
+ process.exit(ExitCode.FatalError);
31
+ }
32
+ const spinner = determineSpinner(options);
33
+ for (const command of commands) {
34
+ const result = await runCommand(command, options);
35
+ if (result.isOk()) {
36
+ results.push(result);
37
+ } else if (result.isErr()) {
38
+ log.error(new Error(`Failed to run command ${italic(command)}`));
39
+ process.exit(ExitCode.FatalError);
40
+ break;
41
+ }
42
+ }
43
+ if (spinner)
44
+ spinner.stop();
45
+ if (numberOfCommands === 1)
46
+ return results[0];
47
+ return results;
48
+ }
49
+ function determineSpinner(options) {
50
+ if (!determineDebugLevel(options))
51
+ return startSpinner(options?.spinnerText);
52
+ return void 0;
53
+ }
@@ -0,0 +1,2 @@
1
+ import ora from 'ora';
2
+ export declare const spinner: typeof ora;
@@ -0,0 +1,2 @@
1
+ import ora from "ora";
2
+ export const spinner = ora;
@@ -0,0 +1 @@
1
+ export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow } from 'kolorist';
@@ -0,0 +1 @@
1
+ export { ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, red, reset, strikethrough, underline, white, yellow } from "kolorist";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/cli",
3
3
  "type": "module",
4
- "version": "0.56.34",
4
+ "version": "0.57.2",
5
5
  "packageManager": "pnpm@8.6.5",
6
6
  "description": "The simple way to create beautiful CLIs.",
7
7
  "author": "Chris Breuer",
@@ -49,18 +49,18 @@
49
49
  "cac": "^6.7.14",
50
50
  "execa": "^7.1.1",
51
51
  "ora": "^6.3.1",
52
- "@stacksjs/config": "0.56.34",
53
- "@stacksjs/error-handling": "0.56.34",
54
- "@stacksjs/logging": "0.56.34",
55
- "@stacksjs/path": "0.56.34",
56
- "@stacksjs/types": "0.56.34",
57
- "@stacksjs/utils": "0.56.34"
52
+ "@stacksjs/config": "0.57.2",
53
+ "@stacksjs/error-handling": "0.57.2",
54
+ "@stacksjs/logging": "0.57.2",
55
+ "@stacksjs/path": "0.57.2",
56
+ "@stacksjs/types": "0.57.2",
57
+ "@stacksjs/utils": "0.57.2"
58
58
  },
59
59
  "dependencies": {
60
60
  "kolorist": "1.8.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@stacksjs/development": "0.56.34"
63
+ "@stacksjs/development": "0.57.2"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "unbuild",