diff --git a/src/manifest.rs b/src/manifest.rs index e86e316..764f8de 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -4,6 +4,7 @@ use std::io::prelude::*; use console::style; use emoji; use failure::Error; +use indicatif::MultiProgress; use progressbar; use serde_json; use toml; @@ -17,20 +18,20 @@ struct CargoManifest { struct CargoPackage { name: String, authors: Vec, - description: String, + description: Option, version: String, - license: String, - repository: String, + license: Option, + repository: Option, } #[derive(Serialize)] struct NpmPackage { name: String, collaborators: Vec, - description: String, + description: Option, version: String, - license: String, - repository: Repository, + license: Option, + repository: Option, files: Vec, } @@ -64,10 +65,10 @@ impl CargoManifest { description: self.package.description, version: self.package.version, license: self.package.license, - repository: Repository { + repository: self.package.repository.map(|repo_url| Repository { ty: "git".to_string(), - url: self.package.repository, - }, + url: repo_url, + }), files: vec![js_file, wasm_file], } } @@ -80,14 +81,41 @@ pub fn write_package_json(path: &str, scope: Option) -> Result<(), Error style("[4/7]").bold().dim(), emoji::MEMO ); - let pb = progressbar::new(step); + + let warn = |field| { + format!( + "{} {}: Field {} is missing from Cargo.toml. It is not necessary, but recommended", + emoji::WARN, + style("[WARN]").bold().dim(), + field + ) + }; + + let m = MultiProgress::new(); + let pb = m.add(progressbar::new(step)); + let pkg_file_path = format!("{}/pkg/package.json", path); let mut pkg_file = File::create(pkg_file_path)?; let crate_data = read_cargo_toml(path)?; let npm_data = crate_data.into_npm(scope); + + if npm_data.description.is_none() { + let warn_pb = m.add(progressbar::new(warn("description"))); + warn_pb.finish(); + } + if npm_data.repository.is_none() { + let warn_pb = m.add(progressbar::new(warn("repository"))); + warn_pb.finish(); + } + if npm_data.license.is_none() { + let warn_pb = m.add(progressbar::new(warn("license"))); + warn_pb.finish(); + } + let npm_json = serde_json::to_string_pretty(&npm_data)?; pkg_file.write_all(npm_json.as_bytes())?; pb.finish(); + m.join_and_clear()?; Ok(()) } diff --git a/tests/fixtures/bad-cargo-toml/Cargo.lock b/tests/fixtures/bad-cargo-toml/Cargo.lock new file mode 100644 index 0000000..c6d7d32 --- /dev/null +++ b/tests/fixtures/bad-cargo-toml/Cargo.lock @@ -0,0 +1,140 @@ +[[package]] +name = "bad-cargo-toml" +version = "0.1.0" +dependencies = [ + "wasm-bindgen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dtoa" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "fnv" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "itoa" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-traits" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde_derive" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive_internals 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive_internals" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_json" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "0.12.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "wasm-bindgen" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "wasm-bindgen-macro 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" +"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" +"checksum num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3c2bd9b9d21e48e956b763c9f37134dc62d9e95da6edb3f672cacb6caf3cd3" +"checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" +"checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" +"checksum serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe95aa0d46f04ce5c3a88bdcd4114ecd6144ed0b2725ebca2f1127744357807" +"checksum serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "23b163a6ce7e1aa897919f9d8e40bd1f8a6f95342ed57727ae31387a01a7a356" +"checksum serde_derive_internals 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "370aa477297975243dc914d0b0e1234927520ec311de507a560fbd1c80f7ab8c" +"checksum serde_json 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "fab6c4d75bedcf880711c85e39ebf8ccc70d0eba259899047ec5d7436643ee17" +"checksum syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)" = "8c5bc2d6ff27891209efa5f63e9de78648d7801f085e4653701a692ce938d6fd" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum wasm-bindgen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "717507a3c7ef09d740c6d781bda57ba054d7b776f3e27d4478e25a773afd2e4b" +"checksum wasm-bindgen-macro 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbc1a194a8fe6319f9f326f0c03d2083d61727ace574f9b1df083bad79a314ad" +"checksum wasm-bindgen-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7cf730a826f1ec1ea2143d8582d5d2d27c0775035652daf0e0337225e8566b" diff --git a/tests/fixtures/bad-cargo-toml/Cargo.toml b/tests/fixtures/bad-cargo-toml/Cargo.toml new file mode 100644 index 0000000..36d09ac --- /dev/null +++ b/tests/fixtures/bad-cargo-toml/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bad-cargo-toml" +version = "0.1.0" +authors = ["Michael Gattozzi "] + +[dependencies] +wasm-bindgen = "0.1" diff --git a/tests/fixtures/bad-cargo-toml/README.md b/tests/fixtures/bad-cargo-toml/README.md new file mode 100644 index 0000000..1aa80a4 --- /dev/null +++ b/tests/fixtures/bad-cargo-toml/README.md @@ -0,0 +1,2 @@ +# bad-cargo-toml +> an example rust -> wasm project diff --git a/tests/fixtures/bad-cargo-toml/src/lib.rs b/tests/fixtures/bad-cargo-toml/src/lib.rs new file mode 100644 index 0000000..d4fb8e9 --- /dev/null +++ b/tests/fixtures/bad-cargo-toml/src/lib.rs @@ -0,0 +1,15 @@ +#![feature(proc_macro)] + +extern crate wasm_bindgen; + +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern { + fn alert(s: &str); +} + +#[wasm_bindgen] +pub fn greet(name: &str) { + alert(&format!("Hello, {}!", name)); +}