scripts.md
This file
Path
docs/scripts.md
53 lines · 1.9 KiB · Markdown
Last changed by
Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
History of this fileTake it
The walk stopped after 200 commits: lines older than 8ff263c point at it.
Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 1–5why, one step back1<picture>2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>Improve process failure logic (#807)ehmickybefore adoption8ff263c
line 6why, one step back6Add user guides (#989)ehmickybefore adoptionbe91ecf
line 7why, one step back7# 📜 ScriptsImprove process failure logic (#807)ehmickybefore adoption8ff263c
line 8why, one step back8Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 9–12why, one step back9## Script files1011[Scripts](https://en.wikipedia.org/wiki/Shell_script) are Node.js files executing a series of commands. While those used to be written with a shell language like [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)), libraries like Execa provide with a better, modern experience.12Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 13why, one step back13Scripts use [`$`](api.md#file-arguments-options) instead of [`execa`](api.md#execafile-arguments-options). The only difference is that `$` includes script-friendly default options: [`stdin: 'inherit'`](input.md#terminal-input) and [`preferLocal: true`](environment.md#local-binaries).Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 14–16why, one step back1415[More info about the difference between Execa, Bash and zx.](bash.md)16Improve process failure logic (#807)ehmickybefore adoption8ff263c
lines 17–19why, one step back17```js18import {$} from 'execa';19Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 20why, one step back20const {stdout: name} = await $`cat package.json`.pipe`grep name`;Improve process failure logic (#807)ehmickybefore adoption8ff263c
lines 21–26why, one step back21console.log(name);2223const branch = await $`git branch --show-current`;24await $`dep deploy --branch=${branch}`;2526await Promise.all([Fix indentationSindre Sorhusbefore adoptionf3cb72b
lines 27–29why, one step back27 $`sleep 1`,28 $`sleep 2`,29 $`sleep 3`,Improve process failure logic (#807)ehmickybefore adoption8ff263c
lines 30–31why, one step back30]);31Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 32–33why, one step back32const directoryName = 'foo bar';33await $`mkdir /tmp/${directoryName}`;Improve process failure logic (#807)ehmickybefore adoption8ff263c
lines 34–35why, one step back34```35Allow template strings with all methods (#933)ehmickybefore adoption8074d85
lines 36–37why, one step back36## Template string syntax37Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 38why, one step back38Just like [`execa`](api.md#execafile-arguments-options), [`$`](api.md#file-arguments-options) can use either the [template string syntax](execution.md#template-string-syntax) or the [array syntax](execution.md#array-syntax).Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 39why, one step back39Add user guides (#989)ehmickybefore adoptionbe91ecf
line 40why, one step back40Conversely, the template string syntax can be used outside of script files: `$` is not required to use that syntax. For example, `execa` [can use it too](execution.md#template-string-syntax).Allow template strings with all methods (#933)ehmickybefore adoption8074d85
lines 41–48why, one step back4142```js43import {execa, $} from 'execa';4445const branch = await execa`git branch --show-current`;46await $('dep', ['deploy', `--branch=${branch}`]);47```48Add user guides (#989)ehmickybefore adoptionbe91ecf
line 49why, one step back49<hr>Improve process failure logic (#807)ehmickybefore adoption8ff263c
line 50why, one step back50Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 51–53why, one step back51[**Next**: 🐢 Node.js files](node.md)\52[**Previous**: 💻 Shell](shell.md)\53[**Top**: Table of contents](../readme.md#documentation)