use std::{env, fs, path::Path};
fn main() {
if env::var_os("CARGO_FEATURE_CONSOLE").is_none() {
return;
}
let out_dir = env::var("OUT_DIR").expect("OUT_DIR set for a build script");
let dest = Path::new(&out_dir).join("console-dist");
let _ = fs::remove_dir_all(&dest);
fs::create_dir_all(&dest).expect("create console-dist");
let manifest = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR");
let src = Path::new(&manifest).join("../boatramp-console/dist");
println!("cargo:rerun-if-changed={}", src.display());
let mut copied = 0usize;
if src.is_dir() {
for entry in fs::read_dir(&src).into_iter().flatten().flatten() {
let path = entry.path();
if path.is_file() {
if let Some(name) = path.file_name() {
fs::copy(&path, dest.join(name)).expect("copy console asset");
copied += 1;
}
}
}
}
if copied == 0 {
fs::write(
dest.join("index.html"),
"<!DOCTYPE html><html><head><title>boatramp console</title></head><body>\
<p>The web console was not built into this binary. Build it with \
<code>just console</code> (a <code>trunk build --release</code> in \
<code>crates/boatramp-console</code>) and rebuild with \
<code>--features console</code>.</p></body></html>",
)
.expect("write placeholder index.html");
if env::var("PROFILE").as_deref() == Ok("release") {
println!(
"cargo:warning=`console` feature is on but crates/boatramp-console/dist is empty; \
embedded a placeholder. Run `just console` to bake the real console assets."
);
}
}
}