scripts.md
This file
Path
docs/scripts.md
54 lines · 1.9 KiB · Markdown
Last changed by
Add user guides (#989)ehmickybefore adoptionbe91ecf
History of this fileTake it
The walk stopped after 200 commits: lines older than e8f6bbd 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>Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 6why, one step back6Add user guides (#989)ehmickybefore adoptionbe91ecf
line 7why, one step back7# 📜 ScriptsAllow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 8why, one step back8Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 9–16why, 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.1213Scripts use [`$`](../readme.md#file-arguments-options) instead of [`execa`](../readme.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).1415[More info about the difference between Execa, Bash and zx.](bash.md)16Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 17–20why, one step back17```js18import {$} from 'execa';1920const {stdout: name} = await $`cat package.json``.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
line 21why, one step back21 .pipe`grep name`;Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 22–27why, one step back22console.log(name);2324const branch = await $`git branch --show-current`;25await $`dep deploy --branch=${branch}`;2627await Promise.all([Fix indentationSindre Sorhusbefore adoptionf3cb72b
lines 28–30why, one step back28 $`sleep 1`,29 $`sleep 2`,30 $`sleep 3`,Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 31–32why, one step back31]);32Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 33–34why, one step back33const directoryName = 'foo bar';34await $`mkdir /tmp/${directoryName}`;Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 35–36why, one step back35```36Allow template strings with all methods (#933)ehmickybefore adoption8074d85
lines 37–38why, one step back37## Template string syntax38Add user guides (#989)ehmickybefore adoptionbe91ecf
line 39why, one step back39Just like [`execa`](../readme.md#execafile-arguments-options), [`$`](../readme.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 40why, one step back40Add user guides (#989)ehmickybefore adoptionbe91ecf
line 41why, one step back41Conversely, 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 42–49why, one step back4243```js44import {execa, $} from 'execa';4546const branch = await execa`git branch --show-current`;47await $('dep', ['deploy', `--branch=${branch}`]);48```49Add user guides (#989)ehmickybefore adoptionbe91ecf
line 50why, one step back50<hr>Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 51why, one step back51Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 52–54why, one step back52[**Next**: 🐢 Node.js files](node.md)\53[**Previous**: 💻 Shell](shell.md)\54[**Top**: Table of contents](../readme.md#documentation)