From 44f26dfcb2c73fea530b65bd434517a26806aaa9 Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Fri, 15 Jun 2018 14:15:20 -0700 Subject: [PATCH 1/3] feat(init): no install flag --- src/command/init.rs | 38 +++++++++++++++++++++++++++++++------- src/command/mod.rs | 21 +++++++++++---------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/command/init.rs b/src/command/init.rs index c409a86..b227162 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -26,6 +26,7 @@ pub fn create_pkg_dir(path: &str, step: &Step) -> result::Result<(), Error> { pub enum InitMode { Normal, Nobuild, + Noinstall, } pub struct Init { @@ -78,9 +79,17 @@ impl Init { step_create_json, step_copy_readme, step_install_wasm_bindgen, - step_running_wasm_bindgen, + step_run_wasm_bindgen, ], InitMode::Nobuild => steps![step_create_dir, step_create_json, step_copy_readme,], + InitMode::Noinstall => steps![ + step_check_crate_config, + step_build_wasm, + step_create_dir, + step_create_json, + step_copy_readme, + step_run_wasm_bindgen + ], } } @@ -211,11 +220,7 @@ impl Init { Ok(()) } - fn step_running_wasm_bindgen( - &mut self, - step: &Step, - log: &Logger, - ) -> result::Result<(), Error> { + fn step_run_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> result::Result<(), Error> { info!(&log, "Building the wasm bindings..."); bindgen::wasm_bindgen_build( &self.crate_path, @@ -259,7 +264,7 @@ mod test { "step_create_json", "step_copy_readme", "step_install_wasm_bindgen", - "step_running_wasm_bindgen" + "step_run_wasm_bindgen" ] ); } @@ -275,4 +280,23 @@ mod test { ["step_create_dir", "step_create_json", "step_copy_readme"] ); } + + #[test] + fn init_skip_install() { + let steps: Vec<&str> = Init::get_process_steps(InitMode::Noinstall) + .into_iter() + .map(|(n, _)| n) + .collect(); + assert_eq!( + steps, + [ + "step_check_crate_config", + "step_build_wasm", + "step_create_dir", + "step_create_json", + "step_copy_readme", + "step_run_wasm_bindgen" + ] + ); + } } diff --git a/src/command/mod.rs b/src/command/mod.rs index 18da885..08abf5e 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -23,9 +23,9 @@ pub enum Command { #[structopt(long = "scope", short = "s")] scope: Option, - #[structopt(long = "--skip-build")] - /// Do not build, only update metadata - skip_build: bool, + #[structopt(long = "mode", short = "m", default_value = "normal")] + /// Sets steps to be run. [possible values: no-build, no-install, normal] + mode: String, #[structopt(long = "no-typescript")] /// By default a *.d.ts file is generated for the generated JS file, but @@ -89,7 +89,7 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error Command::Init { path, scope, - skip_build, + mode, disable_dts, target, debug, @@ -100,17 +100,18 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error "Path: {:?}, Scope: {:?}, Skip build: {}, Disable Dts: {}, Target: {}, Debug: {}", &path, &scope, - &skip_build, + &mode, &disable_dts, &target, debug ); - let mode = if skip_build { - InitMode::Nobuild - } else { - InitMode::Normal + let modetype = match &*mode { + "no-build" => InitMode::Nobuild, + "no-install" => InitMode::Noinstall, + "normal" => InitMode::Normal, + _ => InitMode::Normal, }; - Init::new(path, scope, disable_dts, target, debug).process(&log, mode) + Init::new(path, scope, disable_dts, target, debug).process(&log, modetype) } Command::Pack { path } => { info!(&log, "Running pack command..."); From f2fbe264d42e3bb52f5dcd41a7c0be7f5fe9d722 Mon Sep 17 00:00:00 2001 From: Michael Gattozzi Date: Mon, 18 Jun 2018 12:45:30 -0400 Subject: [PATCH 2/3] fix(no-install): cratename should not be an option --- src/command/init.rs | 22 ++++++++++++---------- src/command/mod.rs | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/command/init.rs b/src/command/init.rs index b227162..7ca6bce 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -35,7 +35,7 @@ pub struct Init { disable_dts: bool, target: String, debug: bool, - crate_name: Option, + crate_name: String, } type InitStep = fn(&mut Init, &Step, &Logger) -> result::Result<(), Error>; @@ -47,15 +47,17 @@ impl Init { disable_dts: bool, target: String, debug: bool, - ) -> Init { - Init { - crate_path: set_crate_path(path), + ) -> Result { + let crate_path = set_crate_path(path); + let crate_name = manifest::get_crate_name(&crate_path)?; + Ok(Init { + crate_path, scope, disable_dts, target, debug, - crate_name: None, - } + crate_name + }) } fn get_process_steps(mode: InitMode) -> Vec<(&'static str, InitStep)> { @@ -202,19 +204,19 @@ impl Init { info!(&log, "Installing wasm-bindgen-cli was successful."); info!(&log, "Getting the crate name from the manifest..."); - self.crate_name = Some(manifest::get_crate_name(&self.crate_path)?); + self.crate_name = manifest::get_crate_name(&self.crate_path)?; #[cfg(not(target_os = "windows"))] info!( &log, "Got crate name {} from the manifest at {}/Cargo.toml.", - &self.crate_name.as_ref().unwrap(), + &self.crate_name, &self.crate_path ); #[cfg(target_os = "windows")] info!( &log, "Got crate name {} from the manifest at {}\\Cargo.toml.", - &self.crate_name.as_ref().unwrap(), + &self.crate_name, &self.crate_path ); Ok(()) @@ -224,7 +226,7 @@ impl Init { info!(&log, "Building the wasm bindings..."); bindgen::wasm_bindgen_build( &self.crate_path, - &self.crate_name.as_ref().unwrap(), + &self.crate_name, self.disable_dts, &self.target, self.debug, diff --git a/src/command/mod.rs b/src/command/mod.rs index 08abf5e..3319c8a 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -111,7 +111,7 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error "normal" => InitMode::Normal, _ => InitMode::Normal, }; - Init::new(path, scope, disable_dts, target, debug).process(&log, modetype) + Init::new(path, scope, disable_dts, target, debug)?.process(&log, modetype) } Command::Pack { path } => { info!(&log, "Running pack command..."); From 78527b7a7ee6969ade7f497124364b3530da8403 Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Mon, 18 Jun 2018 12:54:48 -0400 Subject: [PATCH 3/3] fix(style): appease cargo fmt --- src/command/init.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/init.rs b/src/command/init.rs index 7ca6bce..0648509 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -56,7 +56,7 @@ impl Init { disable_dts, target, debug, - crate_name + crate_name, }) }