@stacksjs/cli 0.57.4 → 0.58.20
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/README.md +54 -15
- package/dist/index.js +372 -0
- package/package.json +50 -30
- package/LICENSE.md +0 -21
- package/dist/actions/index.d.ts +0 -1
- package/dist/actions/index.mjs +0 -1
- package/dist/actions/install.d.ts +0 -27
- package/dist/actions/install.mjs +0 -11
- package/dist/command.d.ts +0 -2
- package/dist/command.mjs +0 -2
- package/dist/console.d.ts +0 -17
- package/dist/console.mjs +0 -55
- package/dist/helpers.d.ts +0 -10
- package/dist/helpers.mjs +0 -52
- package/dist/index.d.ts +0 -9
- package/dist/index.mjs +0 -9
- package/dist/parse.d.ts +0 -12
- package/dist/parse.mjs +0 -71
- package/dist/run.d.ts +0 -33
- package/dist/run.mjs +0 -53
- package/dist/spinner.d.ts +0 -2
- package/dist/spinner.mjs +0 -2
- package/dist/utilities.d.ts +0 -1
- package/dist/utilities.mjs +0 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The simple way to build beautiful CLIs.
|
|
|
12
12
|
## 🤖 Usage
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
|
|
15
|
+
bun install -d @stacksjs/cli
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Now, you can use it in your project:
|
|
@@ -20,12 +20,12 @@ Now, you can use it in your project:
|
|
|
20
20
|
```js
|
|
21
21
|
// command.ts
|
|
22
22
|
// you may create create a relatively complex CLI UI/UX via the following:
|
|
23
|
-
import { command,
|
|
23
|
+
import { ExitCode, command, italic, prompts, spawn, spinner } from '@stacksjs/cli'
|
|
24
24
|
|
|
25
25
|
const stacks = command('stacks')
|
|
26
26
|
|
|
27
27
|
stacks
|
|
28
|
-
.command('example', 'A dummy command') //
|
|
28
|
+
.command('example', 'A dummy command') // bun buddy example
|
|
29
29
|
.option('-i, --install', 'The install option', { default: true })
|
|
30
30
|
.action(async (options) => {
|
|
31
31
|
if (options.install)
|
|
@@ -53,9 +53,10 @@ async function install() {
|
|
|
53
53
|
setTimeout(() => {
|
|
54
54
|
spin.text = italic('This may take a few moments...')
|
|
55
55
|
}, 5000)
|
|
56
|
-
await spawn('
|
|
56
|
+
await spawn('bun install')
|
|
57
57
|
spin.stop()
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
59
60
|
log.error(error)
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -68,7 +69,7 @@ command.parse() // parse the command
|
|
|
68
69
|
You may now run the command via:
|
|
69
70
|
|
|
70
71
|
```bash
|
|
71
|
-
|
|
72
|
+
bun command.ts
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
To view a more detailed example, check out [Buddy](../../buddy/).
|
|
@@ -77,21 +78,59 @@ _You may also use any of the following CLI utilities:_
|
|
|
77
78
|
|
|
78
79
|
```js
|
|
79
80
|
import {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
ansi256Bg,
|
|
82
|
+
bgBlack,
|
|
83
|
+
bgBlue,
|
|
84
|
+
bgCyan,
|
|
85
|
+
bgGray,
|
|
86
|
+
bgGreen,
|
|
87
|
+
bgLightBlue,
|
|
88
|
+
bgLightCyan,
|
|
89
|
+
bgLightGray,
|
|
90
|
+
bgLightGreen,
|
|
91
|
+
bgLightMagenta,
|
|
92
|
+
bgLightRed,
|
|
93
|
+
bgLightYellow,
|
|
94
|
+
bgMagenta,
|
|
95
|
+
bgRed,
|
|
96
|
+
bgWhite,
|
|
97
|
+
bgYellow,
|
|
98
|
+
black,
|
|
99
|
+
blue,
|
|
100
|
+
bold,
|
|
101
|
+
cyan,
|
|
102
|
+
dim,
|
|
103
|
+
gray,
|
|
104
|
+
green,
|
|
105
|
+
hidden,
|
|
106
|
+
inverse,
|
|
107
|
+
italic,
|
|
108
|
+
lightBlue,
|
|
109
|
+
lightCyan,
|
|
110
|
+
lightGray,
|
|
111
|
+
lightGreen,
|
|
112
|
+
lightMagenta,
|
|
113
|
+
lightRed,
|
|
114
|
+
lightYellow,
|
|
115
|
+
link,
|
|
116
|
+
magenta,
|
|
117
|
+
red,
|
|
118
|
+
reset,
|
|
119
|
+
strikethrough,
|
|
120
|
+
underline,
|
|
121
|
+
white,
|
|
122
|
+
yellow
|
|
84
123
|
} from '@stacksjs/cli'
|
|
85
124
|
|
|
86
|
-
log.info(`hello ${bold(italic('world'))`)
|
|
125
|
+
log.info(`hello ${bold(italic('world'))}`)
|
|
87
126
|
```
|
|
88
127
|
|
|
89
|
-
To view the full documentation, please visit [https://stacksjs.
|
|
128
|
+
To view the full documentation, please visit [https://stacksjs.org/cli](https://stacksjs.org/cli).
|
|
90
129
|
|
|
91
130
|
## 🧪 Testing
|
|
92
131
|
|
|
93
132
|
```bash
|
|
94
|
-
|
|
133
|
+
bun test
|
|
95
134
|
```
|
|
96
135
|
|
|
97
136
|
## 📈 Changelog
|
|
@@ -110,7 +149,7 @@ For help, discussion about best practices, or any other conversation that would
|
|
|
110
149
|
|
|
111
150
|
For casual chit-chat with others using this package:
|
|
112
151
|
|
|
113
|
-
[Join the Stacks Discord Server](https://discord.
|
|
152
|
+
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
|
|
114
153
|
|
|
115
154
|
## 🙏🏼 Credits
|
|
116
155
|
|
|
@@ -126,4 +165,4 @@ Many thanks to the following core technologies & people who have contributed to
|
|
|
126
165
|
|
|
127
166
|
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
|
|
128
167
|
|
|
129
|
-
Made with
|
|
168
|
+
Made with 💙
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/actions/install.ts
|
|
3
|
+
import {installPackage as installPkg} from "@antfu/install-pkg";
|
|
4
|
+
async function installPackage(name, options) {
|
|
5
|
+
if (options)
|
|
6
|
+
return await installPkg(name, options);
|
|
7
|
+
return await installPkg(name, { silent: true });
|
|
8
|
+
}
|
|
9
|
+
async function installStack(name, options) {
|
|
10
|
+
if (options)
|
|
11
|
+
return await installPkg(`@stacksjs/${name}`, options);
|
|
12
|
+
return await installPkg(`@stacksjs/${name}`, { silent: true });
|
|
13
|
+
}
|
|
14
|
+
// src/cli.ts
|
|
15
|
+
import cac from "cac";
|
|
16
|
+
// package.json
|
|
17
|
+
var version = "0.58.20";
|
|
18
|
+
|
|
19
|
+
// src/cli.ts
|
|
20
|
+
function cli(name, options) {
|
|
21
|
+
if (typeof name === "object") {
|
|
22
|
+
options = name;
|
|
23
|
+
name = options.name;
|
|
24
|
+
}
|
|
25
|
+
const cli2 = cac(name);
|
|
26
|
+
cli2.help();
|
|
27
|
+
cli2.version(options?.version || version);
|
|
28
|
+
return cli2;
|
|
29
|
+
}
|
|
30
|
+
function parseOptions() {
|
|
31
|
+
const options = cli().parse().options;
|
|
32
|
+
for (const key in options) {
|
|
33
|
+
if (options[key] === "true")
|
|
34
|
+
options[key] = true;
|
|
35
|
+
else if (options[key] === "false")
|
|
36
|
+
options[key] = false;
|
|
37
|
+
}
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
// src/run.ts
|
|
41
|
+
import {err as err2, ok as ok2} from "@stacksjs/error-handling";
|
|
42
|
+
|
|
43
|
+
// src/exec.ts
|
|
44
|
+
import process from "process";
|
|
45
|
+
import {err, handleError, ok} from "@stacksjs/error-handling";
|
|
46
|
+
import {ExitCode} from "@stacksjs/types";
|
|
47
|
+
async function exec(command, options) {
|
|
48
|
+
const cmd = Array.isArray(command) ? command : command.match(/(?:[^\s"]+|"[^"]*")+/g);
|
|
49
|
+
if (!cmd)
|
|
50
|
+
return err(handleError(`Failed to parse command: ${cmd}`, options));
|
|
51
|
+
if (options?.verbose)
|
|
52
|
+
console.log("exec", { command, cmd, options });
|
|
53
|
+
const proc = Bun.spawn(cmd, {
|
|
54
|
+
...options,
|
|
55
|
+
stdout: options?.silent ? "ignore" : options?.stdin ? options.stdin : options?.stdout || "inherit",
|
|
56
|
+
stderr: options?.silent ? "ignore" : options?.stderr || "inherit",
|
|
57
|
+
detached: options?.background || false,
|
|
58
|
+
cwd: options?.cwd || import.meta.dir,
|
|
59
|
+
onExit(_subprocess, exitCode, _signalCode, _error) {
|
|
60
|
+
if (exitCode && exitCode !== ExitCode.Success)
|
|
61
|
+
process.exit(exitCode);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const exited = await proc.exited;
|
|
65
|
+
if (exited === ExitCode.Success)
|
|
66
|
+
return ok(proc);
|
|
67
|
+
return err(handleError(`Failed to execute command: ${cmd.join(" ")}`));
|
|
68
|
+
}
|
|
69
|
+
async function execSync(command, options) {
|
|
70
|
+
const cmd = Array.isArray(command) ? command : command.split(" ");
|
|
71
|
+
const proc = Bun.spawnSync(cmd, {
|
|
72
|
+
...options,
|
|
73
|
+
stdout: options?.stdout ?? "pipe",
|
|
74
|
+
stderr: options?.stderr ?? "inherit",
|
|
75
|
+
cwd: options?.cwd ?? import.meta.dir,
|
|
76
|
+
onExit(_subprocess, exitCode, _signalCode, _error) {
|
|
77
|
+
if (exitCode !== ExitCode.Success && exitCode)
|
|
78
|
+
process.exit(exitCode);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return proc.stdout.toString();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/utilities.ts
|
|
85
|
+
import * as kolorist from "kolorist";
|
|
86
|
+
import {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, ansi256, trueColor, trueColorBg, stripColors} from "kolorist";
|
|
87
|
+
|
|
88
|
+
// src/console.ts
|
|
89
|
+
import {log} from "@stacksjs/logging";
|
|
90
|
+
import prompts from "prompts";
|
|
91
|
+
|
|
92
|
+
class Prompt {
|
|
93
|
+
required;
|
|
94
|
+
constructor() {
|
|
95
|
+
this.required = false;
|
|
96
|
+
}
|
|
97
|
+
require() {
|
|
98
|
+
this.required = true;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
isRequired() {
|
|
102
|
+
return this.required;
|
|
103
|
+
}
|
|
104
|
+
async select(message, options) {
|
|
105
|
+
if (this.isRequired())
|
|
106
|
+
return log.prompt(message, { ...options, type: "select", required: true });
|
|
107
|
+
return log.prompt(message, { ...options, type: "select" });
|
|
108
|
+
}
|
|
109
|
+
async checkbox(message, options) {
|
|
110
|
+
if (this.isRequired())
|
|
111
|
+
return log.prompt(message, { ...options, type: "multiselect", required: true });
|
|
112
|
+
return log.prompt(message, { ...options, type: "multiselect" });
|
|
113
|
+
}
|
|
114
|
+
async confirm(message, options) {
|
|
115
|
+
if (this.isRequired())
|
|
116
|
+
return log.prompt(message, { ...options, type: "confirm", required: true });
|
|
117
|
+
return log.prompt(message, { ...options, type: "confirm" });
|
|
118
|
+
}
|
|
119
|
+
async input(message, options) {
|
|
120
|
+
if (this.isRequired())
|
|
121
|
+
return log.prompt(message, { ...options, type: "text", required: true });
|
|
122
|
+
return log.prompt(message, { ...options, type: "text" });
|
|
123
|
+
}
|
|
124
|
+
async password(message, options) {
|
|
125
|
+
if (this.isRequired())
|
|
126
|
+
return log.prompt(message, { ...options, type: "password", required: true });
|
|
127
|
+
return log.prompt(message, { ...options, type: "password" });
|
|
128
|
+
}
|
|
129
|
+
async number(message, options) {
|
|
130
|
+
if (this.isRequired())
|
|
131
|
+
return log.prompt(message, { ...options, type: "numeral", required: true });
|
|
132
|
+
return log.prompt(message, { ...options, type: "numeral" });
|
|
133
|
+
}
|
|
134
|
+
async multiselect(message, options) {
|
|
135
|
+
if (this.isRequired())
|
|
136
|
+
return log.prompt(message, { ...options, type: "multiselect", required: true });
|
|
137
|
+
return log.prompt(message, { ...options, type: "multiselect" });
|
|
138
|
+
}
|
|
139
|
+
async autocomplete(message, options) {
|
|
140
|
+
if (this.isRequired())
|
|
141
|
+
return log.prompt(message, { ...options, type: "autocomplete", required: true });
|
|
142
|
+
return log.prompt(message, { ...options, type: "autocomplete" });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
var prompt = new Prompt;
|
|
146
|
+
|
|
147
|
+
// src/run.ts
|
|
148
|
+
async function runCommand(command, options) {
|
|
149
|
+
if (options?.verbose)
|
|
150
|
+
log.debug("Running command:", underline(italic(command)), "with options:", options);
|
|
151
|
+
return await exec(command, options);
|
|
152
|
+
}
|
|
153
|
+
async function runProcess(command, options) {
|
|
154
|
+
if (options?.verbose)
|
|
155
|
+
log.debug("Running command:", underline(italic(command)), "with options:", options);
|
|
156
|
+
return await exec(command, options);
|
|
157
|
+
}
|
|
158
|
+
function runCommandSync(command, options) {
|
|
159
|
+
if (options?.verbose)
|
|
160
|
+
log.debug("Running command:", underline(italic(command)), "with options:", options);
|
|
161
|
+
const result = execSync(command, options);
|
|
162
|
+
if (result.isErr())
|
|
163
|
+
return err2(result.error);
|
|
164
|
+
return ok2(result.value);
|
|
165
|
+
}
|
|
166
|
+
async function runCommands(commands, options) {
|
|
167
|
+
const results = [];
|
|
168
|
+
for (const command of commands)
|
|
169
|
+
results.push(await runCommand(command, options));
|
|
170
|
+
return results;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/command.ts
|
|
174
|
+
class Command {
|
|
175
|
+
name;
|
|
176
|
+
description;
|
|
177
|
+
options;
|
|
178
|
+
run;
|
|
179
|
+
onFail;
|
|
180
|
+
onSuccess;
|
|
181
|
+
constructor({ name, description, options, run: run2, onFail, onSuccess }) {
|
|
182
|
+
this.name = name;
|
|
183
|
+
this.description = description;
|
|
184
|
+
this.options = options;
|
|
185
|
+
this.run = run2;
|
|
186
|
+
this.onFail = onFail;
|
|
187
|
+
this.onSuccess = onSuccess;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// src/helpers.ts
|
|
191
|
+
import {config as config2} from "@stacksjs/config";
|
|
192
|
+
import {handleError as handleError2} from "@stacksjs/error-handling";
|
|
193
|
+
import {log as log2} from "@stacksjs/logging";
|
|
194
|
+
import {ExitCode as ExitCode2} from "@stacksjs/types";
|
|
195
|
+
async function intro(command, options) {
|
|
196
|
+
return new Promise((resolve) => {
|
|
197
|
+
if (options?.quiet === false) {
|
|
198
|
+
console.log();
|
|
199
|
+
console.log(cyan(bold("Stacks CLI")) + dim(` v${version}`));
|
|
200
|
+
console.log();
|
|
201
|
+
}
|
|
202
|
+
let msg = `Preparing to run ${bgCyan(italic(bold(` ${command} `)))}`;
|
|
203
|
+
if (command === "buddy deploy")
|
|
204
|
+
msg = `Preparing to run ${bgCyan(italic(bold(` ${command} `)))} for ${bold(`${config2.app.name}`)} ${italic(`via ${config2.app.url}`)}`;
|
|
205
|
+
log2.info(msg);
|
|
206
|
+
if (options?.showPerformance === false || options?.quiet)
|
|
207
|
+
return resolve(0);
|
|
208
|
+
return resolve(performance.now());
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function outro(text, options, error) {
|
|
212
|
+
const message = options?.message || text;
|
|
213
|
+
return new Promise((resolve) => {
|
|
214
|
+
if (error)
|
|
215
|
+
return handleError2(error);
|
|
216
|
+
if (options.startTime) {
|
|
217
|
+
let time = performance.now() - options.startTime;
|
|
218
|
+
if (options.useSeconds) {
|
|
219
|
+
time = time / 1000;
|
|
220
|
+
time = Math.round(time * 100) / 100;
|
|
221
|
+
}
|
|
222
|
+
if (options.quiet === true)
|
|
223
|
+
return resolve(ExitCode2.Success);
|
|
224
|
+
if (error)
|
|
225
|
+
log2.error(`[${time.toFixed(2)}${options.useSeconds ? "s" : "ms"}] Failed`);
|
|
226
|
+
else if (options.type === "info")
|
|
227
|
+
console.log(`${dim(gray(`[${time.toFixed(2)}${options.useSeconds ? "s" : "ms"}]`))} ${message ?? "Complete"}`);
|
|
228
|
+
else
|
|
229
|
+
console.log(`${dim(gray(bold(`[${time.toFixed(2)}${options.useSeconds ? "s" : "ms"}]`)))} ${bold(green(message ?? "Complete"))}`);
|
|
230
|
+
} else {
|
|
231
|
+
if (options?.type === "info")
|
|
232
|
+
console.log(text);
|
|
233
|
+
else if (message !== text)
|
|
234
|
+
log2.success(text);
|
|
235
|
+
}
|
|
236
|
+
return resolve(ExitCode2.Success);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
// src/parse.ts
|
|
240
|
+
import process2 from "process";
|
|
241
|
+
var isLongOption = function(arg) {
|
|
242
|
+
return arg.startsWith("--");
|
|
243
|
+
};
|
|
244
|
+
var isShortOption = function(arg) {
|
|
245
|
+
return arg.startsWith("-") && !isLongOption(arg);
|
|
246
|
+
};
|
|
247
|
+
var parseValue = function(value) {
|
|
248
|
+
if (value === "true")
|
|
249
|
+
return true;
|
|
250
|
+
if (value === "false")
|
|
251
|
+
return false;
|
|
252
|
+
const numberValue = Number.parseFloat(value);
|
|
253
|
+
if (!Number.isNaN(numberValue))
|
|
254
|
+
return numberValue;
|
|
255
|
+
return value.replace(/"/g, "");
|
|
256
|
+
};
|
|
257
|
+
var parseLongOption = function(arg, argv, index, options) {
|
|
258
|
+
const [key, value] = arg.slice(2).split("=");
|
|
259
|
+
if (value !== undefined) {
|
|
260
|
+
options[key] = parseValue(value);
|
|
261
|
+
} else if (index + 1 < argv.length && !argv[index + 1].startsWith("-")) {
|
|
262
|
+
options[key] = argv[index + 1];
|
|
263
|
+
index++;
|
|
264
|
+
} else {
|
|
265
|
+
options[key] = true;
|
|
266
|
+
}
|
|
267
|
+
return index;
|
|
268
|
+
};
|
|
269
|
+
var parseShortOption = function(arg, argv, index, options) {
|
|
270
|
+
const [key, value] = arg.slice(1).split("=");
|
|
271
|
+
if (value !== undefined) {
|
|
272
|
+
for (let j = 0;j < key.length; j++)
|
|
273
|
+
options[key[j]] = parseValue(value);
|
|
274
|
+
} else {
|
|
275
|
+
for (let j = 0;j < key.length; j++) {
|
|
276
|
+
if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1].startsWith("-")) {
|
|
277
|
+
options[key[j]] = parseValue(argv[index + 1]);
|
|
278
|
+
index++;
|
|
279
|
+
} else {
|
|
280
|
+
options[key[j]] = true;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return index;
|
|
285
|
+
};
|
|
286
|
+
function parseArgv(argv) {
|
|
287
|
+
if (argv === undefined)
|
|
288
|
+
argv = process2.argv.slice(2);
|
|
289
|
+
const args = [];
|
|
290
|
+
const options = {};
|
|
291
|
+
for (let i = 0;i < argv.length; i++) {
|
|
292
|
+
const arg = argv[i];
|
|
293
|
+
if (isLongOption(arg))
|
|
294
|
+
i = parseLongOption(arg, argv, i, options);
|
|
295
|
+
else if (isShortOption(arg))
|
|
296
|
+
i = parseShortOption(arg, argv, i, options);
|
|
297
|
+
else
|
|
298
|
+
args.push(arg);
|
|
299
|
+
}
|
|
300
|
+
return { args, options };
|
|
301
|
+
}
|
|
302
|
+
// src/spinner.ts
|
|
303
|
+
import ora from "ora";
|
|
304
|
+
var spinner = ora;
|
|
305
|
+
export {
|
|
306
|
+
yellow,
|
|
307
|
+
white,
|
|
308
|
+
underline,
|
|
309
|
+
trueColorBg,
|
|
310
|
+
trueColor,
|
|
311
|
+
stripColors,
|
|
312
|
+
strikethrough,
|
|
313
|
+
spinner,
|
|
314
|
+
runProcess,
|
|
315
|
+
runCommands,
|
|
316
|
+
runCommandSync,
|
|
317
|
+
runCommand,
|
|
318
|
+
reset,
|
|
319
|
+
red,
|
|
320
|
+
prompts,
|
|
321
|
+
prompt,
|
|
322
|
+
parseOptions,
|
|
323
|
+
parseArgv,
|
|
324
|
+
outro,
|
|
325
|
+
magenta,
|
|
326
|
+
log,
|
|
327
|
+
link,
|
|
328
|
+
lightYellow,
|
|
329
|
+
lightRed,
|
|
330
|
+
lightMagenta,
|
|
331
|
+
lightGreen,
|
|
332
|
+
lightGray,
|
|
333
|
+
lightCyan,
|
|
334
|
+
lightBlue,
|
|
335
|
+
kolorist,
|
|
336
|
+
italic,
|
|
337
|
+
inverse,
|
|
338
|
+
intro,
|
|
339
|
+
installStack,
|
|
340
|
+
installPackage,
|
|
341
|
+
hidden,
|
|
342
|
+
green,
|
|
343
|
+
gray,
|
|
344
|
+
execSync,
|
|
345
|
+
exec,
|
|
346
|
+
dim,
|
|
347
|
+
cyan,
|
|
348
|
+
cli,
|
|
349
|
+
bold,
|
|
350
|
+
blue,
|
|
351
|
+
black,
|
|
352
|
+
bgYellow,
|
|
353
|
+
bgWhite,
|
|
354
|
+
bgRed,
|
|
355
|
+
bgMagenta,
|
|
356
|
+
bgLightYellow,
|
|
357
|
+
bgLightRed,
|
|
358
|
+
bgLightMagenta,
|
|
359
|
+
bgLightGreen,
|
|
360
|
+
bgLightGray,
|
|
361
|
+
bgLightCyan,
|
|
362
|
+
bgLightBlue,
|
|
363
|
+
bgGreen,
|
|
364
|
+
bgGray,
|
|
365
|
+
bgCyan,
|
|
366
|
+
bgBlue,
|
|
367
|
+
bgBlack,
|
|
368
|
+
ansi256Bg,
|
|
369
|
+
ansi256,
|
|
370
|
+
Prompt,
|
|
371
|
+
Command
|
|
372
|
+
};
|
package/package.json
CHANGED
|
@@ -1,70 +1,90 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"
|
|
6
|
-
"description": "The simple way to create beautiful CLIs.",
|
|
4
|
+
"version": "0.58.20",
|
|
5
|
+
"description": "TypeScript framework for CLI artisans. Build beautiful console apps with ease.",
|
|
7
6
|
"author": "Chris Breuer",
|
|
8
7
|
"license": "MIT",
|
|
9
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
10
|
-
"homepage": "https://github.com/stacksjs/stacks/tree/main
|
|
9
|
+
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/src/cli#readme",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
12
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
14
|
-
"directory": "
|
|
13
|
+
"directory": "./storage/framework/core/src/cli"
|
|
15
14
|
},
|
|
16
15
|
"bugs": {
|
|
17
16
|
"url": "https://github.com/stacksjs/stacks/issues"
|
|
18
17
|
},
|
|
19
18
|
"keywords": [
|
|
19
|
+
"bun",
|
|
20
20
|
"cli",
|
|
21
21
|
"commands",
|
|
22
22
|
"command line interface",
|
|
23
|
+
"console",
|
|
24
|
+
"binary",
|
|
25
|
+
"apps",
|
|
26
|
+
"prompts",
|
|
23
27
|
"spinners",
|
|
24
28
|
"utilities",
|
|
25
29
|
"helpers",
|
|
26
30
|
"cac",
|
|
27
31
|
"ora",
|
|
28
|
-
"consola",
|
|
29
|
-
"ez-spawn",
|
|
30
32
|
"stacks"
|
|
31
33
|
],
|
|
32
34
|
"exports": {
|
|
33
35
|
".": {
|
|
34
|
-
"
|
|
35
|
-
"import": "./dist/index.
|
|
36
|
+
"bun": "./src/index.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./*": {
|
|
40
|
+
"bun": "./*",
|
|
41
|
+
"import": "./dist/*"
|
|
36
42
|
}
|
|
37
43
|
},
|
|
38
|
-
"module": "dist/index.
|
|
44
|
+
"module": "dist/index.js",
|
|
39
45
|
"types": "dist/index.d.ts",
|
|
40
46
|
"contributors": [
|
|
41
|
-
"Chris Breuer <chris@
|
|
47
|
+
"Chris Breuer <chris@stacksjs.org>"
|
|
42
48
|
],
|
|
43
49
|
"files": [
|
|
44
|
-
"
|
|
45
|
-
"
|
|
50
|
+
"README.md",
|
|
51
|
+
"dist"
|
|
46
52
|
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "bun --bun build.ts",
|
|
55
|
+
"typecheck": "bun --bun tsc --noEmit",
|
|
56
|
+
"prepublishOnly": "bun --bun run build"
|
|
57
|
+
},
|
|
47
58
|
"peerDependencies": {
|
|
48
|
-
"@antfu/install-pkg": "^0.
|
|
59
|
+
"@antfu/install-pkg": "^0.3.1",
|
|
60
|
+
"@stacksjs/config": "workspace:*",
|
|
61
|
+
"@stacksjs/error-handling": "workspace:*",
|
|
62
|
+
"@stacksjs/logging": "workspace:*",
|
|
63
|
+
"@stacksjs/path": "workspace:*",
|
|
64
|
+
"@stacksjs/types": "workspace:*",
|
|
65
|
+
"@stacksjs/utils": "workspace:*",
|
|
66
|
+
"@stacksjs/validation": "workspace:*",
|
|
67
|
+
"@types/prompts": "^2.4.9",
|
|
49
68
|
"cac": "^6.7.14",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"@stacksjs/config": "0.57.4",
|
|
53
|
-
"@stacksjs/error-handling": "0.57.4",
|
|
54
|
-
"@stacksjs/logging": "0.57.4",
|
|
55
|
-
"@stacksjs/path": "0.57.4",
|
|
56
|
-
"@stacksjs/types": "0.57.4",
|
|
57
|
-
"@stacksjs/utils": "0.57.4"
|
|
69
|
+
"ora": "^8.0.1",
|
|
70
|
+
"prompts": "^2.4.2"
|
|
58
71
|
},
|
|
59
72
|
"dependencies": {
|
|
60
|
-
"
|
|
73
|
+
"@antfu/install-pkg": "^0.3.1",
|
|
74
|
+
"@stacksjs/config": "workspace:*",
|
|
75
|
+
"@stacksjs/error-handling": "workspace:*",
|
|
76
|
+
"@stacksjs/logging": "workspace:*",
|
|
77
|
+
"@stacksjs/path": "workspace:*",
|
|
78
|
+
"@stacksjs/types": "workspace:*",
|
|
79
|
+
"@stacksjs/utils": "workspace:*",
|
|
80
|
+
"@stacksjs/validation": "workspace:*",
|
|
81
|
+
"@types/prompts": "^2.4.9",
|
|
82
|
+
"cac": "^6.7.14",
|
|
83
|
+
"kolorist": "1.8.0",
|
|
84
|
+
"ora": "^8.0.1",
|
|
85
|
+
"prompts": "^2.4.2"
|
|
61
86
|
},
|
|
62
87
|
"devDependencies": {
|
|
63
|
-
"@stacksjs/development": "
|
|
64
|
-
},
|
|
65
|
-
"scripts": {
|
|
66
|
-
"build": "unbuild",
|
|
67
|
-
"dev": "unbuild --stub",
|
|
68
|
-
"typecheck": "tsc --noEmit"
|
|
88
|
+
"@stacksjs/development": "workspace:*"
|
|
69
89
|
}
|
|
70
|
-
}
|
|
90
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Open Web Foundation
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/actions/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './install';
|
package/dist/actions/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./install.mjs";
|
|
@@ -1,27 +0,0 @@
|
|
|
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 {};
|
package/dist/actions/install.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/command.d.ts
DELETED
package/dist/command.mjs
DELETED
package/dist/console.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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 };
|
package/dist/console.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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 };
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
package/dist/helpers.mjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { frameworkVersion } from "@stacksjs/utils";
|
|
2
|
-
import { isString } from "@stacksjs/validation";
|
|
3
|
-
import { log } from "./console.mjs";
|
|
4
|
-
import { spinner } from "./spinner.mjs";
|
|
5
|
-
import { bgCyan, bold, cyan, dim, green, italic, red } from "./utilities.mjs";
|
|
6
|
-
export async function intro(command, options) {
|
|
7
|
-
const version = await frameworkVersion();
|
|
8
|
-
if (options?.quiet === false) {
|
|
9
|
-
console.log();
|
|
10
|
-
console.log(cyan(bold("Stacks CLI")) + dim(` v${version}`));
|
|
11
|
-
console.log();
|
|
12
|
-
}
|
|
13
|
-
log.info(`Preparing to run the ${bgCyan(italic(bold(` ${command} `)))} command`);
|
|
14
|
-
if (options?.showPerformance === false || options?.quiet)
|
|
15
|
-
return;
|
|
16
|
-
return performance.now();
|
|
17
|
-
}
|
|
18
|
-
export function outro(text, options, error) {
|
|
19
|
-
if (options.isError) {
|
|
20
|
-
if (error)
|
|
21
|
-
log.error(isString(error) ? new Error(error) : error);
|
|
22
|
-
} else {
|
|
23
|
-
if (options?.type === "info")
|
|
24
|
-
log.info(text);
|
|
25
|
-
log.success(text);
|
|
26
|
-
}
|
|
27
|
-
if (options.startTime) {
|
|
28
|
-
let time = performance.now() - options.startTime;
|
|
29
|
-
if (options.useSeconds) {
|
|
30
|
-
time = time / 1e3;
|
|
31
|
-
time = Math.round(time * 100) / 100;
|
|
32
|
-
}
|
|
33
|
-
if (options.quiet === true)
|
|
34
|
-
return;
|
|
35
|
-
if (options.isError)
|
|
36
|
-
log.error(red(`in ${time}${options.useSeconds ? "s" : "ms"}`));
|
|
37
|
-
else
|
|
38
|
-
log.success(green(`Done in ${time}${options.useSeconds ? "s" : "ms"}`));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export function startSpinner(text) {
|
|
42
|
-
if (!text)
|
|
43
|
-
text = "Executing...";
|
|
44
|
-
const spin = spinner({
|
|
45
|
-
text
|
|
46
|
-
}).start();
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
spin.text = italic("This may take a few moments...");
|
|
49
|
-
spin.spinner = "clock";
|
|
50
|
-
}, 7500);
|
|
51
|
-
return spin;
|
|
52
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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';
|
|
9
|
-
export { ExitCode } from '@stacksjs/types';
|
package/dist/index.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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";
|
package/dist/parse.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/spinner.d.ts
DELETED
package/dist/spinner.mjs
DELETED
package/dist/utilities.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/dist/utilities.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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";
|