diff --git a/src/builder.rs b/src/builder.rs index 89451e163..101d31ee5 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -3,7 +3,7 @@ use crate::{ error::{Error, Result}, }; use std::{ - io::{Read, Write}, + io::Write, process::Command, }; use wasm_bindgen_cli_support::Bindgen; @@ -29,14 +29,15 @@ pub fn build(config: &CrateConfig) -> Result<()> { let t_start = std::time::Instant::now(); // [1] Build the .wasm module - log::info!("Running build commands..."); + log::info!("🚅 Running build commands..."); let mut cmd = Command::new("cargo"); cmd.current_dir(&crate_dir) .arg("build") .arg("--target") .arg("wasm32-unknown-unknown") - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()); + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()) + ; if config.release { cmd.arg("--release"); @@ -48,16 +49,13 @@ pub fn build(config: &CrateConfig) -> Result<()> { ExecutableType::Example(name) => cmd.arg("--example").arg(name), }; - let mut child = cmd.spawn()?; + let output = cmd.output()?; - let output = child.wait()?; - - if output.success() { - log::info!("Build complete!"); + if output.status.success() { + std::io::stdout().write_all(&output.stdout).unwrap(); } else { log::error!("Build failed!"); - let mut reason = String::new(); - child.stderr.unwrap().read_to_string(&mut reason)?; + let reason = String::from_utf8_lossy(&output.stderr).to_string(); return Err(Error::BuildFailed(reason)); } @@ -98,8 +96,8 @@ pub fn build(config: &CrateConfig) -> Result<()> { // [5] Generate the html file with the module name // TODO: support names via options - log::info!("Writing to '{:#?}' directory...", out_dir); + // log::info!("Writing to '{:#?}' directory...", out_dir); let copy_options = fs_extra::dir::CopyOptions::new(); if static_dir.is_dir() { match fs_extra::dir::copy(static_dir, out_dir, ©_options) { @@ -111,7 +109,7 @@ pub fn build(config: &CrateConfig) -> Result<()> { } let t_end = std::time::Instant::now(); - log::info!("Done in {}ms! 🎉", (t_end - t_start).as_millis()); + log::info!("🏁 Done in {}ms!", (t_end - t_start).as_millis()); Ok(()) } diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index 58d797485..fc329a305 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -1,6 +1,4 @@ use crate::cfg::ConfigOptsBuild; -use anyhow::Result; -use std::path::PathBuf; use structopt::StructOpt; /// Build the Rust WASM app and all of its assets. @@ -18,7 +16,7 @@ impl Build { // change the relase state. crate_config.with_release(self.build.release); - crate::builder::build(&crate_config); + crate::builder::build(&crate_config)?; Ok(()) } diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index 5736ebc19..2c5f42a26 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -1,11 +1,8 @@ -use anyhow::Result; use std::path::PathBuf; use structopt::StructOpt; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use std::collections::HashMap; -use std::str::FromStr; -use std::sync::Arc; /// Config options for the build system. #[derive(Clone, Debug, Default, Deserialize, StructOpt)] diff --git a/src/cli/clean/mod.rs b/src/cli/clean/mod.rs index aeeedf523..1edcd053a 100644 --- a/src/cli/clean/mod.rs +++ b/src/cli/clean/mod.rs @@ -1,6 +1,3 @@ -use crate::cfg::ConfigOptsBuild; -use anyhow::Result; -use std::path::PathBuf; use structopt::StructOpt; /// Build the Rust WASM app and all of its assets. diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 32492459a..a739f9a01 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,5 +1,3 @@ -use anyhow::{Context, Result}; -use std::path::PathBuf; use structopt::StructOpt; pub mod build; diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index 36c050bd3..f2ac2b69f 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -1,6 +1,4 @@ use crate::{cfg::ConfigOptsServe, server}; -use anyhow::Result; -use std::path::PathBuf; use std::io::Write; use structopt::StructOpt; diff --git a/src/cli/translate/to_component.rs b/src/cli/translate/to_component.rs index b08161e9c..d64854d37 100644 --- a/src/cli/translate/to_component.rs +++ b/src/cli/translate/to_component.rs @@ -20,6 +20,7 @@ pub fn convert_html_to_component(html: &str) -> Result { }) } +#[allow(dead_code)] pub struct ComponentRenderer { dom: Dom, icon_index: usize, diff --git a/src/config.rs b/src/config.rs index 47920c583..d17294b18 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,5 @@ use crate::error::Result; -use std::{io::Write, path::PathBuf, process::Command}; +use std::path::PathBuf; #[derive(Debug, Clone)] pub struct CrateConfig { diff --git a/src/main.rs b/src/main.rs index a58794783..41fa5835b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,11 +8,11 @@ async fn main() -> Result<()> { match args.action { Commands::Translate(opts) => { - opts.translate(); + opts.translate()?; } Commands::Build(opts) => { - opts.build(); + opts.build()?; } // Commands::Clean(_) => { @@ -23,7 +23,7 @@ async fn main() -> Result<()> { // // // } Commands::Serve(opts) => { - opts.serve().await; + opts.serve().await?; } } diff --git a/src/server/mod.rs b/src/server/mod.rs index 2e937dbb8..6c6c08c1f 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,6 +1,6 @@ use axum::{ extract::{ - ws::{Message, WebSocket}, + ws::Message, Extension, TypedHeader, WebSocketUpgrade, }, http::StatusCode, @@ -19,11 +19,11 @@ struct WsRelodState { update: bool, } -impl WsRelodState { fn change(&mut self) { self.update = !self.update } } +impl WsRelodState { fn change(&mut self) { self.update = !self.update; } } pub async fn startup(config: CrateConfig) -> anyhow::Result<()> { - log::info!("Starting development server 🚀"); + log::info!("🚀 Starting development server..."); let (tx, rx) = channel(); @@ -40,8 +40,9 @@ pub async fn startup(config: CrateConfig) -> anyhow::Result<()> { match v { DebouncedEvent::Create(_) | DebouncedEvent::Write(_) | DebouncedEvent::Remove(_) | DebouncedEvent::Rename(_, _) => { - builder::build(&watcher_conf).unwrap(); - watcher_ws_state.lock().unwrap().change(); + if let Ok(_) = builder::build(&watcher_conf) { + watcher_ws_state.lock().unwrap().change(); + } }, _ => {} } diff --git a/src/server/serve.html b/src/server/serve.html index 98997403b..b5268bd68 100644 --- a/src/server/serve.html +++ b/src/server/serve.html @@ -14,15 +14,26 @@