Repository: ashleygwilliams/wasm-pack
Pull request #82 (2018-04-16 13:21:52)

Add PR template to the repo
We want to make sure people format their code as well as reference the
issue that's going to be closed as well so we don't have to close the
issue manually! This PR adds a template for PRs that includes these
points as a checklist to ensure future contributors know what they need
to do!


Patch:
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..e07bd50
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,12 @@
+Make sure these boxes are checked! 📦✅
+
+- [ ] You have the latest version of `rustfmt` installed and have your 
+      cloned directory set to nightly
+```bash
+$ rustup override set nightly
+$ rustup component add rustfmt-preview --toolchain nightly
+```
+- [ ] You ran `rustfmt` on the code base before submitting
+- [ ] You reference which issue is being closed in the PR text
+
+✨✨ 😄 Thanks so much for contributing to wasm-pack! 😄 ✨✨
diff --git a/src/bindgen.rs b/src/bindgen.rs
index 19cafeb..af8e17c 100644
--- a/src/bindgen.rs
+++ b/src/bindgen.rs
@@ -1,7 +1,7 @@
+use PBAR;
 use console::style;
 use emoji;
 use std::process::Command;
-use PBAR;
 
 pub fn cargo_install_wasm_bindgen() {
     let step = format!(
diff --git a/src/build.rs b/src/build.rs
index aa3b807..f6953a5 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -1,7 +1,7 @@
+use PBAR;
 use console::style;
 use emoji;
 use std::process::Command;
-use PBAR;
 
 pub fn rustup_add_wasm_target() {
     let step = format!(
diff --git a/src/command.rs b/src/command.rs
deleted file mode 100644
index 0abde7b..0000000
--- a/src/command.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-use bindgen;
-use build;
-use console::style;
-use emoji;
-use failure::Error;
-use indicatif::HumanDuration;
-use manifest;
-use npm;
-use quicli::prelude::*;
-use readme;
-use std::fs;
-use std::result;
-use std::time::Instant;
-use PBAR;
-
-#[derive(Debug, StructOpt)]
-pub enum Command {
-    #[structopt(name = "init")]
-    /// 🐣  initialize a package.json based on your cmpiled wasm
-    Init {
-        path: Option<String>,
-        #[structopt(long = "scope", short = "s")]
-        scope: Option<String>,
-    },
-    #[structopt(name = "pack")]
-    /// 🍱  create a tar of your npm package but don't ublish! [NOT IMPLEMENTED]
-    Pack { path: Option<String> },
-    #[structopt(name = "publish")]
-    /// 🎆  pack up your npm package and publish! [NOT MPLEMENTED]
-    Publish { path: Option<String> },
-}
-
-// quicli::prelude::* imports a different result struct which gets
-// precedence over the std::result::Result, so have had to specify
-// the correct type here.
-pub fn create_pkg_dir(path: &str) -> result::Result<(), Error> {
-    let step = format!(
-        "{} {}Creating a pkg directory...",
-        style("[3/7]").bold().dim(),
-        emoji::FOLDER
-    );
-    let pb = PBAR.message(&step);
-    let pkg_dir_path = format!("{}/pkg", path);
-    fs::create_dir_all(pkg_dir_path)?;
-    pb.finish();
-    Ok(())
-}
-
-pub fn init(path: Option<String>, scope: Option<String>) -> result::Result<(), Error> {
-    let started = Instant::now();
-
-    let crate_path = set_crate_path(path);
-
-    build::rustup_add_wasm_target();
-    build::cargo_build_wasm(&crate_path);
-    create_pkg_dir(&crate_path)?;
-    manifest::write_package_json(&crate_path, scope)?;
-    readme::copy_from_crate(&crate_path)?;
-    bindgen::cargo_install_wasm_bindgen();
-    let name = manifest::get_crate_name(&crate_path)?;
-    bindgen::wasm_bindgen_build(&crate_path, &name);
-    PBAR.one_off_message(&format!(
-        "{} Done in {}",
-        emoji::SPARKLE,
-        HumanDuration(started.elapsed())
-    ));
-    PBAR.one_off_message(&format!(
-        "{} Your WASM pkg is ready to publish at {}/pkg",
-        emoji::PACKAGE,
-        &crate_path
-    ));
-    PBAR.done()?;
-    Ok(())
-}
-
-pub fn pack(path: Option<String>) -> result::Result<(), Error> {
-    let crate_path = set_crate_path(path);
-
-    npm::npm_pack(&crate_path);
-    println!("🎒  packed up your package!");
-    Ok(())
-}
-
-pub fn publish(path: Option<String>) -> result::Result<(), Error> {
-    let crate_path = set_crate_path(path);
-
-    npm::npm_publish(&crate_path);
-    println!("💥  published your package!");
-    Ok(())
-}
-
-fn set_crate_path(path: Option<String>) -> String {
-    let crate_path = match path {
-        Some(p) => p,
-        None => ".".to_string(),
-    };
-
-    crate_path
-}
diff --git a/src/lib.rs b/src/lib.rs
index 46009a9..2330b02 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,7 +3,6 @@ extern crate failure;
 extern crate indicatif;
 #[macro_use]
 extern crate lazy_static;
-extern crate quicli;
 #[macro_use]
 extern crate serde_derive;
 extern crate serde_json;
@@ -11,26 +10,31 @@ extern crate toml;
 
 pub mod bindgen;
 pub mod build;
-pub mod command;
 pub mod emoji;
 pub mod manifest;
 pub mod npm;
 pub mod progressbar;
 pub mod readme;
 
+use std::fs;
+
+use console::style;
+use failure::Error;
 use progressbar::ProgressOutput;
-use quicli::prelude::*;
 
 lazy_static! {
     pub static ref PBAR: ProgressOutput = { ProgressOutput::new() };
 }
 
-/// 📦 ✨  pack and publish your wasm!
-#[derive(Debug, StructOpt)]
-pub struct Cli {
-    #[structopt(subcommand)] // Note that we mark a field as a subcommand
-    pub cmd: command::Command,
-    ///  log all the things
-    #[structopt(long = "verbose", short = "v", parse(from_occurrences))]
-    pub verbosity: u8,
+pub fn create_pkg_dir(path: &str) -> Result<(), Error> {
+    let step = format!(
+        "{} {}Creating a pkg directory...",
+        style("[3/7]").bold().dim(),
+        emoji::FOLDER
+    );
+    let pb = PBAR.message(&step);
+    let pkg_dir_path = format!("{}/pkg", path);
+    fs::create_dir_all(pkg_dir_path)?;
+    pb.finish();
+    Ok(())
 }
diff --git a/src/main.rs b/src/main.rs
index 2b4caa0..bf56f92 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,18 +4,82 @@ extern crate indicatif;
 #[macro_use]
 extern crate quicli;
 
+use std::time::Instant;
+
+use indicatif::HumanDuration;
 use quicli::prelude::*;
-use wasm_pack::command::{init, pack, publish, Command};
-use wasm_pack::Cli;
+use wasm_pack::{bindgen, build, emoji, manifest, npm, readme, PBAR};
+
+/// 📦 ✨  pack and publish your wasm!
+#[derive(Debug, StructOpt)]
+struct Cli {
+    #[structopt(subcommand)] // Note that we mark a field as a subcommand
+    cmd: Command,
+    /// 📝  log all the things!
+    #[structopt(long = "verbose", short = "v", parse(from_occurrences))]
+    verbosity: u8,
+}
+
+#[derive(Debug, StructOpt)]
+enum Command {
+    #[structopt(name = "init")]
+    /// 🐣  initialize a package.json based on your compiled wasm
+    Init {
+        path: Option<String>,
+        #[structopt(long = "scope", short = "s")]
+        scope: Option<String>,
+    },
+    #[structopt(name = "pack")]
+    /// 🍱  create a tar of your npm package but don't publish! [NOT IMPLEMENTED]
+    Pack { path: Option<String> },
+    #[structopt(name = "publish")]
+    /// 🎆  pack up your npm package and publish! [NOT IMPLEMENTED]
+    Publish { path: Option<String> },
+}
 
 main!(|args: Cli, log_level: verbosity| match args.cmd {
     Command::Init { path, scope } => {
-        init(path, scope)?;
+        let started = Instant::now();
+
+        let crate_path = match path {
+            Some(p) => p,
+            None => ".".to_string(),
+        };
+
+        build::rustup_add_wasm_target();
+        build::cargo_build_wasm(&crate_path);
+        wasm_pack::create_pkg_dir(&crate_path)?;
+        manifest::write_package_json(&crate_path, scope)?;
+        readme::copy_from_crate(&crate_path)?;
+        bindgen::cargo_install_wasm_bindgen();
+        let name = manifest::get_crate_name(&crate_path)?;
+        bindgen::wasm_bindgen_build(&crate_path, &name);
+        PBAR.one_off_message(&format!(
+            "{} Done in {}",
+            emoji::SPARKLE,
+            HumanDuration(started.elapsed())
+        ));
+        PBAR.one_off_message(&format!(
+            "{} Your WASM pkg is ready to publish at {}/pkg",
+            emoji::PACKAGE,
+            &crate_path
+        ));
+        PBAR.done()?;
     }
     Command::Pack { path } => {
-        pack(path)?;
+        let crate_path = match path {
+            Some(p) => p,
+            None => ".".to_string(),
+        };
+        npm::npm_pack(&crate_path);
+        println!("🎒  packed up your package!");
     }
     Command::Publish { path } => {
-        publish(path)?;
+        let crate_path = match path {
+            Some(p) => p,
+            None => ".".to_string(),
+        };
+        npm::npm_publish(&crate_path);
+        println!("💥  published your package!");
     }
 });
diff --git a/src/manifest.rs b/src/manifest.rs
index b7a6fb7..c60583a 100644
--- a/src/manifest.rs
+++ b/src/manifest.rs
@@ -1,12 +1,12 @@
 use std::fs::File;
 use std::io::prelude::*;
 
+use PBAR;
 use console::style;
 use emoji;
 use failure::Error;
 use serde_json;
 use toml;
-use PBAR;
 
 #[derive(Deserialize)]
 struct CargoManifest {
diff --git a/src/readme.rs b/src/readme.rs
index fa9d4d3..b050306 100644
--- a/src/readme.rs
+++ b/src/readme.rs
@@ -2,8 +2,8 @@ use console::style;
 use failure::Error;
 use std::fs;
 
-use emoji;
 use PBAR;
+use emoji;
 
 pub fn copy_from_crate(path: &str) -> Result<(), Error> {
     let step = format!(


Test patch:
diff --git a/tests/manifest/main.rs b/tests/manifest/main.rs
index 2ef3a6a..22a2f16 100644
--- a/tests/manifest/main.rs
+++ b/tests/manifest/main.rs
@@ -28,7 +28,7 @@ fn it_gets_the_crate_name_provided_path() {
 #[test]
 fn it_creates_a_package_json_default_path() {
     let path = ".".to_string();
-    wasm_pack::command::create_pkg_dir(&path).unwrap();
+    wasm_pack::create_pkg_dir(&path).unwrap();
     assert!(manifest::write_package_json(&path, None).is_ok());
     let package_json_path = format!("{}/pkg/package.json", &path);
     assert!(fs::metadata(package_json_path).is_ok());
@@ -46,7 +46,7 @@ fn it_creates_a_package_json_default_path() {
 #[test]
 fn it_creates_a_package_json_provided_path() {
     let path = "tests/fixtures/js-hello-world".to_string();
-    wasm_pack::command::create_pkg_dir(&path).unwrap();
+    wasm_pack::create_pkg_dir(&path).unwrap();
     assert!(manifest::write_package_json(&path, None).is_ok());
     let package_json_path = format!("{}/pkg/package.json", &path);
     assert!(fs::metadata(package_json_path).is_ok());
@@ -59,7 +59,7 @@ fn it_creates_a_package_json_provided_path() {
 #[test]
 fn it_creates_a_package_json_provided_path_with_scope() {
     let path = "tests/fixtures/scopes".to_string();
-    wasm_pack::command::create_pkg_dir(&path).unwrap();
+    wasm_pack::create_pkg_dir(&path).unwrap();
     assert!(manifest::write_package_json(&path, Some("test".to_string())).is_ok());
     let package_json_path = format!("{}/pkg/package.json", &path);
     assert!(fs::metadata(package_json_path).is_ok());