feat: commit code

This commit is contained in:
YuKun Liu committed 2022-07-06 22:44:50 +08:00
1 parent 14a2ec306e
commit 3551d1b6a0
1 file changed
+4 -2
+4 -2
View File
@@ -94,14 +94,16 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
.clone() .clone()
.unwrap_or_else(|| vec![PathBuf::from("src")]); .unwrap_or_else(|| vec![PathBuf::from("src")]);
let watcher_config = config.clone();
let mut watcher = RecommendedWatcher::new(move |evt: notify::Result<notify::Event>| { let mut watcher = RecommendedWatcher::new(move |evt: notify::Result<notify::Event>| {
let config = watcher_config.clone();
if chrono::Local::now().timestamp() > last_update_time { if chrono::Local::now().timestamp() > last_update_time {
// Give time for the change to take effect before reading the file // Give time for the change to take effect before reading the file
std::thread::sleep(std::time::Duration::from_millis(100)); std::thread::sleep(std::time::Duration::from_millis(100));
if let Ok(evt) = evt { if let Ok(evt) = evt {
let mut messages = Vec::new(); let mut messages = Vec::new();
let mut needs_rebuild = false; let mut needs_rebuild = false;
for path in evt.paths { for path in evt.paths.clone() {
let mut file = File::open(path.clone()).unwrap(); let mut file = File::open(path.clone()).unwrap();
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") { if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
continue; continue;
@@ -157,7 +159,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
} }
} }
if needs_rebuild { if needs_rebuild {
log::info!("reload required"); print_console_info(port, &config, evt.paths);
if let Err(err) = build_manager.rebuild() { if let Err(err) = build_manager.rebuild() {
log::error!("{}", err); log::error!("{}", err);
} }