Skip to content

Commit

Permalink
Add beep option to beep on conversion success/error in auto mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegray committed Nov 9, 2014
1 parent 1886075 commit 2595a77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/leiningen/scss.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,35 @@
exit-code)))

(defn handle-conversion
[build-map file]
[build-map args file]
(if (is-scss-partial? file)
(doall
(pmap (partial handle-conversion build-map) (stylesheets-with-partial build-map file)))
(convert build-map file)))
(pmap (partial handle-conversion build-map args) (stylesheets-with-partial build-map file)))
(let [exit-code (convert build-map file)]
(when (some #{"beep"} args) (beep (if (= exit-code 0) :success :error))))))

(defn handle-change
[build-map {:keys [file count action]}]
[build-map args {:keys [file count action]}]
(try
(lein/debug (color :blue "Detected file change: [file count action]"
file count action))
(when-let [file (and (is-scss? file) file)]
(lein/info (color :bright-yellow "Detected file change:" (.getName file)))
(print-time (handle-conversion build-map file) (str "handle-change:" file)))
(print-time (handle-conversion build-map args file) (str "handle-change:" file)))
(catch Exception e (lein/warn (with-out-str (st/print-stack-trace e 30))))))

(defn watchd
[build-map dir]
[build-map args dir]
(lein/info (color :bright-yellow "Watching directory" dir))
(watch-dir (partial handle-change build-map) (io/file dir)))
(watch-dir (partial handle-change build-map args) (io/file dir)))

(def watchers (atom []))

(defn auto
[project args builds]
(doseq [build builds
:let [build-map (get-build-map project build)]]
(swap! watchers conj (watchd build-map (source-dir build-map))))
(swap! watchers conj (watchd build-map args (source-dir build-map))))
(.addShutdownHook
(Runtime/getRuntime)
(Thread. #(do (println (color :bright-magenta "\nGoodbye!"))
Expand Down
8 changes: 8 additions & 0 deletions src/leiningen/scss/helpers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [clj-time.core :as time]
[clj-time.format :as format]
[clojure.string :as string]
[clojure.java.shell :as shell]
[leiningen.core.main :as lein]))

(def ^:dynamic *boring* false)
Expand Down Expand Up @@ -40,3 +41,10 @@
(defn now
[]
(color :bright-cyan (format/unparse (format/formatter "[HH:mm:ss]") (time/now))))

(defn beep
[& args]
(apply shell/sh (concat ["beep"] (case (first args)
:success ["-f" "1660" "-l" "80"]
:error ["-f" "110" "-l" "200"]
nil))))

0 comments on commit 2595a77

Please sign in to comment.