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 b88a097
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
19 changes: 17 additions & 2 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,33 @@ pub struct BuildOptions {

#[structopt(long = "debug")]
/// Deprecated. Renamed to `--dev`.
debug: bool,
pub debug: bool,

#[structopt(long = "dev")]
/// Create a development build. Enable debug info, and disable
/// optimizations.
dev: bool,
pub dev: bool,

#[structopt(long = "out-dir", short = "d", default_value = "pkg")]
/// Sets the output directory with a relative path.
pub out_dir: String,
}

impl Default for BuildOptions {
fn default() -> Self {
Self {
path: None,
scope: None,
mode: BuildMode::Normal,
disable_dts: false,
target: String::from("browser"),
debug: false,
dev: false,
out_dir: String::from("pkg"),
}
}
}

type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>;

impl Build {
Expand Down
30 changes: 23 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,29 @@ 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 {
path: Some(crate_path.clone()),
..Default::default()
};
Build::try_from_opts(build_opts)
.and_then(|mut build| build.run(&log))
.map(|()| crate_path.join("pkg"))
.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 b88a097

Please sign in to comment.