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
78
79
80
81
use crate::cmd::run_cmd_directly;
use crate::install::Tools;
use crate::parse::{Opts, SnoopServeOpts};
use crate::{errors::*, get_user_crate_name};
use std::path::PathBuf;
pub fn snoop_build(dir: PathBuf, tools: &Tools, global_opts: &Opts) -> Result<i32, ExecutionError> {
run_cmd_directly(
format!(
"{} run {}",
tools.cargo_engine, global_opts.cargo_engine_args
),
&dir,
vec![
("PERSEUS_ENGINE_OPERATION", "build"),
("CARGO_TARGET_DIR", "dist/target_engine"),
],
)
}
pub fn snoop_wasm_build(
dir: PathBuf,
tools: &Tools,
global_opts: &Opts,
) -> Result<i32, ExecutionError> {
let crate_name = get_user_crate_name(&dir)?;
println!("[NOTE]: You should expect unused code warnings here! Don't worry about them, they're just a product of the target-gating.");
let exit_code = run_cmd_directly(
format!(
"{} build --target wasm32-unknown-unknown {}",
tools.cargo_browser, global_opts.cargo_browser_args
),
&dir,
vec![("CARGO_TARGET_DIR", "dist/target_wasm")],
)?;
if exit_code != 0 {
return Ok(exit_code);
}
run_cmd_directly(
format!(
"{cmd} ./dist/target_wasm/wasm32-unknown-unknown/debug/{crate_name}.wasm --out-dir dist/pkg --out-name perseus_engine --target web {args}",
cmd=tools.wasm_bindgen,
args=global_opts.wasm_bindgen_args,
crate_name=crate_name
),
&dir,
vec![("CARGO_TARGET_DIR", "dist/target_wasm")],
)
}
pub fn snoop_server(
dir: PathBuf,
opts: &SnoopServeOpts,
tools: &Tools,
global_opts: &Opts,
) -> Result<i32, ExecutionError> {
run_cmd_directly(
format!(
"{} run {}",
tools.cargo_engine, global_opts.cargo_engine_args
),
&dir,
vec![
("PERSEUS_ENGINE_OPERATION", "serve"),
("CARGO_TARGET_DIR", "dist/target_engine"),
("PERSEUS_HOST", &opts.host),
("PERSEUS_PORT", &opts.port.to_string()),
], )
}