Use checksums instead of last modified times.
Also add pandect dependency.
This commit is contained in:
parent
6f7cb79a65
commit
4eb0036ef5
2 changed files with 35 additions and 25 deletions
33
project.clj
33
project.clj
|
@ -1,16 +1,17 @@
|
|||
(defproject cryogen-core "0.1.10"
|
||||
:description "Cryogen's compiler"
|
||||
:url "https://github.com/lacarmen/cryogen-core"
|
||||
:license {:name "Eclipse Public License"
|
||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||
[clj-rss "0.1.9"]
|
||||
[me.raynes/fs "1.4.6"]
|
||||
[crouton "0.1.2"]
|
||||
[cheshire "5.4.0"]
|
||||
[clj-text-decoration "0.0.3"]
|
||||
[io.aviso/pretty "0.1.13"]
|
||||
[hiccup "1.0.5"]
|
||||
[selmer "0.7.8"]
|
||||
[markdown-clj "0.9.61"
|
||||
:exclusions [com.keminglabs/cljx]]])
|
||||
(defproject cryogen-core "0.1.11-SNAPSHOT"
|
||||
:description "Cryogen's compiler"
|
||||
:url "https://github.com/lacarmen/cryogen-core"
|
||||
:license {:name "Eclipse Public License"
|
||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||
[clj-rss "0.1.9"]
|
||||
[me.raynes/fs "1.4.6"]
|
||||
[crouton "0.1.2"]
|
||||
[cheshire "5.4.0"]
|
||||
[clj-text-decoration "0.0.3"]
|
||||
[io.aviso/pretty "0.1.13"]
|
||||
[hiccup "1.0.5"]
|
||||
[selmer "0.7.8"]
|
||||
[markdown-clj "0.9.61"
|
||||
:exclusions [com.keminglabs/cljx]]
|
||||
[pandect "0.4.1"]])
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
(ns cryogen-core.watcher
|
||||
(:require [clojure.java.io :refer [file]]
|
||||
[cryogen-core.io :refer [ignore]]))
|
||||
[cryogen-core.io :refer [ignore]]
|
||||
[pandect.core :refer [md5]]
|
||||
[clojure.set :as set]))
|
||||
|
||||
(defn get-assets [root ignored-files]
|
||||
(->> root
|
||||
(defn get-assets [path ignored-files]
|
||||
(->> path
|
||||
file
|
||||
file-seq
|
||||
(filter #(not (.isDirectory %)))
|
||||
(filter (ignore ignored-files))))
|
||||
|
||||
(defn sum-times [path ignored-files]
|
||||
(->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
|
||||
(defn checksums [path ignored-files]
|
||||
(let [files (get-assets path ignored-files)]
|
||||
(zipmap (map md5 files) files)))
|
||||
|
||||
(defn find-changes [old-sums new-sums]
|
||||
(let [old-sum-set (-> old-sums keys set)
|
||||
new-sum-set (-> new-sums keys set)]
|
||||
(when-some [changes (set/difference new-sum-set old-sum-set)]
|
||||
(vals (select-keys new-sums changes)))))
|
||||
|
||||
(defn watch-assets [root ignored-files action]
|
||||
(loop [times (sum-times root ignored-files)]
|
||||
(loop [sums (checksums root ignored-files)]
|
||||
(Thread/sleep 300)
|
||||
(let [new-times (sum-times root ignored-files)]
|
||||
(when-not (= times new-times)
|
||||
(let [new-sums (checksums root ignored-files)]
|
||||
(when (find-changes sums new-sums)
|
||||
(action))
|
||||
(recur new-times))))
|
||||
(recur new-sums))))
|
||||
|
||||
(defn start-watcher! [root ignored-files action]
|
||||
(doto (Thread. #(watch-assets root ignored-files action))
|
||||
|
|
Loading…
Reference in a new issue