pre-build before wasm-pack publish

master
csmoe 7 years ago
parent 8ed6e3dfaf
commit d5a7a7beb1
  1. 19
      src/command/build.rs
  2. 24
      src/command/publish/mod.rs

@ -102,12 +102,12 @@ 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 = "release")]
/// Create a release build. Enable optimizations and disable debug info.
@ -122,6 +122,21 @@ pub struct BuildOptions {
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 {

@ -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;
@ -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(|| {
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 '{:#?}'",
"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!");

Loading…
Cancel
Save