Skip to content

Commit

Permalink
fix: reload should ignore some folders including assets
Browse files Browse the repository at this point in the history
Resolved logseq#1521
  • Loading branch information
tiensonqin committed Mar 27, 2021
1 parent 920d8f9 commit a371c73
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}))]
Expand Down

0 comments on commit a371c73

Please sign in to comment.