Skip to content

Commit

Permalink
Merge pull request #151 from kohensu/add_--skip-build_flag_#144
Browse files Browse the repository at this point in the history
Add --skip-build flag for init command #144
  • Loading branch information
ashleygwilliams authored Jun 13, 2018
2 parents 06160a1 + 74fe847 commit 0c8c90a
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 156 deletions.
12 changes: 12 additions & 0 deletions docs/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ The exact meaning of this flag may evolve as the platform matures.

[npm-scope-documentation]: https://docs.npmjs.com/misc/scope
[cargo-profile-sections-documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections

## Skipping build

The init command accepts an optional `--skip-build` argument.

This will deactivate those steps:
- installing wasm target (via cargo)
- compiling the code to wasm
- installing wasm-bindgen (via rustup)
- running wasm-bindgen on the built wasm

Basically it will remains only the steps that update the metadata of `package.json`.
25 changes: 9 additions & 16 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use console::style;
use emoji;
use error::Error;
use progressbar::Step;
use std::process::Command;
use PBAR;

pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
let step = format!(
"{} {}Installing WASM-bindgen...",
style("[6/7]").bold().dim(),
emoji::DOWN_ARROW
);
let pb = PBAR.message(&step);
pub fn cargo_install_wasm_bindgen(step: &Step) -> Result<(), Error> {
let msg = format!("{}Installing WASM-bindgen...", emoji::DOWN_ARROW);
let pb = PBAR.step(step, &msg);
let output = Command::new("cargo")
.arg("install")
.arg("wasm-bindgen-cli")
Expand All @@ -33,15 +29,12 @@ pub fn wasm_bindgen_build(
path: &str,
name: &str,
disable_dts: bool,
target: String,
target: &str,
debug: bool,
step: &Step,
) -> Result<(), Error> {
let step = format!(
"{} {}Running WASM-bindgen...",
style("[7/7]").bold().dim(),
emoji::RUNNER
);
let pb = PBAR.message(&step);
let msg = format!("{}Running WASM-bindgen...", emoji::RUNNER);
let pb = PBAR.step(step, &msg);
let binary_name = name.replace("-", "_");
let release_or_debug = if debug { "debug" } else { "release" };
let wasm_path = format!(
Expand All @@ -54,7 +47,7 @@ pub fn wasm_bindgen_build(
"--no-typescript"
};

let target_arg = match target.as_str() {
let target_arg = match target {
"nodejs" => "--nodejs",
_ => "--browser",
};
Expand Down
22 changes: 7 additions & 15 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use console::style;
use emoji;
use error::Error;
use progressbar::Step;
use std::process::Command;
use PBAR;

pub fn rustup_add_wasm_target() -> Result<(), Error> {
let step = format!(
"{} {}Adding WASM target...",
style("[1/7]").bold().dim(),
emoji::TARGET
);
let pb = PBAR.message(&step);
pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> {
let msg = format!("{}Adding WASM target...", emoji::TARGET);
let pb = PBAR.step(step, &msg);
let output = Command::new("rustup")
.arg("target")
.arg("add")
Expand All @@ -25,13 +21,9 @@ pub fn rustup_add_wasm_target() -> 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);
pub fn cargo_build_wasm(path: &str, debug: bool, step: &Step) -> Result<(), Error> {
let msg = format!("{}Compiling to WASM...", emoji::CYCLONE);
let pb = PBAR.step(step, &msg);
let output = {
let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build");
Expand Down
Loading

0 comments on commit 0c8c90a

Please sign in to comment.