use std::path::PathBuf;
use binoc_sdk::Changeset;
use schemars::schema_for;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_path = std::env::args()
.nth(1)
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("docs/users/reference/changeset-schema.json"));
let schema = schema_for!(Changeset);
let mut json = serde_json::to_string_pretty(&schema)?;
json.push('\n');
if let Some(parent) = out_path.parent() {
std::fs::create_dir_all(parent)?;
}
let unchanged = std::fs::read_to_string(&out_path)
.map(|existing| existing == json)
.unwrap_or(false);
if unchanged {
eprintln!("{} is up to date.", out_path.display());
} else {
std::fs::write(&out_path, json)?;
eprintln!("Wrote {}", out_path.display());
}
Ok(())
}