Merge pull request #95 from ashleygwilliams/index-main

feat(manifest): add main entry
master
ashley williams 7 years ago committed by GitHub
commit 40a5e66d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/bindgen.rs
  2. 2
      src/build.rs
  3. 2
      src/command.rs
  4. 2
      src/main.rs
  5. 7
      src/manifest.rs
  6. 2
      src/npm.rs
  7. 2
      src/readme.rs
  8. 8
      tests/manifest/main.rs
  9. 1
      tests/manifest/utils.rs

@ -1,8 +1,9 @@
use PBAR;
use console::style; use console::style;
use emoji; use emoji;
use failure::Error; use failure::Error;
use std::fs;
use std::process::Command; use std::process::Command;
use PBAR;
pub fn cargo_install_wasm_bindgen() -> Result<(), Error> { pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
let step = format!( let step = format!(
@ -13,11 +14,15 @@ pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
let pb = PBAR.message(&step); let pb = PBAR.message(&step);
let output = Command::new("cargo") let output = Command::new("cargo")
.arg("install") .arg("install")
.arg("wasm-bindgen") .arg("wasm-bindgen-cli")
.output()?; .output()?;
pb.finish(); pb.finish();
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); let s = String::from_utf8_lossy(&output.stderr);
if s.contains("already exists") {
PBAR.one_off_message("wasm-bindgen already installed");
return Ok(());
}
PBAR.error("Installing wasm-bindgen failed"); PBAR.error("Installing wasm-bindgen failed");
bail!(format!("Details:\n{}", s)); bail!(format!("Details:\n{}", s));
} else { } else {
@ -46,6 +51,9 @@ pub fn wasm_bindgen_build(path: &str, name: &str) -> Result<(), Error> {
PBAR.error("wasm-bindgen failed to execute properly"); PBAR.error("wasm-bindgen failed to execute properly");
bail!(format!("Details:\n{}", s)); bail!(format!("Details:\n{}", s));
} else { } else {
let js_file = format!("{}/pkg/{}.js", path, binary_name);
let index_file = format!("{}/pkg/index.js", path);
fs::rename(&js_file, &index_file)?;
Ok(()) Ok(())
} }
} }

@ -1,8 +1,8 @@
use PBAR;
use console::style; use console::style;
use emoji; use emoji;
use failure::Error; use failure::Error;
use std::process::Command; use std::process::Command;
use PBAR;
pub fn rustup_add_wasm_target() -> Result<(), Error> { pub fn rustup_add_wasm_target() -> Result<(), Error> {
let step = format!( let step = format!(

@ -1,4 +1,3 @@
use PBAR;
use bindgen; use bindgen;
use build; use build;
use console::style; use console::style;
@ -13,6 +12,7 @@ use readme;
use std::fs; use std::fs;
use std::result; use std::result;
use std::time::Instant; use std::time::Instant;
use PBAR;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
pub enum Command { pub enum Command {

@ -5,8 +5,8 @@ extern crate indicatif;
extern crate quicli; extern crate quicli;
use quicli::prelude::*; use quicli::prelude::*;
use wasm_pack::Cli;
use wasm_pack::command::run_wasm_pack; use wasm_pack::command::run_wasm_pack;
use wasm_pack::Cli;
main!(|args: Cli, log_level: verbosity| { main!(|args: Cli, log_level: verbosity| {
run_wasm_pack(args.cmd)?; run_wasm_pack(args.cmd)?;

@ -1,12 +1,12 @@
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use PBAR;
use console::style; use console::style;
use emoji; use emoji;
use failure::Error; use failure::Error;
use serde_json; use serde_json;
use toml; use toml;
use PBAR;
#[derive(Deserialize)] #[derive(Deserialize)]
struct CargoManifest { struct CargoManifest {
@ -32,6 +32,7 @@ struct NpmPackage {
license: Option<String>, license: Option<String>,
repository: Option<Repository>, repository: Option<Repository>,
files: Vec<String>, files: Vec<String>,
main: String,
} }
#[derive(Serialize)] #[derive(Serialize)]
@ -53,7 +54,6 @@ fn read_cargo_toml(path: &str) -> Result<CargoManifest, Error> {
impl CargoManifest { impl CargoManifest {
fn into_npm(mut self, scope: Option<String>) -> NpmPackage { fn into_npm(mut self, scope: Option<String>) -> NpmPackage {
let filename = self.package.name.replace("-", "_"); let filename = self.package.name.replace("-", "_");
let js_file = format!("{}.js", filename);
let wasm_file = format!("{}_bg.wasm", filename); let wasm_file = format!("{}_bg.wasm", filename);
if let Some(s) = scope { if let Some(s) = scope {
self.package.name = format!("@{}/{}", s, self.package.name); self.package.name = format!("@{}/{}", s, self.package.name);
@ -68,7 +68,8 @@ impl CargoManifest {
ty: "git".to_string(), ty: "git".to_string(),
url: repo_url, url: repo_url,
}), }),
files: vec![js_file, wasm_file], files: vec![wasm_file],
main: "index.js".to_string(),
} }
} }
} }

@ -1,6 +1,6 @@
use PBAR;
use failure::Error; use failure::Error;
use std::process::Command; use std::process::Command;
use PBAR;
pub fn npm_pack(path: &str) -> Result<(), Error> { pub fn npm_pack(path: &str) -> Result<(), Error> {
let pkg_file_path = format!("{}/pkg", path); let pkg_file_path = format!("{}/pkg", path);

@ -2,8 +2,8 @@ use console::style;
use failure::Error; use failure::Error;
use std::fs; use std::fs;
use PBAR;
use emoji; use emoji;
use PBAR;
pub fn copy_from_crate(path: &str) -> Result<(), Error> { pub fn copy_from_crate(path: &str) -> Result<(), Error> {
let step = format!( let step = format!(

@ -40,7 +40,8 @@ fn it_creates_a_package_json_default_path() {
pkg.repository.url, pkg.repository.url,
"https://github.com/ashleygwilliams/wasm-pack.git" "https://github.com/ashleygwilliams/wasm-pack.git"
); );
assert_eq!(pkg.files, ["wasm_pack.js", "wasm_pack_bg.wasm"]); assert_eq!(pkg.files, ["wasm_pack_bg.wasm"]);
assert_eq!(pkg.main, "index.js");
} }
#[test] #[test]
@ -53,7 +54,6 @@ fn it_creates_a_package_json_provided_path() {
assert!(utils::read_package_json(&path).is_ok()); assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap(); let pkg = utils::read_package_json(&path).unwrap();
assert_eq!(pkg.name, "js-hello-world"); assert_eq!(pkg.name, "js-hello-world");
assert_eq!(pkg.files, ["js_hello_world.js", "js_hello_world_bg.wasm"]);
} }
#[test] #[test]
@ -66,8 +66,4 @@ fn it_creates_a_package_json_provided_path_with_scope() {
assert!(utils::read_package_json(&path).is_ok()); assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap(); let pkg = utils::read_package_json(&path).unwrap();
assert_eq!(pkg.name, "@test/scopes-hello-world"); assert_eq!(pkg.name, "@test/scopes-hello-world");
assert_eq!(
pkg.files,
["scopes_hello_world.js", "scopes_hello_world_bg.wasm"]
);
} }

@ -12,6 +12,7 @@ pub struct NpmPackage {
pub license: String, pub license: String,
pub repository: Repository, pub repository: Repository,
pub files: Vec<String>, pub files: Vec<String>,
pub main: String,
} }
#[derive(Deserialize)] #[derive(Deserialize)]

Loading…
Cancel
Save