Skip to content

Commit

Permalink
Build CLI: Release Command (in progress)...
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
AmmarAbouZor committed Aug 20, 2024
1 parent f26750b commit 8a23320
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 14 additions & 7 deletions cli/src/release/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -89,13 +89,13 @@ unsafe fn set_env_vars() {
}
}

fn build_cmd() -> ProcessCommand {
fn build_cmd() -> anyhow::Result<ProcessCommand> {
// `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 {
Expand Down Expand Up @@ -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<ProcessCommand> {
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<()> {
Expand Down
1 change: 0 additions & 1 deletion cli/src/release/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 8a23320

Please sign in to comment.