output_helpers.ts

view source

Declarations
#

7 declarations

format_and_output
#

output_helpers.ts view source

<T>(data: T, formatters: OutputFormatters<T>, options: OutputOptions): Promise<void> import {format_and_output} from '@fuzdev/fuz_repos/output_helpers.js';

Formats data and outputs to file or stdout based on options.

Supports three formats:

  • stdout: Uses logger for colored/styled output (cannot use with --outfile)
  • json: Stringified JSON
  • markdown: Formatted markdown text

data

type T

formatters

options

returns

Promise<void>

generics

format_and_output<T>
T

throws

  • Error - if stdout format used with `outfile`, or if logger missing for stdout

output_is_machine
#

output_helpers.ts view source

(format: string, outfile: string | undefined): boolean import {output_is_machine} from '@fuzdev/fuz_repos/output_helpers.js';

Whether a task's stdout carries a machine-readable document: a json or markdown report not sent to --outfile.

format

the task's --format

type string

outfile

the task's --outfile, if any

type string | undefined

returns

boolean

OutputFormat
#

output_helpers.ts view source

OutputFormat

type "stdout" | "json" | "markdown"

import type {OutputFormat} from '@fuzdev/fuz_repos/output_helpers.js';

OutputFormatters
#

output_helpers.ts view source

OutputFormatters<T> import type {OutputFormatters} from '@fuzdev/fuz_repos/output_helpers.js';

generics

OutputFormatters<T>
T

json

type (data: T): string

data

type T
returns string

markdown

type (data: T): string[]

data

type T
returns string[]

stdout

This function should call log methods directly for colored/styled output.

type (data: T, log: Logger): void

data

type T

log

type Logger
returns void

OutputOptions
#

output_helpers.ts view source

OutputOptions import type {OutputOptions} from '@fuzdev/fuz_repos/output_helpers.js';

format

type OutputFormat

outfile?

type string

log?

type Logger

write_stdout?

Where a json or markdown document goes without outfile; the one route_human_output returns, so the document reaches stdout while the logger's lines go to stderr.

type (content: string): void

default `console.log`

content

type string
returns void

route_human_output
#

output_helpers.ts view source

(log: Logger, machine: boolean): WriteStdout import {route_human_output} from '@fuzdev/fuz_repos/output_helpers.js';

Keeps a task's stdout for its machine-readable document or stream when machine is set: the logger's info and debug lines, which it writes with console.log, go where its errors go — stderr — and child loggers inherit that. Gro hands a task the logger its own lines go through, so gro's lines after the task runs (✓, the timings) follow to stderr; the two it prints before the task runs (invoking, → <task>) stay on stdout, out of the task's reach.

log

the task's logger

type Logger

machine

whether stdout carries a machine-readable document or stream

type boolean

returns

WriteStdout

writes to the stdout the logger wrote to before, for the document

mutates

  • log — overrides its `console` when `machine` is set

WriteStdout
#

output_helpers.ts view source

WriteStdout import type {WriteStdout} from '@fuzdev/fuz_repos/output_helpers.js';

Writes one machine-readable document, or one line of a stream, to stdout, ending it with a newline.

(call)

type (content: string): void

content

type string
returns void

Imported by
#