diff --git a/src/dist.rs b/src/dist.rs index 473b77d..f680f83 100644 --- a/src/dist.rs +++ b/src/dist.rs @@ -170,11 +170,11 @@ impl Dist { /// /// This will generate JS bindings via [`wasm-bindgen`](https://docs.rs/wasm-bindgen/latest/wasm_bindgen/) /// and copy files from a given static directory if any to finally return - /// the paths of the generated artifacts with [`DistResult`]. + /// the path of the generated artifacts. /// /// Wasm optimizations can be achieved using [`crate::WasmOpt`] if the /// feature `wasm-opt` is enabled. - pub fn run(self, package_name: &str) -> Result { + pub fn run(self, package_name: &str) -> Result { log::trace!("Getting package's metadata"); let metadata = metadata(); @@ -288,23 +288,13 @@ impl Dist { .generate_output() .context("could not generate Wasm bindgen file")?; - let wasm_js = output.js().to_owned(); - let wasm_bin = output.wasm_mut().emit_wasm(); - - let wasm_js_path = dist_dir_path.join(&app_name).with_extension("js"); - let wasm_bin_path = dist_dir_path.join(&app_name).with_extension("wasm"); - if dist_dir_path.exists() { log::trace!("Removing already existing dist directory"); fs::remove_dir_all(&dist_dir_path)?; } - log::trace!("Creating new dist directory"); - fs::create_dir_all(&dist_dir_path).context("cannot create build directory")?; - - log::trace!("Writing Wasm output into dist directory"); - fs::write(&wasm_js_path, wasm_js).context("cannot write js file")?; - fs::write(&wasm_bin_path, wasm_bin).context("cannot write Wasm file")?; + log::trace!("Writing outputs to dist directory"); + output.emit(&dist_dir_path)?; if let Some(static_dir) = self.static_dir_path { #[cfg(feature = "sass")] @@ -327,11 +317,7 @@ impl Dist { log::info!("Successfully built in {}", dist_dir_path.display()); - Ok(DistResult { - dist_dir: dist_dir_path, - js: wasm_js_path, - wasm: wasm_bin_path, - }) + Ok(dist_dir_path) } } @@ -416,17 +402,6 @@ fn sass( Ok(()) } -/// Provides paths of the generated dist artifacts. -#[derive(Debug)] -pub struct DistResult { - /// Directory containing the generated artifacts. - pub dist_dir: PathBuf, - /// JS output generated by wasm-bindgen. - pub js: PathBuf, - /// Wasm output generated by wasm-bindgen. - pub wasm: PathBuf, -} - /// Get the default dist directory. /// /// The default for debug build is `target/debug/dist` and `target/release/dist`