sh-thunk
Generate promise returning thunks from shell strings.
This makes it really simple to execute shell scripts from task runners suchs as Gulp and Jake which can take promise returning function as the task implementation.
Here's an example of a gulpfile.js
:
const task parallel = ;const sh = ; const jsfiles = "foo.js" "bar.js"; // Simple commands; // Expand arrays in tagged templates;; // Run commands in parallel with gulp 4; // Multiline scripts;
jakefile.js
is basically the same:
const task = ;const sh = ; ;
Also useful in jest hooks:
// generate 5MB file;
The scripts are executed with sh -eu
and ./node_modules/.bin
is put to PATH
automatically.
Capturing output
There's a sh.capture
variant if you need to capture command output instead
of piping it through.
const stdout stderr both = await shcapture`git rev-parse --abbrev-ref HEAD`;
Where stdout
and stderr
are strings of the corresponding output channels
and both
is string with both outputs interleaved as it would show up in the
terminal.