#!/usr/bin/env node// tsus CLI: `tsus check [dir]` and `tsus build [dir]`, both with --json.// Diagnostics are machine-first: stable codes, JSON mode, human text is a// rendering of the same data.import path from "node:path";import process from "node:process";import { checkProject, buildProject } from "../src/build.js";const usage = () => { console.error("usage: tsus <check|build> [dir] [--json]"); process.exit(2);};const args = process.argv.slice(2);const command = args[0];const json = args.includes("--json");const dirArg = args.slice(1).find((a) => !a.startsWith("--")) ?? ".";const rootDir = path.resolve(dirArg);const renderHuman = (diagnostics) => { for (const d of diagnostics) { console.error(`error ${d.code}: ${d.message}`); console.error(` --> ${d.file}:${d.line}:${d.col}`); console.error(` hint: ${d.hint}`); } console.error(`${diagnostics.length} error(s)`);};const report = (result, extra) => { const ok = result.diagnostics.length === 0; if (json) { console.log(JSON.stringify({ ok, diagnostics: result.diagnostics, ...extra }, null, 2)); } else if (ok) { console.log(extra?.emitted ? `built ${extra.emitted.length} file(s)` : "check passed"); } else { renderHuman(result.diagnostics); } process.exit(ok ? 0 : 1);};if (command === "check") { report(checkProject(rootDir));} else if (command === "build") { const result = buildProject(rootDir); report(result, { emitted: result.emitted.map((f) => path.relative(rootDir, f)) });} else { usage();}