Skip to content

Instantly share code, notes, and snippets.

@ccfontes
Created August 23, 2014 01:55
Show Gist options
  • Save ccfontes/de00fded09ce69e542ee to your computer and use it in GitHub Desktop.
Save ccfontes/de00fded09ce69e542ee to your computer and use it in GitHub Desktop.
Runs 'lein cljsbuild auto' (non blocking) when there are changes in the cljs files. Accepts other commands as arguments to execute after the daemon is launched. Example: 'script/with/cljs lein run' (script has problems with messages printing to several terminals)
#!/usr/bin/env hy
; Author: <Carlos C. Fontes> [email protected]
(import [sh [touch ls lein sleep]]
[glob [glob]]
sys
[subprocess [call Popen PIPE STDOUT]]
[thread [start_new_thread]])
(defn with-print-call [exe]
(let [[p (apply Popen [exe] {"stdout" PIPE "stderr" STDOUT})]]
(print "p " p)
(print "(.poll p) " (.poll p))
(while true
(sleep 2)
(if-not (.poll p) (continue))
(print p.stdout.readline))))
(defn what-last-modified-file []
(->> "src-cljs/app/*.cljs"
glob
(ls "-t" "resources/public/js/main.js")
.split
first))
(defn cljs-watcher []
(while true
(if (= "cljs" (-> (what-last-modified-file) (.split ".") .pop))
(with-print-call ["lein" "cljsbuild" "auto"])
(sleep 2))
(sys.stdout.flush)))
(start_new_thread cljs-watcher (,))
(-> sys.argv rest call)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment