Think this is better

Changed files
+18 -12
.cargo
+2
.cargo/config.toml
··· 1 + [env] 2 + CARGO_WORKSPACE_DIR = { value = "", relative = true }
+16 -12
build.rs
··· 2 2 const MINIMUM_BUN_VERSION: (u32, u32, u32) = (1, 2, 4); 3 3 4 4 fn main() { 5 - // The build script will be ran from the server directory, so we need to go up one directory to get to the root 6 - let root_path = match std::env::var("CARGO_MANIFEST_DIR") { 7 - Ok(path) => (path + "/..").replace("\\", "/").replace("/server/..", "/"), 8 - Err(_) => panic!("Failed to get root path"), 9 - }; 10 5 // Tell cargo to rerun the build script if the client directory changes 11 - println!("cargo::rerun-if-changed={}client/src/", root_path); 12 - println!("cargo::rerun-if-changed={}client/app.css", root_path); 13 - println!("cargo::rerun-if-changed={}server/src/", root_path); 6 + println!( 7 + "cargo::rerun-if-changed={}client/src/", 8 + env!("CARGO_WORKSPACE_DIR") 9 + ); 10 + println!( 11 + "cargo::rerun-if-changed={}client/app.css", 12 + env!("CARGO_WORKSPACE_DIR") 13 + ); 14 + println!( 15 + "cargo::rerun-if-changed={}server/src/", 16 + env!("CARGO_WORKSPACE_DIR") 17 + ); 14 18 // Check if Bun is installed and is the correct version 15 19 println!("Checking for Bun..."); 16 20 let bun_version = match std::process::Command::new("bun").arg("--version").output() { ··· 58 62 // Install the dependencies: bun install 59 63 println!("Installing Bun dependencies..."); 60 64 let install_result = std::process::Command::new("bun") 61 - .current_dir(root_path.clone() + "/client") 65 + .current_dir(env!("CARGO_WORKSPACE_DIR").to_string() + "/client") 62 66 .args(&["install"]) 63 67 .output() 64 68 .expect("Failed to install Bun dependencies"); ··· 122 126 123 127 println!("Checking Gleam client code..."); 124 128 let lustre_result = std::process::Command::new("gleam") 125 - .current_dir(root_path.clone() + "/client") 129 + .current_dir(env!("CARGO_WORKSPACE_DIR").to_string() + "/client") 126 130 .args(&["check"]) 127 131 .output() 128 132 .expect("Failed to check Gleam code"); ··· 137 141 // Compile the Gleam code: gleam run -m lustre/dev build --minify=true 138 142 println!("Compiling Gleam client code..."); 139 143 let lustre_result = std::process::Command::new("gleam") 140 - .current_dir(root_path.clone() + "/client") 144 + .current_dir(env!("CARGO_WORKSPACE_DIR").to_string() + "/client") 141 145 .args(&[ 142 146 "run", 143 147 "-m", ··· 158 162 // Transpile tailwind styles 159 163 println!("Transpiling Tailwind styles..."); 160 164 let tailwind_result = std::process::Command::new("bun") 161 - .current_dir(root_path.clone() + "/client") 165 + .current_dir(env!("CARGO_WORKSPACE_DIR").to_string() + "/client") 162 166 .args(&[ 163 167 "x", 164 168 "@tailwindcss/cli",