Skip to content

Commit

Permalink
pre-build before wasm-pack publish
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Nov 11, 2018
1 parent 91e3293 commit 950d679
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl FromStr for BuildMode {
}

/// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, StructOpt)]
#[derive(Debug, Default, StructOpt)]
pub struct BuildOptions {
/// The path to the Rust crate.
#[structopt(parse(from_os_str))]
Expand Down
27 changes: 20 additions & 7 deletions src/command/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub mod access;

use self::access::Access;
use command::build::{Build, BuildOptions};
use command::utils::{find_pkg_directory, set_crate_path};
use failure::Error;
use npm;
Expand All @@ -21,14 +22,26 @@ pub fn publish(

info!(&log, "Publishing the npm package...");
info!(&log, "npm info located in the npm debug log");
let pkg_directory = find_pkg_directory(&crate_path).ok_or_else(|| {
format_err!(
"Unable to find the pkg directory at path '{:#?}', or in a child directory of '{:#?}'",
&crate_path,
&crate_path
)
})?;

let pkg_directory = match find_pkg_directory(&crate_path) {
Some(path) => Ok(path),
None => {
// while `wasm-pack publish`, if the pkg directory cannot be found,
// then try to `wasm-pack build`
let build_opts = BuildOptions::default();
Build::try_from_opts(build_opts)
.and_then(|mut build| build.run(&log))
.map(|()| PathBuf::from("."))
.map_err(|_| {
format_err!(
"Unable to find the pkg directory at path '{:#?}',\
or in a child directory of '{:#?}'",
&crate_path,
&crate_path
)
})
}
}?;
npm::npm_publish(log, &pkg_directory.to_string_lossy(), access)?;
info!(&log, "Published your package!");

Expand Down

0 comments on commit 950d679

Please sign in to comment.