gen-doctor-components.ts
28 lines · scripts/gen-doctor-components.ts at 3f79d81
1#!/usr/bin/env -S bun --no-env-file --config=/dev/null
2/**
3 * Generate bin/gstack-doctor-components.sh — the Bash render of the doctor's
4 * component table (lib/doctor-components.ts) and result-code anchors
5 * (lib/result-codes.ts). The doctor must report with Bun absent, so the table
6 * ships as a committed sourced file, refreshed from scripts/gen-skill-docs.ts
7 * and checked for freshness by test/doctor-components.test.ts, the way the
8 * agents digest is.
9 */
10import * as fs from 'fs';
11import * as path from 'path';
12import { renderDoctorComponentsSh } from '../lib/doctor-components';
14const ROOT = path.resolve(import.meta.dir, '..');
15export const DOCTOR_COMPONENTS_RELPATH = 'bin/gstack-doctor-components.sh';
17export function writeDoctorComponentsSh(opts?: { outRoot?: string }): { outPath: string; bytes: number } {
18 const content = renderDoctorComponentsSh();
19 const outPath = path.join(opts?.outRoot ?? ROOT, DOCTOR_COMPONENTS_RELPATH);
20 fs.mkdirSync(path.dirname(outPath), { recursive: true });
21 fs.writeFileSync(outPath, content);
22 return { outPath, bytes: Buffer.byteLength(content, 'utf-8') };
23}
25if (import.meta.main) {
26 const { outPath, bytes } = writeDoctorComponentsSh();
27 console.log(`[gen-doctor-components] ${path.relative(ROOT, outPath)}: ${bytes} bytes`);
28}