Skip to content
Myr

scripts.md

This file

Path

docs/scripts.md

54 lines · 1.9 KiB · Markdown

Last changed by

Move API reference to its own page (#996)ehmickybefore adoption7cde496

History of this file

Take it

The walk stopped after 200 commits: lines older than 67b476b point at it.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 1–5why, one step back
1<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 `error.message` (#705)ehmickybefore adoption67b476b

line 6why, one step back
6

Add user guides (#989)ehmickybefore adoptionbe91ecf

line 7why, one step back
7# 📜 Scripts

Improve `error.message` (#705)ehmickybefore adoption67b476b

line 8why, one step back
8

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 9–12why, one step back
9## Script files
1011[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.12

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 13why, one step back
13Scripts 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 back
14
15[More info about the difference between Execa, Bash and zx.](bash.md)16

Improve `error.message` (#705)ehmickybefore adoption67b476b

lines 17–20why, one step back
17```js
18import {$} from 'execa';1920const {stdout: name} = await $`cat package.json`

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

line 21why, one step back
21 .pipe`grep name`;

Improve `error.message` (#705)ehmickybefore adoption67b476b

lines 22–27why, one step back
22console.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 back
28 $`sleep 1`,
29 $`sleep 2`,30 $`sleep 3`,

Improve `error.message` (#705)ehmickybefore adoption67b476b

lines 31–32why, one step back
31]);
32

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 33–34why, one step back
33const directoryName = 'foo bar';
34await $`mkdir /tmp/${directoryName}`;

Improve `error.message` (#705)ehmickybefore adoption67b476b

lines 35–36why, one step back
35```
36

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 37–38why, one step back
37## Template string syntax
38

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 39why, one step back
39Just 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 40why, one step back
40

Add user guides (#989)ehmickybefore adoptionbe91ecf

line 41why, one step back
41Conversely, 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 back
42
43```js44import {execa, $} from 'execa';4546const branch = await execa`git branch --show-current`;47await $('dep', ['deploy', `--branch=${branch}`]);48```49

Add user guides (#989)ehmickybefore adoptionbe91ecf

line 50why, one step back
50<hr>

Improve `error.message` (#705)ehmickybefore adoption67b476b

line 51why, one step back
51

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 52–54why, one step back
52[**Next**: 🐢 Node.js files](node.md)\
53[**Previous**: 💻 Shell](shell.md)\54[**Top**: Table of contents](../readme.md#documentation)