#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" README_HEADER_PATH="$SCRIPT_DIR/README_HEADER.md" TARGET_README_PATH="$SCRIPT_DIR/README.md" SCRIPT_DIR="$SCRIPT_DIR" \ README_HEADER_PATH="$README_HEADER_PATH" \ TARGET_README_PATH="$TARGET_README_PATH" \ node --input-type=module <<'EOF' import { execFileSync } from "node:child_process"; import { readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; const placeholder = "___DOCS___"; const scriptDir = process.env.SCRIPT_DIR; const headerPath = process.env.README_HEADER_PATH; const targetPath = process.env.TARGET_README_PATH; if (!scriptDir || !headerPath || !targetPath) { throw new Error("missing required README path environment variables"); } const generatorPath = path.join(scriptDir, "docs", "src", "generate.ts"); const docs = execFileSync( "node", ["--experimental-strip-types", generatorPath, "--stdout"], { encoding: "utf8" }, ).trimEnd(); const header = readFileSync(headerPath, "utf8"); if (!header.includes(placeholder)) { throw new Error(`placeholder '${placeholder}' not found in ${headerPath}`); } const combined = header.split(placeholder).join(docs); const output = combined.endsWith("\n") ? combined : `${combined}\n`; writeFileSync(targetPath, output, "utf8"); console.log(`[docs] wrote ${targetPath}`); EOF