feat(cli): run beforeDev and beforeBuild in a shell, closes #1295 (#1399)

This commit is contained in:
Lucas Fernandes Nogueira
2021-03-28 20:25:06 -03:00
committed by GitHub
parent fd5bb2c201
commit 32eb0d562b
5 changed files with 29 additions and 47 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri-cli": patch
---
Run `beforeDevCommand` and `beforeBuildCommand` in a shell.

11
cli/core/Cargo.lock generated Normal file → Executable file
View File

@@ -1963,7 +1963,6 @@ dependencies = [
"toml_edit",
"ureq",
"valico",
"which",
]
[[package]]
@@ -2370,16 +2369,6 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a32b378380f4e9869b22f0b5177c68a5519f03b3454fde0b291455ddbae266c"
[[package]]
name = "which"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe"
dependencies = [
"either",
"libc",
]
[[package]]
name = "wildmatch"
version = "1.1.0"

View File

@@ -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"

View File

@@ -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()),
)?;
}
}

View File

@@ -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();
}
}