From a371c73a0b00aec232eecd0f88e8602688d68e89 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sat, 27 Mar 2021 09:20:10 +0800 Subject: [PATCH] fix: reload should ignore some folders including assets Resolved #1521 --- src/electron/electron/handler.cljs | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/electron/electron/handler.cljs b/src/electron/electron/handler.cljs index e4f2bfa301..30ba959a91 100644 --- a/src/electron/electron/handler.cljs +++ b/src/electron/electron/handler.cljs @@ -55,17 +55,27 @@ (string/replace path "\\" "/") path))) +;; TODO: ignore according to mime types +(defn ignored-path? + [dir path] + (or + (some #(string/starts-with? path (str dir "/" %)) + ["." "assets" "node_modules"]) + (some #(string/ends-with? path (str dir "/" %)) + [".swap" ".crswap" ".tmp"]))) + (defn- get-files [path] - (let [result (->> (map - (fn [path] - (let [stat (fs/statSync path)] - (when-not (.isDirectory stat) - {:path (fix-win-path! path) - :content (read-file path) - :stat stat}))) - (readdir path)) - (remove nil?))] + (let [result (->> + (readdir path) + (remove (partial ignored-path? path)) + (map (fn [path] + (let [stat (fs/statSync path)] + (when-not (.isDirectory stat) + {:path (fix-win-path! path) + :content (read-file path) + :stat stat})))) + (remove nil?))] (vec (cons {:path (fix-win-path! path)} result)))) ;; TODO: Is it going to be slow if it's a huge directory @@ -100,12 +110,7 @@ (when (fs/existsSync dir) (let [watcher (.watch watcher dir (clj->js - {:ignored (fn [path] - (or - (some #(string/starts-with? path (str dir "/" %)) - ["." "assets" "node_modules"]) - (some #(string/ends-with? path (str dir "/" %)) - [".swap" ".crswap" ".tmp"]))) + {:ignored (partial ignored-path? dir) :ignoreInitial false :persistent true :awaitWriteFinish true}))]