-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Currently, beholder can only handle directories, not files (i.e. it inherits gmethvin/directory-watcher#95). It would be nice to work around this upstream. Here is some code I use in my own project—maybe this fits into the API?
(require [babashka.fs :as fs])
(defn on-file-change
[cb paths event]
; behold doesn't support file filters, only directory filters. implement them ourselves.
(when (contains? paths (-> event :path))
(cb event)))
(defn to-dir [path]
(let [dir (if (fs/directory? path) path (fs/parent path))]
(-> dir fs/real-path str)))
(defn watch-files
[cb paths]
(let [abs-paths (set (map fs/real-path paths))
dirs (set (map to-dir abs-paths))]
(apply behold/watch #(on-file-change cb abs-paths %) dirs)))Metadata
Metadata
Assignees
Labels
No labels