Procházet zdrojové kódy

feat: commit console log

YuKun Liu před 3 roky
rodič
revize
61c06ea598
5 změnil soubory, kde provedl 26 přidání a 22 odebrání
  1. 5 1
      src/builder.rs
  2. 1 1
      src/cli/build/mod.rs
  3. 1 1
      src/cli/serve/mod.rs
  4. 1 1
      src/server/hot_reload.rs
  5. 18 18
      src/server/mod.rs

+ 5 - 1
src/builder.rs

@@ -13,7 +13,7 @@ use std::{
 };
 use wasm_bindgen_cli_support::Bindgen;
 
-pub fn build(config: &CrateConfig) -> Result<()> {
+pub fn build(config: &CrateConfig, quiet: bool) -> Result<()> {
     // [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?)
     // [2] Generate the appropriate build folders
     // [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm
@@ -52,6 +52,10 @@ pub fn build(config: &CrateConfig) -> Result<()> {
         cmd.arg("--verbose");
     }
 
+    if quiet {
+        cmd.arg("--quiet");
+    }
+
     if config.custom_profile.is_some() {
         let custom_profile = config.custom_profile.as_ref().unwrap();
         cmd.arg("--profile");

+ 1 - 1
src/cli/build/mod.rs

@@ -34,7 +34,7 @@ impl Build {
 
         match platform.as_str() {
             "web" => {
-                crate::builder::build(&crate_config)?;
+                crate::builder::build(&crate_config, false)?;
             }
             "desktop" => {
                 crate::builder::build_desktop(&crate_config, false)?;

+ 1 - 1
src/cli/serve/mod.rs

@@ -40,7 +40,7 @@ impl Serve {
 
         match platform.as_str() {
             "web" => {
-                crate::builder::build(&crate_config)?;
+                crate::builder::build(&crate_config, false)?;
             }
             "desktop" => {
                 crate::builder::build_desktop(&crate_config, true)?;

+ 1 - 1
src/server/hot_reload.rs

@@ -154,7 +154,7 @@ pub async fn hot_reload_handler(
                                         log::error!("parse error:\n--> at {}:{}:{}\n\t{:?}", parse_error.location.file_path, parse_error.location.line, parse_error.location.column, parse_error.message);
                                     },
                                     Error::RecompileRequiredError(_) => {
-                                        if let Err(err) = state.build_manager.build(){
+                                        if let Err(err) = state.build_manager.rebuild(){
                                             log::error!("{}", err);
                                         }
                                     }

+ 18 - 18
src/server/mod.rs

@@ -27,9 +27,9 @@ pub struct BuildManager {
 }
 
 impl BuildManager {
-    fn build(&self) -> Result<()> {
-        log::info!("🪁 Rebuild code");
-        builder::build(&self.config)?;
+    fn rebuild(&self) -> Result<()> {
+        log::info!("🪁 Rebuild project");
+        builder::build(&self.config, true)?;
         // change the websocket reload state to true;
         // the page will auto-reload.
         if self
@@ -158,7 +158,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
                 }
                 if needs_rebuild {
                     log::info!("reload required");
-                    if let Err(err) = build_manager.build() {
+                    if let Err(err) = build_manager.rebuild() {
                         log::error!("{}", err);
                     }
                 }
@@ -274,7 +274,7 @@ pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
         if info.is_ok() {
             let info = info.unwrap();
             if chrono::Local::now().timestamp() > last_update_time {
-                match build_manager.build() {
+                match build_manager.rebuild() {
                     Ok(_) => {
                         last_update_time = chrono::Local::now().timestamp();
                         print_rebuild_info(info.paths);
@@ -433,19 +433,19 @@ fn print_console_info(port: u16, config: &CrateConfig) {
 }
 
 fn print_rebuild_info(paths: Vec<PathBuf>) {
-    print!(
-        "{}",
-        String::from_utf8_lossy(
-            &Command::new(if cfg!(target_os = "windows") {
-                "cls"
-            } else {
-                "clear"
-            })
-            .output()
-            .unwrap()
-            .stdout
-        )
-    );
+    // print!(
+    //     "{}",
+    //     String::from_utf8_lossy(
+    //         &Command::new(if cfg!(target_os = "windows") {
+    //             "cls"
+    //         } else {
+    //             "clear"
+    //         })
+    //         .output()
+    //         .unwrap()
+    //         .stdout
+    //     )
+    // );
 
     for path in paths {
         let path = path.strip_prefix(crate::crate_root().unwrap()).unwrap().to_path_buf();