scripts.md
This file
Path
docs/scripts.md
53 lines · 1.9 KiB · Markdown
Last changed by
Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–37why, 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>67# 📜 Scripts89## 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 [`$`](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).1415[More info about the difference between Execa, Bash and zx.](bash.md)1617```js18import {$} from 'execa';1920const {stdout: name} = await $`cat package.json`.pipe`grep name`;21console.log(name);2223const branch = await $`git branch --show-current`;24await $`dep deploy --branch=${branch}`;2526await Promise.all([27 $`sleep 1`,28 $`sleep 2`,29 $`sleep 3`,30]);3132const directoryName = 'foo bar';33await $`mkdir /tmp/${directoryName}`;34```3536## Template string syntax37Improve documentation of Execa methods (#1115)ehmickybefore adoptionca2e813
line 38why, one step back38Just like [`execa`](api.md#execacommand), [`$`](api.md#command) can use either the [template string syntax](execution.md#template-string-syntax) or the [array syntax](execution.md#array-syntax).100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 39–53why, one step back3940Conversely, 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).4142```js43import {execa, $} from 'execa';4445const branch = await execa`git branch --show-current`;46await $('dep', ['deploy', `--branch=${branch}`]);47```4849<hr>5051[**Next**: 🐢 Node.js files](node.md)\52[**Previous**: 💻 Shell](shell.md)\53[**Top**: Table of contents](../readme.md#documentation)