31 lines
1.2 KiB
Rust
31 lines
1.2 KiB
Rust
//! CLI binary that regenerates `.huskies/source-map.json` from scratch.
|
|
//!
|
|
//! Usage: `source-map-regen [--project-root <path>]`
|
|
//!
|
|
//! Scans every tracked Rust and TypeScript file in the project via `git ls-files`,
|
|
//! extracts public item signatures, and writes a fresh sorted JSON map. The output
|
|
//! is byte-identical across runs on the same source tree (deterministic).
|
|
//!
|
|
//! Intended to be called from the pre-commit quality gate (`script/check`) so that
|
|
//! every commit captures an accurate, stale-entry-free snapshot of the source map.
|
|
|
|
use source_map_gen::regenerate_source_map;
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
let root = parse_arg(&args, "--project-root").unwrap_or_else(|| ".".to_string());
|
|
let root_path = Path::new(&root);
|
|
let map_path = root_path.join(".huskies").join("source-map.json");
|
|
|
|
if let Err(e) = regenerate_source_map(root_path, &map_path) {
|
|
eprintln!("source-map-regen: {e}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
|
|
/// Parse a flag value from an argument list (e.g. `--flag value`).
|
|
fn parse_arg(args: &[String], flag: &str) -> Option<String> {
|
|
args.windows(2).find(|w| w[0] == flag).map(|w| w[1].clone())
|
|
}
|