~starkingdoms/starkingdoms

ref: fff9fc74c01a2ceb75dcf23979d942d4b98a5b9b starkingdoms/crates/xtask/src/util.rs -rw-r--r-- 1.6 KiB
fff9fc74 — core chore: continue ci/cd work 16 days ago
                                                                                
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
use std::path::{Path, PathBuf};
use std::process::exit;
use colored::Colorize;

pub fn workspace_dir() -> PathBuf {
    let output = std::process::Command::new(env!("CARGO"))
        .arg("locate-project")
        .arg("--workspace")
        .arg("--message-format=plain")
        .output()
        .unwrap()
        .stdout;
    let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim());
    cargo_path.parent().unwrap().to_path_buf()
}

pub fn cargo(cmd: String) {
    println!("{} cargo {}", "[cargo]".bold().cyan(), cmd);
    let mut output = std::process::Command::new(env!("CARGO"));

    for command in cmd.split(" ") {
        output.arg(command);
    }
    let output = output.spawn().unwrap().wait().unwrap();

    if !output.success() {
        println!("{}", "============ TASK FAILED".bold().red());
        exit(1);
    }
}

pub fn wasmopt(cmd: String) {
    println!("{} wasm-opt {}", "[wasm-opt]".bold().cyan(), cmd);
    let mut output = std::process::Command::new("wasm-opt");

    for command in cmd.split(" ") {
        output.arg(command);
    }
    let output = output.spawn().unwrap().wait().unwrap();

    if !output.success() {
        println!("{}", "============ TASK FAILED".bold().red());
        exit(1);
    }
}

pub fn wbg(cmd: String) {
    println!("{} wasm-bindgen {}", "[wasm-bindgen]".bold().cyan(), cmd);
    let mut output = std::process::Command::new("wasm-bindgen");

    for command in cmd.split(" ") {
        output.arg(command);
    }
    let output = output.spawn().unwrap().wait().unwrap();

    if !output.success() {
        println!("{}", "============ TASK FAILED".bold().red());
        exit(1);
    }
}