serveChecks

tcmts.cli.checkers.serveChecks · #tbdorhzo · term · runs on the server

uses node:readline

A checker process (tcm internal-check, not a command anyone types): a CheckRequest per line on stdin, and for each, in turn, a line on stdout: \0check and its CheckResult (or {"error": …}) as JSON.

import { runCheck } from "#codebase/tcmts/cli/checkers";
import type { CheckRequest } from "#codebase/tcmts/cli/checkers";
import readline from "node:readline";

export async function serveChecks(): Promise<void> {
  for await (const line of readline.createInterface({
    input: process.stdin,
    crlfDelay: Infinity,
  })) {
    if (!line.trim()) continue;
    let out: string;
    try {
      out = JSON.stringify(runCheck(JSON.parse(line) as CheckRequest));
    } catch (e) {
      out = JSON.stringify({ error: (e as Error).message });
    }
    process.stdout.write(`\0check ${out}\n`);
  }
}

uses

used by