gitmyhub

shell-task

JavaScript ★ 49 updated 9y ago

Proof-of-concept then-able shell commands in node.

A tiny JavaScript library for chaining shell commands one after another, like a readable script written in code.

JavaScriptNode.jssetup: easycomplexity 2/5

Shell-Task Explanation

Imagine you need to run a series of commands in your terminal—like initializing a git repository, adding files, committing, and pushing. Normally you'd either run each command separately or write a shell script. This library lets you chain those commands together in JavaScript in a way that feels natural and readable, with the ability to pause and run custom code in between.

The way it works is straightforward: you create a new Task with your first shell command, then call .then() to add the next command, and keep chaining. Each command waits for the previous one to finish before starting. You can also pass JavaScript functions to .then() instead of shell commands—useful if you need to do some calculation, log something, or pause for a moment before continuing. When you're done chaining all your steps, you call .run() to actually execute everything in sequence.

A real-world example would be a developer automating a deployment workflow. Instead of manually running git init, waiting for it to finish, then git add ., then git commit, they could write it all out in one readable chain. If something fails partway through, the callback function at the end lets you decide whether to stop, log an error, or skip that step and continue.

One important note from the README: even though it looks and feels like JavaScript Promises (with the .then() syntax), it's actually not a true Promise. It's a simpler custom implementation designed specifically for this use case. This means some of the advanced features you might expect from Promises aren't available, but for straightforward sequential task running, it's lightweight and easy to follow.

Where it fits