1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::errors::*;
use crate::parse::SnoopServeOpts;
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
fn run_cmd_directly(cmd: String, dir: &Path) -> Result<i32, ExecutionError> {
#[cfg(unix)]
let shell_exec = "sh";
#[cfg(windows)]
let shell_exec = "powershell";
#[cfg(unix)]
let shell_param = "-c";
#[cfg(windows)]
let shell_param = "-command";
let output = Command::new(shell_exec)
.args([shell_param, &cmd])
.current_dir(dir)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.map_err(|err| ExecutionError::CmdExecFailed { cmd, source: err })?;
let exit_code = match output.status.code() {
Some(exit_code) => exit_code,
None if output.status.success() => 0,
None => 1,
};
Ok(exit_code)
}
pub fn snoop_build(dir: PathBuf) -> Result<i32, ExecutionError> {
let target = dir.join(".perseus/builder");
run_cmd_directly(
format!(
"{} run",
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string())
),
&target,
)
}
pub fn snoop_wasm_build(dir: PathBuf) -> Result<i32, ExecutionError> {
let target = dir.join(".perseus");
run_cmd_directly(
format!(
"{} build --target web",
env::var("PERSEUS_WASM_PACK_PATH").unwrap_or_else(|_| "wasm-pack".to_string())
),
&target,
)
}
pub fn snoop_server(dir: PathBuf, opts: SnoopServeOpts) -> Result<i32, ExecutionError> {
let target = dir.join(".perseus/server");
run_cmd_directly(
format!(
"{} run {}",
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
format!(
"--features integration-{} --no-default-features",
opts.integration.to_string()
)
),
&target,
)
}