Skip to content

Commit

Permalink
feat(cli): run beforeDev and beforeBuild in a shell, closes #1295 (#1399
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lucasfernog authored Mar 28, 2021
1 parent fd5bb2c commit 32eb0d5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changes/command-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-cli": patch
---

Run `beforeDevCommand` and `beforeBuildCommand` in a shell.
11 changes: 0 additions & 11 deletions cli/core/Cargo.lock
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions cli/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
serde_with = "1.6"

[target."cfg(target_os = \"windows\")".dependencies]
which = "4.0"

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.3"
30 changes: 13 additions & 17 deletions cli/core/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,22 @@ impl Build {
}

if let Some(before_build) = &config_.build.before_build_command {
let mut cmd: Option<&str> = None;
let mut args: Vec<&str> = vec![];
for token in before_build.split(' ') {
if cmd.is_none() && !token.is_empty() {
cmd = Some(token);
} else {
args.push(token)
}
}

if let Some(cmd) = cmd {
if !before_build.is_empty() {
logger.log(format!("Running `{}`", before_build));
#[cfg(target_os = "windows")]
let mut command = Command::new(
which::which(&cmd).expect(&format!("failed to find `{}` in your $PATH", cmd)),
);
execute_with_output(
&mut Command::new("cmd")
.arg("/C")
.arg(before_build)
.current_dir(app_dir()),
)?;
#[cfg(not(target_os = "windows"))]
let mut command = Command::new(cmd);
command.args(args).current_dir(app_dir());
execute_with_output(&mut command)?;
execute_with_output(
&mut Command::new("sh")
.arg("-c")
.arg(before_build)
.current_dir(app_dir()),
)?;
}
}

Expand Down
27 changes: 11 additions & 16 deletions cli/core/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,20 @@ impl Dev {
.build
.before_dev_command
{
let mut cmd: Option<&str> = None;
let mut args: Vec<&str> = vec![];
for token in before_dev.split(' ') {
if cmd.is_none() && !token.is_empty() {
cmd = Some(token);
} else {
args.push(token)
}
}

if let Some(cmd) = cmd {
if !before_dev.is_empty() {
logger.log(format!("Running `{}`", before_dev));
#[cfg(target_os = "windows")]
let mut command = Command::new(
which::which(&cmd).expect(&format!("failed to find `{}` in your $PATH", cmd)),
);
let child = Command::new("cmd")
.arg("/C")
.arg(before_dev)
.current_dir(app_dir())
.spawn()?;
#[cfg(not(target_os = "windows"))]
let mut command = Command::new(cmd);
let child = command.args(args).current_dir(app_dir()).spawn()?;
let child = Command::new("sh")
.arg("-c")
.arg(before_dev)
.current_dir(app_dir())
.spawn()?;
BEFORE_DEV.set(Mutex::new(child)).unwrap();
}
}
Expand Down

0 comments on commit 32eb0d5

Please sign in to comment.