@stacksjs/cli 0.63.0 → 0.64.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/README.md +161 -0
- package/dist/index.js +18 -830
- package/dist/index.js.map +105 -5
- package/package.json +7 -21
- package/src/app.ts +773 -0
- package/src/console.ts +2 -109
- package/src/helpers.ts +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,166 @@ You may now run the command via:
|
|
|
72
72
|
bun command.ts
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
## CLI Apps
|
|
76
|
+
|
|
77
|
+
### Setup
|
|
78
|
+
|
|
79
|
+
The `intro` and `outro` functions will print a message to begin or end a prompt session, respectively.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
import { intro, outro } from '@stacksjs/cli';
|
|
83
|
+
|
|
84
|
+
intro(`create-my-app`);
|
|
85
|
+
// Do stuff
|
|
86
|
+
outro(`You're all set!`);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Cancellation
|
|
90
|
+
|
|
91
|
+
The `isCancel` function is a guard that detects when a user cancels a question with `CTRL + C`. You should handle this situation for each prompt, optionally providing a nice cancellation message with the `cancel` utility.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { isCancel, cancel, text } from '@stacksjs/cli';
|
|
95
|
+
|
|
96
|
+
const value = await text(/* TODO */);
|
|
97
|
+
|
|
98
|
+
if (isCancel(value)) {
|
|
99
|
+
cancel('Operation cancelled.');
|
|
100
|
+
process.exit(0);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Components
|
|
105
|
+
|
|
106
|
+
### Text
|
|
107
|
+
|
|
108
|
+
The text component accepts a single line of text.
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
import { text } from '@stacksjs/cli';
|
|
112
|
+
|
|
113
|
+
const meaning = await text({
|
|
114
|
+
message: 'What is the meaning of life?',
|
|
115
|
+
placeholder: 'Not sure',
|
|
116
|
+
initialValue: '42',
|
|
117
|
+
validate(value) {
|
|
118
|
+
if (value.length === 0) return `Value is required!`;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Confirm
|
|
124
|
+
|
|
125
|
+
The confirm component accepts a yes or no answer. The result is a boolean value of `true` or `false`.
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
import { confirm } from '@stacksjs/cli';
|
|
129
|
+
|
|
130
|
+
const shouldContinue = await confirm({
|
|
131
|
+
message: 'Do you want to continue?',
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Select
|
|
136
|
+
|
|
137
|
+
The select component allows a user to choose one value from a list of options. The result is the `value` prop of a given option.
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
import { select } from '@stacksjs/cli';
|
|
141
|
+
|
|
142
|
+
const projectType = await select({
|
|
143
|
+
message: 'Pick a project type.',
|
|
144
|
+
options: [
|
|
145
|
+
{ value: 'ts', label: 'TypeScript' },
|
|
146
|
+
{ value: 'js', label: 'JavaScript' },
|
|
147
|
+
{ value: 'coffee', label: 'CoffeeScript', hint: 'oh no' },
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Multi-Select
|
|
153
|
+
|
|
154
|
+
The `multiselect` component allows a user to choose many values from a list of options. The result is an array with all selected `value` props.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { multiselect } from '@stacksjs/cli';
|
|
158
|
+
|
|
159
|
+
const additionalTools = await multiselect({
|
|
160
|
+
message: 'Select additional tools.',
|
|
161
|
+
options: [
|
|
162
|
+
{ value: 'eslint', label: 'ESLint', hint: 'recommended' },
|
|
163
|
+
{ value: 'prettier', label: 'Prettier' },
|
|
164
|
+
{ value: 'gh-action', label: 'GitHub Action' },
|
|
165
|
+
],
|
|
166
|
+
required: false,
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Spinner
|
|
171
|
+
|
|
172
|
+
The spinner component surfaces a pending action, such as a long-running download or dependency installation.
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import { spinner } from '@stacksjs/cli';
|
|
176
|
+
|
|
177
|
+
const s = spinner();
|
|
178
|
+
s.start('Installing via npm');
|
|
179
|
+
// Do installation here
|
|
180
|
+
s.stop('Installed via npm');
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Utilities
|
|
184
|
+
|
|
185
|
+
### Grouping
|
|
186
|
+
|
|
187
|
+
Grouping prompts together is a great way to keep your code organized. This accepts a JSON object with a name that can be used to reference the group later. The second argument is an optional but has a `onCancel` callback that will be called if the user cancels one of the prompts in the group.
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
import * as p from '@stacksjs/cli';
|
|
191
|
+
|
|
192
|
+
const group = await p.group(
|
|
193
|
+
{
|
|
194
|
+
name: () => p.text({ message: 'What is your name?' }),
|
|
195
|
+
age: () => p.text({ message: 'What is your age?' }),
|
|
196
|
+
color: ({ results }) =>
|
|
197
|
+
p.multiselect({
|
|
198
|
+
message: `What is your favorite color ${results.name}?`,
|
|
199
|
+
options: [
|
|
200
|
+
{ value: 'red', label: 'Red' },
|
|
201
|
+
{ value: 'green', label: 'Green' },
|
|
202
|
+
{ value: 'blue', label: 'Blue' },
|
|
203
|
+
],
|
|
204
|
+
}),
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
// On Cancel callback that wraps the group
|
|
208
|
+
// So if the user cancels one of the prompts in the group this function will be called
|
|
209
|
+
onCancel: ({ results }) => {
|
|
210
|
+
p.cancel('Operation cancelled.');
|
|
211
|
+
process.exit(0);
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
console.log(group.name, group.age, group.color);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Tasks
|
|
220
|
+
|
|
221
|
+
Execute multiple tasks in spinners.
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
await p.tasks([
|
|
225
|
+
{
|
|
226
|
+
title: 'Installing via npm',
|
|
227
|
+
task: async (message) => {
|
|
228
|
+
// Do installation here
|
|
229
|
+
return 'Installed via npm';
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
```
|
|
234
|
+
|
|
75
235
|
To view a more detailed example, check out [Buddy](../../buddy/).
|
|
76
236
|
|
|
77
237
|
_You may also use any of the following CLI utilities:_
|
|
@@ -156,6 +316,7 @@ For casual chit-chat with others using this package:
|
|
|
156
316
|
Many thanks to the following core technologies & people who have contributed to this package:
|
|
157
317
|
|
|
158
318
|
- [CAC](https://github.com/cacjs/cac)
|
|
319
|
+
- [Clack](https://github.com/bombshell-dev/clack)
|
|
159
320
|
- [Ora](https://github.com/sindresorhus/ora)
|
|
160
321
|
- [Consola](https://github.com/unjs/consola)
|
|
161
322
|
- [Chris Breuer](https://github.com/chrisbbreuer)
|