Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 1.88 KB

scripts.md

File metadata and controls

53 lines (36 loc) · 1.88 KB
execa logo

📜 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