File tree Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Original file line number Diff line number Diff line change 41
41
42
42
(def verbose? (some #{" -v" " --verbose" } *command-line-args*))
43
43
44
- (defn debug [& args] (when verbose? (apply println " [DEBUG]" args)))
45
- (defn info [& args] (apply println " [INFO]" args))
46
- (defn warn [& args] (apply println " [WARN]" args))
47
- (defn error [& args] (apply println " [ERROR]" args))
44
+ (defn debug [& args] (when verbose? (apply println ( java.util.Date. ) " [DEBUG]" args)))
45
+ (defn info [& args] (apply println ( java.util.Date. ) " [INFO]" args))
46
+ (defn warn [& args] (apply println ( java.util.Date. ) " [WARN]" args))
47
+ (defn error [& args] (apply println ( java.util.Date. ) " [ERROR]" args))
48
48
49
49
(defn shellquote [a]
50
50
(cond
Original file line number Diff line number Diff line change 12
12
java.nio.file.Files
13
13
java.nio.file.Paths
14
14
java.nio.file.Path
15
- java.io.File))
15
+ java.io.File
16
+ io.methvin.watcher.DirectoryWatcher))
16
17
17
18
(defonce watchers (atom nil ))
18
19
24
25
25
26
(require 'clojure.pprint)
26
27
28
+ (defn build-watcher
29
+ " Creates a watcher taking a callback function `cb` that will be invoked
30
+ whenever a file in one of the `paths` chages.
31
+
32
+ Not meant to be called directly but use `watch` or `watch-blocking` instead."
33
+ [cb paths]
34
+ (-> (DirectoryWatcher/builder )
35
+ (.paths (map #(Path/of % (into-array String [])) paths))
36
+ (.listener (#'beholder/fn->listener cb))
37
+ #_(.fileHashing false )
38
+ (.build )))
39
+
40
+ (defn watch
41
+ " Creates a directory watcher that will invoke the callback function `cb` whenever
42
+ a file event in one of the `paths` occurs. Watching will happen asynchronously.
43
+
44
+ Returns a directory watcher that can be passed to `stop` to stop the watch."
45
+ [cb & paths]
46
+ (doto (build-watcher cb paths)
47
+ (.watchAsync )))
48
+
27
49
(defn watch!
28
50
" Watch a number of files, takes a map from filename (string) to
29
51
handler (receives a map with `:type` and `:path`, as with Beholder)."
41
63
(run! beholder/stop w))
42
64
(doall
43
65
(for [dir directories]
44
- (beholder/watch
45
- (fn [{:keys [type path] :as event}]
46
- (if-let [f (get file->handler (str path))]
47
- (try
48
- (f event)
49
- (catch Exception e
50
- (prn e)))))
51
- (str dir))))))))
66
+ (do
67
+ (print dir " " )
68
+ (time
69
+ (watch
70
+ (fn [{:keys [type path] :as event}]
71
+ (if-let [f (get file->handler (str path))]
72
+ (try
73
+ (f event)
74
+ (catch Exception e
75
+ (prn e)))))
76
+ (str dir))))))))))
52
77
53
78
(comment
54
79
(watch!
You can’t perform that action at this time.
0 commit comments