termprompt

Tasks

Multi-step task runner with individual status indicators.

Preview

Running

tasks
Install dependencies
Compile TypeScript
Run tests

Completed

tasks
Install dependencies
Compile TypeScript
Run tests

Usage

import { tasks } from 'termprompt';

const result = await tasks([
  {
    title: 'Install dependencies',
    task: async () => {
      await installDeps();
    },
  },
  {
    title: 'Compile TypeScript',
    task: async () => {
      await compile();
    },
  },
  {
    title: 'Run tests',
    task: async () => {
      await runTests();
    },
  },
]);

if (result.errors.length > 0) {
  console.error('Some tasks failed.');
}

API

tasks(items, config?)

Returns Promise<TasksResult>.

TaskItem

FieldTypeDescription
titlestringTask display text
task(ctx, update) => Promise<void>Async function to execute
enabledboolean | ((ctx) => boolean)Skip task if false

The task function receives a shared context object and an update callback to change the title mid-execution.

TasksConfig

ConfigTypeDefaultDescription
concurrentbooleanfalseRun tasks in parallel
outputWritableprocess.stdoutOutput stream

TasksResult

FieldTypeDescription
errorsError[]Errors from any failed tasks

Concurrent Execution

await tasks(
  [
    { title: 'Lint', task: async () => await lint() },
    { title: 'Test', task: async () => await test() },
    { title: 'Build', task: async () => await build() },
  ],
  { concurrent: true },
);

All tasks start at the same time. The display updates as each completes independently.

Conditional Tasks

await tasks([
  {
    title: 'Run migrations',
    task: async () => await migrate(),
    enabled: process.env.NODE_ENV === 'production',
  },
]);

Disabled tasks show as skipped with a strikethrough title.

skipped task
Install dependencies
Run migrations
Start server

Updating Task Title

await tasks([
  {
    title: 'Downloading',
    task: async (ctx, update) => {
      update('Downloading... 50%');
      await download();
      update('Downloading... 100%');
    },
  },
]);

Task Statuses

StatusIconDescription
pending dimNot started
running animatedCurrently active
success greenCompleted
error redFailed
skipped dimDisabled/skipped

On this page