#[cfg(target_arch = "wasm32")]
fn main() {}
#[cfg(not(target_arch = "wasm32"))]
use std::path::{Path, PathBuf};
#[cfg(not(target_arch = "wasm32"))]
use std::process::ExitCode;
#[cfg(not(target_arch = "wasm32"))]
use localharness::docs_manifest;
#[cfg(not(target_arch = "wasm32"))]
const MANAGED_DOCS: &[&str] = &["web/skill.md", "web/llms.txt"];
#[cfg(not(target_arch = "wasm32"))]
fn crate_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
#[cfg(not(target_arch = "wasm32"))]
fn main() -> ExitCode {
let check = std::env::args().any(|a| a == "--check");
let root = crate_root();
let mut any_drift = false;
let mut any_error = false;
for rel in MANAGED_DOCS {
let path = root.join(rel);
let doc = match std::fs::read_to_string(&path) {
Ok(s) => s,
Err(e) => {
eprintln!("gen-docs: cannot read {}: {e}", path.display());
any_error = true;
continue;
}
};
let (filled, report) = docs_manifest::fill(&doc);
if check {
if report.drifted() {
any_drift = true;
for key in &report.changed {
println!("DRIFT {rel}: GEN:{key} is stale");
}
} else {
println!("ok {rel} ({} block(s) fresh)", report.fresh.len());
}
} else if report.drifted() {
if let Err(e) = write_doc(&path, &filled) {
eprintln!("gen-docs: cannot write {}: {e}", path.display());
any_error = true;
continue;
}
println!(
"updated {rel}: {}",
report
.changed
.iter()
.map(|k| format!("GEN:{k}"))
.collect::<Vec<_>>()
.join(", ")
);
} else {
println!("ok {rel} ({} block(s) already fresh)", report.fresh.len());
}
}
if any_error {
return ExitCode::FAILURE;
}
if check && any_drift {
eprintln!("\ndoc drift detected — run `cargo run --bin gen-docs` to regenerate.");
return ExitCode::FAILURE;
}
ExitCode::SUCCESS
}
#[cfg(not(target_arch = "wasm32"))]
fn write_doc(path: &Path, content: &str) -> std::io::Result<()> {
std::fs::write(path, content)
}