Skip to content

🐡 Sequential and parallel task list runner for terminal

License

Notifications You must be signed in to change notification settings

shreyansh-zazz/taskz

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Taskz

Simple sequential and parallel task list runner for terminal.

render1563366532786

Install

npm i taskz

Getting started

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();

Usage

Create tasks

// Create tasks
const myTasks = taskz([
  { text: "task 1", task: () => { /* ... */ } },
  { text: "task 2", task: () => { /* ... */ } }
]);

// Run it
myTasks.run()

Subtasks

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: () => { /* ... */ } }
    ]) 
  }
]);

Concurrent tasks (parallelism)

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

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 () => {} }
]);

Advanced Usage

Use context

const myTasks = taskz([
  { 
    text: "task 1", 
    task: ctx => { ctx.val = "foo" } 
  },
  { 
    text: "task 2", 
    task: ctx => { doSomethingWith(ctx.val) } 
  }
]);

Change text within a task during execution

const myTasks = taskz([
  {
    text: "my subtask 2",
    task: async ctx => {
      ctx.text("my subtask 2 foo");
      await new Promise(resolve => setTimeout(resolve, 200));
      ctx.text("my subtask 2 bar");
    }
  }
]);

Related

  • spinnies - Elegant terminal multiple spinners manager
  • cli-spinners - Spinners for use in the terminal
  • listr - Terminal task list (unmaintained)

License

MIT © rap2h

About

🐡 Sequential and parallel task list runner for terminal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%