Merge pull request #186 from ashleygwilliams/no-install-no-cry

feat(init): no install flag
master
ashley williams 7 years ago committed by GitHub
commit 48410ba07f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      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 { pub enum InitMode {
Normal, Normal,
Nobuild, Nobuild,
Noinstall,
} }
pub struct Init { pub struct Init {
@ -34,7 +35,7 @@ pub struct Init {
disable_dts: bool, disable_dts: bool,
target: String, target: String,
debug: bool, debug: bool,
crate_name: Option<String>, crate_name: String,
} }
type InitStep = fn(&mut Init, &Step, &Logger) -> result::Result<(), Error>; type InitStep = fn(&mut Init, &Step, &Logger) -> result::Result<(), Error>;
@ -46,15 +47,17 @@ impl Init {
disable_dts: bool, disable_dts: bool,
target: String, target: String,
debug: bool, debug: bool,
) -> Init { ) -> Result<Init, Error> {
Init { let crate_path = set_crate_path(path);
crate_path: set_crate_path(path), let crate_name = manifest::get_crate_name(&crate_path)?;
Ok(Init {
crate_path,
scope, scope,
disable_dts, disable_dts,
target, target,
debug, debug,
crate_name: None, crate_name,
} })
} }
fn get_process_steps(mode: InitMode) -> Vec<(&'static str, InitStep)> { fn get_process_steps(mode: InitMode) -> Vec<(&'static str, InitStep)> {
@ -78,9 +81,17 @@ impl Init {
step_create_json, step_create_json,
step_copy_readme, step_copy_readme,
step_install_wasm_bindgen, 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::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
],
} }
} }
@ -193,33 +204,29 @@ impl Init {
info!(&log, "Installing wasm-bindgen-cli was successful."); info!(&log, "Installing wasm-bindgen-cli was successful.");
info!(&log, "Getting the crate name from the manifest..."); 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"))] #[cfg(not(target_os = "windows"))]
info!( info!(
&log, &log,
"Got crate name {} from the manifest at {}/Cargo.toml.", "Got crate name {} from the manifest at {}/Cargo.toml.",
&self.crate_name.as_ref().unwrap(), &self.crate_name,
&self.crate_path &self.crate_path
); );
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
info!( info!(
&log, &log,
"Got crate name {} from the manifest at {}\\Cargo.toml.", "Got crate name {} from the manifest at {}\\Cargo.toml.",
&self.crate_name.as_ref().unwrap(), &self.crate_name,
&self.crate_path &self.crate_path
); );
Ok(()) Ok(())
} }
fn step_running_wasm_bindgen( fn step_run_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> result::Result<(), Error> {
&mut self,
step: &Step,
log: &Logger,
) -> result::Result<(), Error> {
info!(&log, "Building the wasm bindings..."); info!(&log, "Building the wasm bindings...");
bindgen::wasm_bindgen_build( bindgen::wasm_bindgen_build(
&self.crate_path, &self.crate_path,
&self.crate_name.as_ref().unwrap(), &self.crate_name,
self.disable_dts, self.disable_dts,
&self.target, &self.target,
self.debug, self.debug,
@ -259,7 +266,7 @@ mod test {
"step_create_json", "step_create_json",
"step_copy_readme", "step_copy_readme",
"step_install_wasm_bindgen", "step_install_wasm_bindgen",
"step_running_wasm_bindgen" "step_run_wasm_bindgen"
] ]
); );
} }
@ -275,4 +282,23 @@ mod test {
["step_create_dir", "step_create_json", "step_copy_readme"] ["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")] #[structopt(long = "scope", short = "s")]
scope: Option<String>, scope: Option<String>,
#[structopt(long = "--skip-build")] #[structopt(long = "mode", short = "m", default_value = "normal")]
/// Do not build, only update metadata /// Sets steps to be run. [possible values: no-build, no-install, normal]
skip_build: bool, mode: String,
#[structopt(long = "no-typescript")] #[structopt(long = "no-typescript")]
/// By default a *.d.ts file is generated for the generated JS file, but /// 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 { Command::Init {
path, path,
scope, scope,
skip_build, mode,
disable_dts, disable_dts,
target, target,
debug, 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: {}, Disable Dts: {}, Target: {}, Debug: {}",
&path, &path,
&scope, &scope,
&skip_build, &mode,
&disable_dts, &disable_dts,
&target, &target,
debug debug
); );
let mode = if skip_build { let modetype = match &*mode {
InitMode::Nobuild "no-build" => InitMode::Nobuild,
} else { "no-install" => InitMode::Noinstall,
InitMode::Normal "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 } => { Command::Pack { path } => {
info!(&log, "Running pack command..."); info!(&log, "Running pack command...");

Loading…
Cancel
Save