use std::{path::Path, process::Command};

fn main() {
    println!("cargo:rerun-if-changed=migrations");
    println!("cargo:rerun-if-changed=reminder-dashboard");

    Command::new("npm")
        .arg("run")
        .arg("build")
        .current_dir(Path::new("reminder-dashboard"))
        .env("VITE_VERSION", env!("CARGO_PKG_VERSION"))
        .spawn()
        .expect("Failed to build NPM")
        .wait()
        .expect("Failed to wait for NPM build");

    Command::new("cp")
        .arg("reminder-dashboard/dist/index.html")
        .arg("static/index.html")
        .spawn()
        .expect("Failed to copy index.html")
        .wait()
        .expect("Failed to wait for index.html copy");

    Command::new("cp")
        .arg("-r")
        .arg("reminder-dashboard/dist/static/assets")
        .arg("static/")
        .spawn()
        .expect("Failed to copy assets")
        .wait()
        .expect("Failed to wait for assets copy");
}
