fix(crate_config): combine crate type and dep check, emit step

master
Ashley Williams 7 years ago
parent c190d5d444
commit d09db16623
  1. 32
      src/command.rs
  2. 12
      src/manifest.rs

@ -213,13 +213,12 @@ impl Init {
match mode {
InitMode::Normal => steps![
step_check_dependency,
step_check_crate_config,
step_add_wasm_target,
step_build_wasm,
step_create_dir,
step_create_json,
step_copy_readme,
step_check_crate_type,
step_install_wasm_bindgen,
step_running_wasm_bindgen,
],
@ -260,10 +259,10 @@ impl Init {
Ok(())
}
fn step_check_dependency(&mut self, _step: &Step, log: &Logger) -> result::Result<(), Error> {
info!(&log, "Checking wasm-bindgen dependency...");
manifest::check_wasm_bindgen(&self.crate_path)?;
info!(&log, "wasm-bindgen dependency is correctly declared.");
fn step_check_crate_config(&mut self, step: &Step, log: &Logger) -> result::Result<(), Error> {
info!(&log, "Checking crate configuration...");
manifest::check_crate_config(&self.crate_path, step)?;
info!(&log, "Crate is correctly configured.");
Ok(())
}
@ -330,23 +329,6 @@ impl Init {
Ok(())
}
fn step_check_crate_type(&mut self, _step: &Step, log: &Logger) -> result::Result<(), Error> {
info!(&log, "Checking the crate type from the manifest...");
manifest::check_crate_type(&self.crate_path)?;
#[cfg(not(target_os = "windows"))]
info!(
&log,
"Checked crate type from the manifest at {}/Cargo.toml.", &self.crate_path
);
#[cfg(target_os = "windows")]
info!(
&log,
"Checked crate type from the manifest at {}\\Cargo.toml.", &self.crate_path
);
Ok(())
}
fn step_install_wasm_bindgen(
&mut self,
step: &Step,
@ -477,13 +459,12 @@ mod test {
assert_eq!(
steps,
[
"step_check_dependency",
"step_check_crate_config",
"step_add_wasm_target",
"step_build_wasm",
"step_create_dir",
"step_create_json",
"step_copy_readme",
"step_check_crate_type",
"step_install_wasm_bindgen",
"step_running_wasm_bindgen"
]
@ -499,7 +480,6 @@ mod test {
assert_eq!(
steps,
[
"step_check_dependency",
"step_create_dir",
"step_create_json",
"step_copy_readme"

@ -148,7 +148,15 @@ pub fn get_crate_name(path: &str) -> Result<String, Error> {
Ok(read_cargo_toml(path)?.package.name)
}
pub fn check_wasm_bindgen(path: &str) -> Result<(), Error> {
pub fn check_crate_config(path: &str, step: &Step) -> Result<(), Error> {
let msg = format!("{}Checking crate configuration...", emoji::WRENCH);
PBAR.step(&step, &msg)?;
check_wasm_bindgen(path)?;
check_crate_type(path)?;
Ok(())
}
fn check_wasm_bindgen(path: &str) -> Result<(), Error> {
if read_cargo_toml(path)?.dependencies.map_or(false, |x| {
!x.wasm_bindgen.unwrap_or("".to_string()).is_empty()
}) {
@ -160,7 +168,7 @@ pub fn check_wasm_bindgen(path: &str) -> Result<(), Error> {
))
}
pub fn check_crate_type(path: &str) -> Result<(), Error> {
fn check_crate_type(path: &str) -> Result<(), Error> {
if read_cargo_toml(path)?.lib.map_or(false, |lib| {
lib.crate_type
.map_or(false, |types| types.iter().any(|s| s == "cdylib"))

Loading…
Cancel
Save