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
use crate::cmd::run_cmd_directly;
use crate::errors::*;
use crate::parse::{SnoopServeOpts, SnoopWasmOpts};
use std::env;
use std::path::PathBuf;
pub fn snoop_build(dir: PathBuf) -> Result<i32, ExecutionError> {
run_cmd_directly(
format!(
"{} run {}",
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
env::var("PERSEUS_CARGO_ARGS").unwrap_or_else(|_| String::new())
),
&dir,
vec![("PERSEUS_ENGINE_OPERATION", "build")],
)
}
pub fn snoop_wasm_build(dir: PathBuf, opts: SnoopWasmOpts) -> Result<i32, ExecutionError> {
run_cmd_directly(
format!(
"{} build --out-dir dist/pkg --out-name perseus_engine --target web {} {}",
env::var("PERSEUS_WASM_PACK_PATH").unwrap_or_else(|_| "wasm-pack".to_string()),
if opts.profiling {
"--profiling"
} else {
"--dev"
},
env::var("PERSEUS_WASM_PACK_ARGS").unwrap_or_else(|_| String::new())
),
&dir,
vec![],
)
}
pub fn snoop_server(dir: PathBuf, opts: SnoopServeOpts) -> Result<i32, ExecutionError> {
env::set_var("PERSEUS_HOST", opts.host);
env::set_var("PERSEUS_PORT", opts.port.to_string());
run_cmd_directly(
format!(
"{} run {}",
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
env::var("PERSEUS_CARGO_ARGS").unwrap_or_else(|_| String::new())
),
&dir,
vec![("PERSEUS_ENGINE_OPERATION", "serve")],
)
}