commit
aced19ce2a
@ -1,21 +1,26 @@
|
|||||||
(ns cryogen-core.watcher
|
(ns cryogen-core.watcher
|
||||||
(:require [clojure.java.io :refer [file]]))
|
(:require [clojure.java.io :refer [file]]
|
||||||
|
[cryogen-core.io :refer [ignore]]))
|
||||||
|
|
||||||
(defn get-assets [root]
|
(defn get-assets [root ignored-files]
|
||||||
(file-seq (file root)))
|
(->> root
|
||||||
|
file
|
||||||
|
file-seq
|
||||||
|
(filter #(not (.isDirectory %)))
|
||||||
|
(filter (ignore ignored-files))))
|
||||||
|
|
||||||
(defn sum-times [path]
|
(defn sum-times [path ignored-files]
|
||||||
(->> (get-assets path) (map #(.lastModified %)) (reduce +)))
|
(->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
|
||||||
|
|
||||||
(defn watch-assets [root action]
|
(defn watch-assets [root ignored-files action]
|
||||||
(loop [times (sum-times root)]
|
(loop [times (sum-times root ignored-files)]
|
||||||
(Thread/sleep 300)
|
(Thread/sleep 300)
|
||||||
(let [new-times (sum-times root)]
|
(let [new-times (sum-times root ignored-files)]
|
||||||
(when-not (= times new-times)
|
(when-not (= times new-times)
|
||||||
(action))
|
(action))
|
||||||
(recur new-times))))
|
(recur new-times))))
|
||||||
|
|
||||||
(defn start-watcher! [root action]
|
(defn start-watcher! [root ignored-files action]
|
||||||
(doto (Thread. #(watch-assets root action))
|
(doto (Thread. #(watch-assets root ignored-files action))
|
||||||
(.setDaemon true)
|
(.setDaemon true)
|
||||||
(.start)))
|
(.start)))
|
||||||
|
Loading…
Reference in New Issue