Skip to content

Commit 0c8c90a

Browse files
Merge pull request #151 from kohensu/add_--skip-build_flag_#144
Add --skip-build flag for init command #144
2 parents 06160a1 + 74fe847 commit 0c8c90a

File tree

9 files changed

+356
-156
lines changed

9 files changed

+356
-156
lines changed

docs/init.md

+12
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ The exact meaning of this flag may evolve as the platform matures.
5858

5959
[npm-scope-documentation]: https://docs.npmjs.com/misc/scope
6060
[cargo-profile-sections-documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections
61+
62+
## Skipping build
63+
64+
The init command accepts an optional `--skip-build` argument.
65+
66+
This will deactivate those steps:
67+
- installing wasm target (via cargo)
68+
- compiling the code to wasm
69+
- installing wasm-bindgen (via rustup)
70+
- running wasm-bindgen on the built wasm
71+
72+
Basically it will remains only the steps that update the metadata of `package.json`.

src/bindgen.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
use console::style;
21
use emoji;
32
use error::Error;
3+
use progressbar::Step;
44
use std::process::Command;
55
use PBAR;
66

7-
pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
8-
let step = format!(
9-
"{} {}Installing WASM-bindgen...",
10-
style("[6/7]").bold().dim(),
11-
emoji::DOWN_ARROW
12-
);
13-
let pb = PBAR.message(&step);
7+
pub fn cargo_install_wasm_bindgen(step: &Step) -> Result<(), Error> {
8+
let msg = format!("{}Installing WASM-bindgen...", emoji::DOWN_ARROW);
9+
let pb = PBAR.step(step, &msg);
1410
let output = Command::new("cargo")
1511
.arg("install")
1612
.arg("wasm-bindgen-cli")
@@ -33,15 +29,12 @@ pub fn wasm_bindgen_build(
3329
path: &str,
3430
name: &str,
3531
disable_dts: bool,
36-
target: String,
32+
target: &str,
3733
debug: bool,
34+
step: &Step,
3835
) -> Result<(), Error> {
39-
let step = format!(
40-
"{} {}Running WASM-bindgen...",
41-
style("[7/7]").bold().dim(),
42-
emoji::RUNNER
43-
);
44-
let pb = PBAR.message(&step);
36+
let msg = format!("{}Running WASM-bindgen...", emoji::RUNNER);
37+
let pb = PBAR.step(step, &msg);
4538
let binary_name = name.replace("-", "_");
4639
let release_or_debug = if debug { "debug" } else { "release" };
4740
let wasm_path = format!(
@@ -54,7 +47,7 @@ pub fn wasm_bindgen_build(
5447
"--no-typescript"
5548
};
5649

57-
let target_arg = match target.as_str() {
50+
let target_arg = match target {
5851
"nodejs" => "--nodejs",
5952
_ => "--browser",
6053
};

src/build.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
use console::style;
21
use emoji;
32
use error::Error;
3+
use progressbar::Step;
44
use std::process::Command;
55
use PBAR;
66

7-
pub fn rustup_add_wasm_target() -> Result<(), Error> {
8-
let step = format!(
9-
"{} {}Adding WASM target...",
10-
style("[1/7]").bold().dim(),
11-
emoji::TARGET
12-
);
13-
let pb = PBAR.message(&step);
7+
pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> {
8+
let msg = format!("{}Adding WASM target...", emoji::TARGET);
9+
let pb = PBAR.step(step, &msg);
1410
let output = Command::new("rustup")
1511
.arg("target")
1612
.arg("add")
@@ -25,13 +21,9 @@ pub fn rustup_add_wasm_target() -> Result<(), Error> {
2521
}
2622
}
2723

28-
pub fn cargo_build_wasm(path: &str, debug: bool) -> Result<(), Error> {
29-
let step = format!(
30-
"{} {}Compiling to WASM...",
31-
style("[2/7]").bold().dim(),
32-
emoji::CYCLONE
33-
);
34-
let pb = PBAR.message(&step);
24+
pub fn cargo_build_wasm(path: &str, debug: bool, step: &Step) -> Result<(), Error> {
25+
let msg = format!("{}Compiling to WASM...", emoji::CYCLONE);
26+
let pb = PBAR.step(step, &msg);
3527
let output = {
3628
let mut cmd = Command::new("cargo");
3729
cmd.current_dir(path).arg("build");

0 commit comments

Comments
 (0)