Simple sequential and parallel task list runner for terminal.
npm i taskz
Create your task sequence then run it.
const taskz = require("taskz");
taskz([
{
text: "first task - sleeps for 200ms",
task: async () => await new Promise(resolve => setTimeout(resolve, 200));
},
{
text: "this task will fail",
task: async () => {
throw new Error("this task failed");
}
}
]).run();
// Create tasks
const myTasks = taskz([
{ text: "task 1", task: () => { /* ... */ } },
{ text: "task 2", task: () => { /* ... */ } }
]);
// Run it
myTasks.run()
Replace task
by tasks
and call taskz
function.
const myTasks = taskz([
{ text: "task 1", task: () => { /* ... */ } },
{
text: "task 2 with subtasks",
tasks: taskz([
{ text: "task 2.1", task: () => { /* ... */ } },
{ text: "task 2.2", task: () => { /* ... */ } }
])
}
]);
Add { parallel: true }
as a second parameter in taskz
.
const myTasks = taskz([
{ text: "task 1", task: () => { /* ... */ } },
{ text: "task 2", task: () => { /* ... */ } }
], { parallel: true });
You can mix parallel and sequencial tasks within the same scenario via subtasks.
Fail and stop with stopOnError
option. Does only work for sequencial tasks.
const myTasks = taskz([
{
text: "this task will fail and stop",
stopOnError: true,
task: async () => {
throw new Error("this task failed and stopped the whole process");
}
},
{ text: "this task will never be displayed", task: async () => {} }
]);
const myTasks = taskz([
{
text: "task 1",
task: ctx => { ctx.val = "foo" }
},
{
text: "task 2",
task: ctx => { doSomethingWith(ctx.val) }
}
]);
const myTasks = taskz([
{
text: "my subtask 2",
task: async (ctx, setText) => {
setText("my subtask 2 foo");
await new Promise(resolve => setTimeout(resolve, 200));
setText(kleur.magenta("my subtask 2 bar");
}
}
]);
- spinnies - Elegant terminal multiple spinners manager
- cli-spinners - Spinners for use in the terminal
- listr - Terminal task list (unmaintained)
MIT © rap2h