Skip to content

Commit 73bf72f

Browse files
authoredApr 15, 2022
Beautify README.md
1 parent eceff79 commit 73bf72f

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed
 

‎README.md

+49-43
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ npm i -g zx
3333

3434
**Requirement**: Node version >= 16.0.0
3535

36+
## Goods
37+
38+
[$](#command-) · [cd()](#cd) · [fetch()](#fetch) · [question()](#question) · [sleep()](#sleep) · [nothrow()](#nothrow) · [quiet()](#quiet) ·
39+
[chalk](#chalk-package) · [yaml](#yaml-package) · [fs](#fs-package) · [globby](#globby-package) · [os](#os-package) · [path](#path-package) · [minimist](#minimist-package) · [which](#which-package) ·
40+
[__filename](#__filename--__dirname) · [__dirname](#__filename--__dirname)
41+
3642
## Documentation
3743

3844
Write your scripts in a file with `.mjs` extension in order to
@@ -103,7 +109,7 @@ try {
103109
}
104110
```
105111

106-
#### `ProcessPromise`
112+
### `ProcessPromise`
107113

108114
```ts
109115
class ProcessPromise<T> extends Promise<T> {
@@ -124,7 +130,7 @@ await $`cat file.txt`.pipe(process.stdout)
124130

125131
Read more about [pipelines](docs/pipelines.md).
126132

127-
#### `ProcessOutput`
133+
### `ProcessOutput`
128134

129135
```ts
130136
class ProcessOutput {
@@ -136,9 +142,9 @@ class ProcessOutput {
136142
}
137143
```
138144

139-
### Functions
145+
## Functions
140146

141-
#### `cd()`
147+
### `cd()`
142148

143149
Changes the current working directory.
144150

@@ -147,7 +153,7 @@ cd('/tmp')
147153
await $`pwd` // outputs /tmp
148154
```
149155

150-
#### `fetch()`
156+
### `fetch()`
151157

152158
A wrapper around the [node-fetch](https://www.npmjs.com/package/node-fetch) package.
153159

@@ -158,7 +164,7 @@ if (resp.ok) {
158164
}
159165
```
160166

161-
#### `question()`
167+
### `question()`
162168

163169
A wrapper around the [readline](https://nodejs.org/api/readline.html) package.
164170

@@ -178,15 +184,15 @@ function question(query?: string, options?: QuestionOptions): Promise<string>
178184
type QuestionOptions = { choices: string[] }
179185
```
180186
181-
#### `sleep()`
187+
### `sleep()`
182188
183189
A wrapper around the `setTimeout` function.
184190
185191
```js
186192
await sleep(1000)
187193
```
188194
189-
#### `nothrow()`
195+
### `nothrow()`
190196
191197
Changes behavior of `$` to not throw an exception on non-zero exit codes.
192198
@@ -219,7 +225,7 @@ if ((await nothrow($`[[ -d path ]]`)).exitCode == 0) {
219225
...
220226
}
221227
```
222-
#### `quiet()`
228+
### `quiet()`
223229

224230
Changes behavior of `$` to disable verbose output.
225231

@@ -234,35 +240,35 @@ await quiet($`grep something from-file`)
234240
// Command and output will not be displayed.
235241
```
236242

237-
### Packages
243+
## Packages
238244

239245
Following packages are available without importing inside scripts.
240246

241-
#### `chalk` package
247+
### `chalk` package
242248

243249
The [chalk](https://www.npmjs.com/package/chalk) package.
244250

245251
```js
246252
console.log(chalk.blue('Hello world!'))
247253
```
248254

249-
#### `yaml` package
255+
### `yaml` package
250256

251257
The [yaml](https://www.npmjs.com/package/yaml) package.
252258

253259
```js
254260
console.log(YAML.parse('foo: bar').foo)
255261
```
256262

257-
#### `fs` package
263+
### `fs` package
258264

259265
The [fs-extra](https://www.npmjs.com/package/fs-extra) package.
260266

261267
```js
262268
let content = await fs.readFile('./package.json')
263269
```
264270

265-
#### `globby` package
271+
### `globby` package
266272

267273
The [globby](https://github.com/sindresorhus/globby) package.
268274

@@ -278,29 +284,29 @@ Also, globby available via the `glob` shortcut:
278284
await $`svgo ${await glob('*.svg')}`
279285
```
280286

281-
#### `os` package
287+
### `os` package
282288

283289
The [os](https://nodejs.org/api/os.html) package.
284290

285291
```js
286292
await $`cd ${os.homedir()} && mkdir example`
287293
```
288294

289-
#### `path` package
295+
### `path` package
290296

291297
The [path](https://nodejs.org/api/path.html) package.
292298

293299
```js
294300
await $`mkdir ${path.join(basedir, 'output')}`
295301
```
296302

297-
#### `minimist` package
303+
### `minimist` package
298304

299305
The [minimist](https://www.npmjs.com/package/minimist) package.
300306

301307
Available as global const `argv`.
302308

303-
#### `which`
309+
### `which` package
304310

305311
The [which](https://github.com/npm/node-which) package.
306312

@@ -310,9 +316,9 @@ let node = await which('node')
310316
let node = which.sync('node')
311317
```
312318

313-
### Configuration
319+
## Configuration
314320

315-
#### `$.shell`
321+
### `$.shell`
316322

317323
Specifies what shell is used. Default is `which bash`.
318324

@@ -322,29 +328,29 @@ $.shell = '/usr/bin/bash'
322328

323329
Or use a CLI argument: `--shell=/bin/bash`
324330

325-
#### `$.spawn`
331+
### `$.spawn`
326332

327333
Specifies a `spawn` api. Defaults to `require('child_process').spawn`.
328334

329-
#### `$.maxBuffer`
335+
### `$.maxBuffer`
330336

331337
Specifies the largest number of bytes allowed on stdout or stderr.
332338
Defaults to `200 * 1024 * 1024` (200 MiB).
333339

334-
#### `$.prefix`
340+
### `$.prefix`
335341

336342
Specifies the command that will be prefixed to all commands run.
337343

338344
Default is `set -euo pipefail;`.
339345

340346
Or use a CLI argument: `--prefix='set -e;'`
341347

342-
#### `$.quote`
348+
### `$.quote`
343349

344350
Specifies a function for escaping special characters during
345351
command substitution.
346352

347-
#### `$.verbose`
353+
### `$.verbose`
348354

349355
Specifies verbosity. Default is `true`.
350356

@@ -353,15 +359,15 @@ outputs.
353359

354360
Or use a CLI argument `--quiet` to set `$.verbose = false`.
355361

356-
### Polyfills
362+
## Polyfills
357363

358-
#### `__filename` & `__dirname`
364+
### `__filename` & `__dirname`
359365

360366
In [ESM](https://nodejs.org/api/esm.html) modules, Node.js does not provide
361367
`__filename` and `__dirname` globals. As such globals are really handy in scripts,
362368
`zx` provides these for use in `.mjs` files (when using the `zx` executable).
363369

364-
#### `require()`
370+
### `require()`
365371

366372
In [ESM](https://nodejs.org/api/modules.html#modules_module_createrequire_filename)
367373
modules, the `require()` function is not defined.
@@ -372,13 +378,13 @@ files (when using `zx` executable).
372378
let {version} = require('./package.json')
373379
```
374380
375-
### Experimental
381+
## Experimental
376382
377383
The zx also provides a few experimental functions. Please leave a feedback about
378384
those features in [the discussion](https://github.com/google/zx/discussions/299).
379385
To enable new features via CLI pass `--experimental` flag.
380386
381-
#### `retry()`
387+
### `retry()`
382388
383389
Retries a command a few times. Will return after the first
384390
successful attempt, or will throw after specifies attempts count.
@@ -392,7 +398,7 @@ let {stdout} = await retry(5)`curl localhost`
392398
let {stdout} = await retry(3, 500)`npm whoami`
393399
```
394400
395-
#### `echo()`
401+
### `echo()`
396402
397403
A `console.log()` alternative which can take [ProcessOutput](#processoutput).
398404
@@ -406,7 +412,7 @@ echo`Current branch is ${branch}.`
406412
echo('Current branch is', branch)
407413
```
408414
409-
#### `startSpinner()`
415+
### `startSpinner()`
410416
411417
Starts a simple CLI spinner, and returns `stop()` function.
412418
@@ -418,7 +424,7 @@ await $`long-running command`
418424
stop()
419425
```
420426
421-
#### `withTimeout()`
427+
### `withTimeout()`
422428
423429
Runs and sets a timeout for a cmd.
424430
@@ -428,16 +434,16 @@ import {withTimeout} from 'zx/experimental'
428434
await withTimeout(100, 'SIGTERM')`sleep 9999`
429435
```
430436
431-
### FAQ
437+
## FAQ
432438
433-
#### Passing env variables
439+
### Passing env variables
434440
435441
```js
436442
process.env.FOO = 'bar'
437443
await $`echo $FOO`
438444
```
439445
440-
#### Passing array of values
446+
### Passing array of values
441447
442448
If array of values passed as argument to `$`, items of the array will be escaped
443449
individually and concatenated via space.
@@ -448,7 +454,7 @@ let files = [...]
448454
await $`tar cz ${files}`
449455
```
450456
451-
#### Importing from other scripts
457+
### Importing from other scripts
452458
453459
It is possible to make use of `$` and other functions via explicit imports:
454460
@@ -458,13 +464,13 @@ import {$} from 'zx'
458464
await $`date`
459465
```
460466
461-
#### Scripts without extensions
467+
### Scripts without extensions
462468
463469
If script does not have a file extension (like `.git/hooks/pre-commit`), zx
464470
assumes that it is an [ESM](https://nodejs.org/api/modules.html#modules_module_createrequire_filename)
465471
module.
466472
467-
#### Markdown scripts
473+
### Markdown scripts
468474
469475
The `zx` can execute scripts written in markdown
470476
([docs/markdown.md](docs/markdown.md)):
@@ -473,7 +479,7 @@ The `zx` can execute scripts written in markdown
473479
zx docs/markdown.md
474480
```
475481
476-
#### TypeScript scripts
482+
### TypeScript scripts
477483
478484
```ts
479485
import {$} from 'zx'
@@ -511,7 +517,7 @@ in `tsconfig.json`.
511517
```
512518
513519
514-
#### Executing remote scripts
520+
### Executing remote scripts
515521
516522
If the argument to the `zx` executable starts with `https://`, the file will be
517523
downloaded and executed.
@@ -524,7 +530,7 @@ zx https://medv.io/example-script.mjs
524530
zx https://medv.io/game-of-life.mjs
525531
```
526532

527-
#### Executing scripts from stdin
533+
### Executing scripts from stdin
528534

529535
The `zx` supports executing scripts from stdin.
530536

@@ -534,7 +540,7 @@ await $`pwd`
534540
EOF
535541
```
536542

537-
#### Attaching .bash_profile/.zshrc
543+
### Attaching .bash_profile/.zshrc
538544

539545
By default `child_process` does not include aliases and bash functions.
540546
But you are still able to do it by hand. Just attach necessary directives to `$.prefix`.

0 commit comments

Comments
 (0)
Please sign in to comment.