-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathgen-docs
More file actions
executable file
·44 lines (34 loc) · 1.35 KB
/
gen-docs
File metadata and controls
executable file
·44 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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