Improve documentation (#1003)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 63de206 · Browse files · 4 files·+67 added−64 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+67 added−64 removed
- other:+67 added−64 removed
Provenance
- Commit
c8a6ed7- Tree
2073bd9- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
63de206
4 files changed+67 added−64 removed
modified:docs/bash.md+61 added-58 removed
80 unmodified lines81 ### Global variables82 83 ```js84 // zx85-await $`echo example`;85+await $`npm run build`;86 ```87 88 ```js89 // Execa90 import {$} from 'execa';91 92-await $`echo example`;92+await $`npm run build`;93 ```94 95 [More info.](execution.md)96 97 ### Command execution98 99 ```sh100 # Bash101-echo example101+npm run build102 ```103 104 ```js105 // zx106-await $`echo example`;106+await $`npm run build`;107 ```108 109 ```js110 // Execa111-await $`echo example`;111+await $`npm run build`;112 ```113 114 ### Multiline commands115 103 unmodified lines219 ### Subcommands220 221 ```sh222 # Bash223-echo "$(echo example)"223+echo "$(npm run build)"224 ```225 226 ```js227 // zx228-const example = await $`echo example`;229-await $`echo ${example}`;228+const result = await $`npm run build`;229+await $`echo ${result}`;230 ```231 232 ```js233 // Execa234-const example = await $`echo example`;235-await $`echo ${example}`;234+const result = await $`npm run build`;235+await $`echo ${result}`;236 ```237 238 [More info.](execution.md#subcommands)239 240 ### Serial commands241 242 ```sh243 # Bash244-echo one && echo two244+npm run build && npm run test245 ```246 247 ```js248 // zx249-await $`echo one && echo two`;249+await $`npm run build && npm run test`;250 ```251 252 ```js253 // Execa254-await $`echo one`;255-await $`echo two`;254+await $`npm run build`;255+await $`npm run test`;256 ```257 258 ### Parallel commands259 260 ```sh261 # Bash262-echo one &263-echo two &262+npm run build &263+npm run test &264 ```265 266 ```js267 // zx268-await Promise.all([$`echo one`, $`echo two`]);268+await Promise.all([$`npm run build`, $`npm run test`]);269 ```270 271 ```js272 // Execa273-await Promise.all([$`echo one`, $`echo two`]);273+await Promise.all([$`npm run build`, $`npm run test`]);274 ```275 276 ### Global/shared options277 278 ```sh279 # Bash280 options="timeout 5"281-$options echo one282-$options echo two283-$options echo three281+$options npm run init282+$options npm run build283+$options npm run test284 ```285 286 ```js287 // zx288 const timeout = '5s';289-await $`echo one`.timeout(timeout);290-await $`echo two`.timeout(timeout);291-await $`echo three`.timeout(timeout);289+await $`npm run init`.timeout(timeout);290+await $`npm run build`.timeout(timeout);291+await $`npm run test`.timeout(timeout);292 ```293 294 ```js295 // Execa296 import {$ as $_} from 'execa';297 298 const $ = $_({timeout: 5000});299 300-await $`echo one`;301-await $`echo two`;302-await $`echo three`;300+await $`npm run init`;301+await $`npm run build`;302+await $`npm run test`;303 ```304 305 [More info.](execution.md#globalshared-options)306 307 ### Environment variables308 309 ```sh310 # Bash311-EXAMPLE=1 example_command311+EXAMPLE=1 npm run build312 ```313 314 ```js315 // zx316 $.env.EXAMPLE = '1';317-await $`example_command`;317+await $`npm run build`;318 delete $.env.EXAMPLE;319 ```320 321 ```js322 // Execa323-await $({env: {EXAMPLE: '1'}})`example_command`;323+await $({env: {EXAMPLE: '1'}})`npm run build`;324 ```325 326 [More info.](input.md#environment-variables)327 50 unmodified lines378 ### Silent stderr379 380 ```sh381 # Bash382-echo example 2> /dev/null382+npm run build 2> /dev/null383 ```384 385 ```js386 // zx387-await $`echo example`.stdio('inherit', 'pipe', 'ignore');387+await $`npm run build`.stdio('inherit', 'pipe', 'ignore');388 ```389 390 ```js391 // Execa does not print stdout/stderr by default392-await $`echo example`;392+await $`npm run build`;393 ```394 395 ### Verbose mode396 397 ```sh398 # Bash399 set -v400-echo example400+npm run build401 ```402 403 ```js404 // zx >=8405-await $`echo example`.verbose();405+await $`npm run build`.verbose();406 407 // or:408 $.verbose = true;409 ```410 411 ```js412 // Execa413-await $({verbose: 'full'})`echo example`;413+await $({verbose: 'full'})`npm run build`;414 ```415 416 Or:417 3 unmodified lines421 422 Which prints:423 424 ```425-[19:49:00.360] [0] $ echo example426-example425+[19:49:00.360] [0] $ npm run build426+Building...427+Done.428 [19:49:00.383] [0] √ (done in 23ms)429 ```430 431 [More info.](debugging.md#verbose-mode)22 unmodified lines454 ### Piping stdout and stderr to another command455 456 ```sh457 # Bash457-echo example |& cat458+npm run build |& cat459 ```460 461 ```js462 // zx462-const echo = $`echo example`;463+const subprocess = $`npm run build`;464 const cat = $`cat`;464-echo.pipe(cat)465-echo.stderr.pipe(cat.stdin);466-await Promise.all([echo, cat]);465+subprocess.pipe(cat);466+subprocess.stderr.pipe(cat.stdin);467+await Promise.all([subprocess, cat]);468 ```469 470 ```js471 // Execa471-await $({all: true})`echo example`472+await $({all: true})`npm run build`473 .pipe({from: 'all'})`cat`;474 ```475 476 [More info.](pipe.md#source-file-descriptor)1 unmodified line478 ### Piping stdout to a file479 480 ```sh481 # Bash481-echo example > output.txt482+npm run build > output.txt483 ```484 485 ```js486 // zx487+import {createWriteStream} from 'node:fs';488+486-await $`echo example`.pipe(fs.createWriteStream('output.txt'));489+await $`npm run build`.pipe(createWriteStream('output.txt'));490 ```491 492 ```js493 // Execa491-await $({stdout: {file: 'output.txt'}})`echo example`;494+await $({stdout: {file: 'output.txt'}})`npm run build`;495 ```496 497 [More info.](output.md#file-output)498 499 ### Piping stdin from a file500 501 ```sh502 # Bash500-echo example < input.txt503+cat < input.txt504 ```505 506 ```js507 // zx123 unmodified lines631 ### Exit codes632 633 ```sh634 # Bash632-false635+npm run build636 echo $?637 ```638 639 ```js640 // zx638-const {exitCode} = await $`false`.nothrow();641+const {exitCode} = await $`npm run build`.nothrow();642 echo`${exitCode}`;643 ```644 645 ```js646 // Execa644-const {exitCode} = await $({reject: false})`false`;647+const {exitCode} = await $({reject: false})`npm run build`;648 console.log(exitCode);649 ```650 651 [More info.](errors.md#exit-code)1 unmodified line653 ### Timeouts654 655 ```sh656 # Bash654-timeout 5 echo example657+timeout 5 npm run build658 ```659 660 ```js661 // zx659-await $`echo example`.timeout('5s');662+await $`npm run build`.timeout('5s');663 ```664 665 ```js666 // Execa664-await $({timeout: 5000})`echo example`;667+await $({timeout: 5000})`npm run build`;668 ```669 670 [More info.](termination.md#timeout)671 67 unmodified lines739 ### Background subprocess740 741 ```sh742 # Bash740-echo one &743+npm run build &744 ```745 746 ```js747 // zx does not allow setting the `detached` option748 ```749 750 ```js751 // Execa749-await $({detached: true})`echo one`;752+await $({detached: true})`npm run build`;753 ```754 755 [More info.](environment.md#background-subprocess)756 88 unmodified lines845 ### PID846 847 ```sh848 # Bash846-echo example &849+npm run build &850 echo $!851 ```852 853 ```js1 unmodified line855 ```856 857 ```js858 // Execa856-const {pid} = $`echo example`;859+const {pid} = $`npm run build`;860 ```861 862 [More info.](termination.md#inter-process-termination)863 5 unmodified linesmodified:docs/input.md+2 added-2 removed
73 unmodified lines7475767778787980808182838424 unmodified lines73 unmodified lines
## File input
```jsawait execa({inputFile: './input.txt'})`npm run scaffold`;await execa({inputFile: 'input.txt'})`npm run scaffold`;// Or:await execa({stdin: {file: './input.txt'}})`npm run scaffold`;await execa({stdin: {file: 'input.txt'}})`npm run scaffold`;// Or:await execa({stdin: new URL('file:///path/to/input.txt')})`npm run scaffold`;```
24 unmodified linesmodified:docs/output.md+2 added-2 removed
27 unmodified lines28 29 ## File output30 31 ```js32-await execa({stdout: {file: './output.txt'}})`npm run build`;32+await execa({stdout: {file: 'output.txt'}})`npm run build`;33 // Or:34 await execa({stdout: new URL('file:///path/to/output.txt')})`npm run build`;35 ```36 20 unmodified lines57 58 The following example redirects `stdout` to both the [terminal](#terminal-output) and an `output.txt` [file](#file-output), while also retrieving its value [programmatically](#stdout-and-stderr).59 60 ```js61-const {stdout} = await execa({stdout: ['inherit', {file: './output.txt'}, 'pipe']})`npm run build`;61+const {stdout} = await execa({stdout: ['inherit', {file: 'output.txt'}, 'pipe']})`npm run build`;62 console.log(stdout);63 ```64 65 When combining [`'inherit'`](#terminal-output) with other values, please note that the subprocess will not be an interactive TTY, even if the current process is one.106 unmodified linesmodified:docs/streams.md+2 added-2 removed
13 unmodified lines14 import {createReadStream} from 'node:fs';15 import {once} from 'node:events';16 import {execa} from 'execa';17 18-const readable = createReadStream('./input.txt');18+const readable = createReadStream('input.txt');19 await once(readable, 'open');20 await execa({stdin: readable})`npm run scaffold`;21 ```22 3 unmodified lines26 import {createWriteStream} from 'node:fs';27 import {once} from 'node:events';28 import {execa} from 'execa';29 30-const writable = createWriteStream('./output.txt');30+const writable = createWriteStream('output.txt');31 await once(writable, 'open');32 await execa({stdout: writable})`npm run build`;33 ```34 83 unmodified lines