Skip to content

Commit

Permalink
Added logic to the bindgen::cargo_install_wasm_bindgen function to ch…
Browse files Browse the repository at this point in the history
…eck if 'wasm-bindgen' already exists in the path.
  • Loading branch information
data-pup committed Apr 13, 2018
1 parent 0f01272 commit b28b3cd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
26 changes: 24 additions & 2 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use PBAR;
use console::style;
use emoji;
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() {
if wasm_bindgen_installed() {
return;
}
let step = format!(
"{} {}Installing WASM-bindgen...",
style("[6/7]").bold().dim(),
Expand Down Expand Up @@ -36,3 +45,16 @@ pub fn wasm_bindgen_build(path: &str, name: &str) {
.unwrap_or_else(|e| panic!("{} failed to execute process: {}", emoji::ERROR, e));
pb.finish();
}

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
}
}
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use PBAR;
use console::style;
use emoji;
use std::process::Command;
use PBAR;

pub fn rustup_add_wasm_target() {
let step = format!(
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fs::File;
use std::io::prelude::*;

use PBAR;
use console::style;
use emoji;
use failure::Error;
use serde_json;
use toml;
use PBAR;

#[derive(Deserialize)]
struct CargoManifest {
Expand Down
2 changes: 1 addition & 1 deletion src/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use console::style;
use failure::Error;
use std::fs;

use PBAR;
use emoji;
use PBAR;

pub fn copy_from_crate(path: &str) -> Result<(), Error> {
let step = format!(
Expand Down

0 comments on commit b28b3cd

Please sign in to comment.