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 fileTake it
scripts.md
📜 Scripts
Script files
Scripts are Node.js files executing a series of commands. While those used to be written with a shell language like Bash, libraries like Execa provide with a better, modern experience.
Scripts use $ instead of execa. The only difference is that $ includes script-friendly default options: stdin: 'inherit' and preferLocal: true.
More info about the difference between Execa, Bash and zx.
import {$} from 'execa';
const {stdout: name} = await $`cat package.json`
.pipe`grep name`;
console.log(name);
const branch = await $`git branch --show-current`;
await $`dep deploy --branch=${branch}`;
await Promise.all([
$`sleep 1`,
$`sleep 2`,
$`sleep 3`,
]);
const directoryName = 'foo bar';
await $`mkdir /tmp/${directoryName}`;
Template string syntax
Just like execa, $ can use either the template string syntax or the array syntax.
Conversely, 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.
import {execa, $} from 'execa';
const branch = await execa`git branch --show-current`;
await $('dep', ['deploy', `--branch=${branch}`]);
Next: 🐢 Node.js files
Previous: 💻 Shell
Top: Table of contents