Skip to content

Commit

Permalink
feat(install): Check if wasm-bindgen is already installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
data-pup committed Apr 25, 2018
1 parent a906fe6 commit f3f365e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
use console::style;
use emoji;
use failure::Error;
use std::process::Command;
use std::{env, fs, process::Command};
use PBAR;

#[cfg(target_family = "windows")]
static PATH_SEP: &str = ";";

#[cfg(not(target_family = "windows"))]
static PATH_SEP: &str = ":";

pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
if wasm_bindgen_installed() {
return Ok(());
}
let step = format!(
"{} {}Installing WASM-bindgen...",
style("[6/7]").bold().dim(),
Expand Down Expand Up @@ -53,3 +62,16 @@ pub fn wasm_bindgen_build(path: &str, name: &str) -> Result<(), Error> {
Ok(())
}
}

fn wasm_bindgen_installed() -> bool {
if let Ok(path) = env::var("PATH") {
path.split(PATH_SEP)
.map(|p: &str| -> bool {
let prog_str = format!("{}/wasm-bindgen", p);
fs::metadata(prog_str).is_ok()
})
.fold(false, |res, b| res || b)
} else {
false
}
}

0 comments on commit f3f365e

Please sign in to comment.