# @ms-cloudpack/task-reporter

A library for standardizing how tasks are logged to the console.

## Example usage

1. Create a reporter:

```ts
const taskReporter = new TaskReporter({
  productName: `Foobar`,
  version: `1.2.3`,
  description: `running tasks with ${bold(`15`)} workers`,
  showStarted: false,
  showPending: true,
  showCompleted: true,
  showSummary: true,
  showTaskDetails: true,
});
```

2. Add tasks with the reporter `addTask` method:

```ts
const task = taskReporter.addTask(`build something`, /* initially idle */ true);

// When you are starting the task, you can call start:
try {
  task.start();
} finally {
  task.complete({ status: 'complete' /* etc */ });
}
```

3. You can use various formatting helpers to spice up the colorization and formatting of your logging:

```ts
// Fail example, with provide details:
import { bulletedList } from '@ms-cloudpack/task-reporter';

task.complete({
  status: 'fail',
  message: 'Reason',
  details: bulletedList(['Name: value', 'Errors:', ['sub-bullet things', 'etc'], 'Warnings', ['warn1', etc]]),
});
```

A variety of helper functions are available for formatting.

```ts
import { cyan, bold, red } from '@ms-cloudpack/task-reporter';

task.complete('fail', { message: cyan(bold(`I am an ${red(`error`)}`)) });
```

4. When all your tasks are completed, or if you encountered an exit-early scenario, call `reporter.complete('reason')` to end task logging. Any pending tasks will be marked as skipped, and running tasks will be marked as aborted.

```ts
process.on('SIGINT', () => {
  reporter.complete('User hit Ctrl-C');
  void reporter.dispose();
});

await doStuff();
reporter.complete(reason);
await reporter.dispose();
```
