From d09db166235de6d74dedb2c30260175a111bc819 Mon Sep 17 00:00:00 2001
From: Ashley Williams <ashley666ashley@gmail.com>
Date: Thu, 14 Jun 2018 13:39:02 -0700
Subject: [PATCH] fix(crate_config): combine crate type and dep check, emit
 step

---
 src/command.rs  | 32 ++++++--------------------------
 src/manifest.rs | 12 ++++++++++--
 2 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/src/command.rs b/src/command.rs
index 60ac613..5d2ea8e 100644
--- a/src/command.rs
+++ b/src/command.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"
diff --git a/src/manifest.rs b/src/manifest.rs
index cf7c9e4..703fd3f 100644
--- a/src/manifest.rs
+++ b/src/manifest.rs
@@ -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"))