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
use crate::cmd::run_stage;
use crate::errors::*;
use console::{style, Emoji};
use std::path::PathBuf;
static GENERATING: Emoji<'_, '_> = Emoji("🔨", "");
static BUILDING: Emoji<'_, '_> = Emoji("🏗️ ", "");
static FINALIZING: Emoji<'_, '_> = Emoji("📦", "");
macro_rules! handle_exit_code {
($code:expr) => {
let (_, _, code) = $code;
if code != 0 {
return Ok(code);
}
};
}
pub fn build_internal(dir: PathBuf, num_steps: u8) -> Result<i32> {
let mut target = dir;
target.extend([".perseus"]);
handle_exit_code!(run_stage(
vec!["cargo run"],
&target,
format!(
"{} {} Generating your app",
style(format!("[1/{}]", num_steps)).bold().dim(),
GENERATING
)
)?);
handle_exit_code!(run_stage(
vec![
"wasm-pack build --target web",
"rm -rf dist/pkg",
"mv pkg/ dist/",
],
&target,
format!(
"{} {} Building your app to WASM",
style(format!("[2/{}]", num_steps)).bold().dim(),
BUILDING
)
)?);
handle_exit_code!(run_stage(
vec!["rollup main.js --format iife --file dist/pkg/bundle.js"],
&target,
format!(
"{} {} Finalizing bundle",
style(format!("[3/{}]", num_steps)).bold().dim(),
FINALIZING
)
)?);
Ok(0)
}
pub fn build(dir: PathBuf, prog_args: &[String]) -> Result<i32> {
let should_watch = prog_args.get(1);
let dflt_watch_path = ".".to_string();
let _watch_path = prog_args.get(2).unwrap_or(&dflt_watch_path);
if should_watch == Some(&"-w".to_string()) || should_watch == Some(&"--watch".to_string()) {
todo!("watching not yet supported, try a tool like 'entr'");
}
let exit_code = build_internal(dir.clone(), 3)?;
Ok(exit_code)
}