cryogen-core/src/cryogen_core/watcher.clj

27 lines
790 B
Clojure
Raw Normal View History

2014-12-05 15:56:40 +00:00
(ns cryogen-core.watcher
(:require [clojure.java.io :refer [file]]
[cryogen-core.io :refer [ignore]]))
2014-12-04 16:38:48 +00:00
(defn get-assets [root ignored-files]
(->> root
file
file-seq
(filter #(not (.isDirectory %)))
(filter (ignore ignored-files))))
2014-12-04 16:38:48 +00:00
(defn sum-times [path ignored-files]
(->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
2014-12-04 16:38:48 +00:00
(defn watch-assets [root ignored-files action]
(loop [times (sum-times root ignored-files)]
2014-12-04 16:38:48 +00:00
(Thread/sleep 300)
(let [new-times (sum-times root ignored-files)]
2014-12-04 16:38:48 +00:00
(when-not (= times new-times)
(action))
(recur new-times))))
(defn start-watcher! [root ignored-files action]
(doto (Thread. #(watch-assets root ignored-files action))
2014-12-04 16:38:48 +00:00
(.setDaemon true)
(.start)))