瀏覽代碼

intigrate with .gitignore

Evan Almloff 2 年之前
父節點
當前提交
d642e53a2b
共有 2 個文件被更改,包括 13 次插入2 次删除
  1. 2 1
      packages/hot-reload/Cargo.toml
  2. 11 1
      packages/hot-reload/src/lib.rs

+ 2 - 1
packages/hot-reload/Cargo.toml

@@ -16,4 +16,5 @@ chrono = "0.4.23"
 serde_json = "1.0.91"
 serde = { version = "1", features = ["derive"] }
 execute = "0.2.11"
-once_cell = "1.17.0"
+once_cell = "1.17.0"
+gitignore = "1.0.7"

+ 11 - 1
packages/hot-reload/src/lib.rs

@@ -157,6 +157,10 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
 
             // watch for changes
             std::thread::spawn(move || {
+                // try to find the gitingore file
+                let gitignore_file_path = crate_dir.join(".gitignore");
+                let gitignore_file = gitignore::File::new(&gitignore_file_path.as_path());
+
                 let mut last_update_time = chrono::Local::now().timestamp();
 
                 let (tx, rx) = std::sync::mpsc::channel();
@@ -210,7 +214,13 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
                                     // skip non rust files
                                     matches!(path.extension().and_then(|p| p.to_str()), Some("rs" | "toml" | "css" | "html" | "js")) &&
                                     // skip excluded paths
-                                    !excluded_paths.iter().any(|p| path.starts_with(p))
+                                    !excluded_paths.iter().any(|p| path.starts_with(p)) && match &gitignore_file{
+                                        Ok(file) => match file.is_excluded(path){
+                                            Ok(excluded) => !excluded,
+                                            Err(_) => true,
+                                        },
+                                        Err(_) => true,
+                                    }
                                 })
                                 .collect::<Vec<_>>();