use std::process::Command;
fn main() {
let sha = std::env::var("CONFER_GIT_SHA")
.ok()
.filter(|s| !s.is_empty())
.unwrap_or_else(|| {
Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "unknown".to_string())
});
println!("cargo:rustc-env=CONFER_GIT_SHA={sha}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-env-changed=CONFER_GIT_SHA");
let out = std::env::var("OUT_DIR").expect("OUT_DIR");
let html = std::fs::read_to_string("ui/dist/index.html").unwrap_or_else(|_| {
"<!doctype html><meta charset=\"utf-8\"><title>confer serve</title>\
<body style=\"font-family:system-ui;max-width:34rem;margin:3rem auto;padding:0 1rem\">\
<h1>confer serve</h1><p>The web dashboard isn't built yet. Run \
<code>npm --prefix ui install && npm --prefix ui run build</code>, then rebuild confer.</p>\
<p>The JSON API (<code>/api/*</code>) and the no-JS view (<code>/classic</code>) work regardless.</p>"
.to_string()
});
std::fs::write(std::path::Path::new(&out).join("dashboard.html"), html).expect("write dashboard.html");
println!("cargo:rerun-if-changed=ui/dist/index.html");
}