feat(init): no install flag

master
Ashley Williams 7 years ago
parent 1c50b12b8f
commit 44f26dfcb2
  1. 38
      src/command/init.rs
  2. 21
      src/command/mod.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"
]
);
}
}

@ -23,9 +23,9 @@ pub enum Command {
#[structopt(long = "scope", short = "s")]
scope: Option<String>,
#[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...");

Loading…
Cancel
Save