Skip to content

Commit

Permalink
Add a --debug option to suppress --release.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsybitesyspider committed May 28, 2018
1 parent edfae10 commit 7b432ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
13 changes: 11 additions & 2 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
}
}

pub fn wasm_bindgen_build(path: &str, name: &str, disable_dts: bool) -> Result<(), Error> {
pub fn wasm_bindgen_build(
path: &str,
name: &str,
disable_dts: bool,
debug: bool,
) -> Result<(), Error> {
let step = format!(
"{} {}Running WASM-bindgen...",
style("[7/7]").bold().dim(),
emoji::RUNNER
);
let pb = PBAR.message(&step);
let binary_name = name.replace("-", "_");
let wasm_path = format!("target/wasm32-unknown-unknown/release/{}.wasm", binary_name);
let release_or_debug = if debug { "debug" } else { "release" };
let wasm_path = format!(
"target/wasm32-unknown-unknown/{}/{}.wasm",
release_or_debug, binary_name
);
let dts_arg = if disable_dts == false {
"--typescript"
} else {
Expand Down
18 changes: 10 additions & 8 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ pub fn rustup_add_wasm_target() -> Result<(), Error> {
}
}

pub fn cargo_build_wasm(path: &str) -> Result<(), Error> {
pub fn cargo_build_wasm(path: &str, debug: bool) -> Result<(), Error> {
let step = format!(
"{} {}Compiling to WASM...",
style("[2/7]").bold().dim(),
emoji::CYCLONE
);
let pb = PBAR.message(&step);
let output = Command::new("cargo")
.current_dir(path)
.arg("build")
.arg("--release")
.arg("--target")
.arg("wasm32-unknown-unknown")
.output()?;
let output = {
let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build");
if !debug {
cmd.arg("--release");
}
cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.output()?
};
pb.finish();
if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr);
Expand Down
11 changes: 8 additions & 3 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub enum Command {
scope: Option<String>,
#[structopt(long = "no-typescript")]
disable_dts: bool,
#[structopt(long = "debug")]
/// Build without --release.
debug: bool,
},

#[structopt(name = "pack")]
Expand Down Expand Up @@ -67,7 +70,8 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
path,
scope,
disable_dts,
} => init(path, scope, disable_dts),
debug,
} => init(path, scope, disable_dts, debug),
Command::Pack { path } => pack(path),
Command::Publish { path } => publish(path),
Command::Login {
Expand Down Expand Up @@ -114,19 +118,20 @@ fn init(
path: Option<String>,
scope: Option<String>,
disable_dts: bool,
debug: bool,
) -> result::Result<(), Error> {
let started = Instant::now();

let crate_path = set_crate_path(path);

build::rustup_add_wasm_target()?;
build::cargo_build_wasm(&crate_path)?;
build::cargo_build_wasm(&crate_path, debug)?;
create_pkg_dir(&crate_path)?;
manifest::write_package_json(&crate_path, scope, disable_dts)?;
readme::copy_from_crate(&crate_path)?;
bindgen::cargo_install_wasm_bindgen()?;
let name = manifest::get_crate_name(&crate_path)?;
bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts)?;
bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, debug)?;
PBAR.message(&format!(
"{} Done in {}",
emoji::SPARKLE,
Expand Down

0 comments on commit 7b432ef

Please sign in to comment.