From 8a233201b813e2724f7f7e078238348916a8751d Mon Sep 17 00:00:00 2001 From: Ammar Abou Zor Date: Tue, 20 Aug 2024 14:56:19 +0200 Subject: [PATCH] Build CLI: Release Command (in progress)... * Fixes on Window: Electron app path has a special case on windows and can't be retrieved without the shell with its shell name. * Remove todo since `tar` exists on windows by default as well and it would better to not include it in the tool itself if possible. --- cli/src/release/bundle.rs | 21 ++++++++++++++------- cli/src/release/compress.rs | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cli/src/release/bundle.rs b/cli/src/release/bundle.rs index 89c827e27..83595493d 100644 --- a/cli/src/release/bundle.rs +++ b/cli/src/release/bundle.rs @@ -28,7 +28,7 @@ pub async fn bundle_release() -> anyhow::Result<()> { // Run build bundle command println!("{}", style("Start Build Bundle command...").blue().bright()); - let build_cmd = build_cmd(); + let build_cmd = build_cmd().context("Error while retrieving command to bundle release")?; let pwd = Target::App.cwd(); let status = tokio::process::Command::new(build_cmd.cmd) .args(build_cmd.args) @@ -89,13 +89,13 @@ unsafe fn set_env_vars() { } } -fn build_cmd() -> ProcessCommand { +fn build_cmd() -> anyhow::Result { // `cfg!` macro is used instead of `cfg` attribute to keep linting and build checks // activated on all method independent from development environment. if cfg!(target_os = "linux") { - build_cmd_linux() + Ok(build_cmd_linux()) } else if cfg!(target_os = "macos") { - build_cmd_mac() + Ok(build_cmd_mac()) } else if cfg!(target_os = "windows") { build_cmd_windows() } else { @@ -175,15 +175,22 @@ fn build_cmd_mac() -> ProcessCommand { } } -fn build_cmd_windows() -> ProcessCommand { - let cmd = electron_builder_cmd(); +fn build_cmd_windows() -> anyhow::Result { + let mut path = Target::App.cwd().join("node_modules").join(".bin"); + + // The script files can get the extension '*.cmd' on Windows + let electron_build_env_path = which::which_in("electron-builder", Some(&path), &path) + .context("Error while resolving electron bin path on Windows")?; + path = electron_build_env_path; + + let cmd = path.to_string_lossy().into(); let args = vec![ String::from("--win"), String::from("--dir"), String::from("--config=./electron.config.win.json"), ]; - ProcessCommand::new(cmd, args) + Ok(ProcessCommand::new(cmd, args)) } async fn create_snapshot() -> anyhow::Result<()> { diff --git a/cli/src/release/compress.rs b/cli/src/release/compress.rs index b6af69589..c5d456d4a 100644 --- a/cli/src/release/compress.rs +++ b/cli/src/release/compress.rs @@ -23,7 +23,6 @@ pub async fn compress() -> anyhow::Result<()> { // We must call the shell and pass it all the arguments at once because we are using the shell // wild card `*` which can't be running without a shell. - // TODO AAZ: Use the crates `flate2` and `tar` to decompress directly. let mut command = if cfg!(target_os = "windows") { let mut cmd = tokio::process::Command::new("cmd"); cmd.arg("/C");