Skip to content

Instantly share code, notes, and snippets.

@vise890
Last active January 25, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vise890/15e8b1b69ea00605dea4 to your computer and use it in GitHub Desktop.
Save vise890/15e8b1b69ea00605dea4 to your computer and use it in GitHub Desktop.
shebang support for clojurescript
;; pseudocode
(ns bolt.core
(:require ,,,))
(def BIN_PATH "~/.bolt/bin")
(declare
hash-file
cljs->js
compile
nodejs-run)
(defn run
"runs the .cljs file at path"
[path]
(let [hash (hash-file path)
cache (fs/file BIN_PATH hash ".js")]
(if (fs/exists? cache)
(nodejs-run cache)
(do (compile-to path cache)
(nodejs-run cache)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn hash-file
"returns the hash of the contents of the file at path"
[path]
(digests/sha1 (slurp path)))
(defn cljs->js [string]
;; aware of dependencies
;; similar to boot's (set-env! :dependencies '[[alandipert/hyperturbo "1.0.0"]])
;; in files with #!/usr/bin/env boot
,,,)
(defn compile [src dest]
(let [src (slurp src)
compiled (cljs->js src)]
(spit cache compiled)))
(defn nodejs-run [file]
(os/exec (str "node " (fs/absolute-path file)))
#!/usr/bin/env bolt
;; sample script
(set-env! :dependencies '[[clj-http "2.0.1"]
[prismatic/dommy "1.1.0"]])
(ns temperatueriv
(:require-macros [cljs.core.async.macros :refer [go]]
[dommy.core :refer [sel1]])
(:require [cljs-http.client :as http]
[cljs.core.async :refer [<!]]))))
(println "==> fetching temperature for Bristol")
(go (let [resp (<! (http/get "http://www.bbc.co.uk/weather/2654675"))
body (:body resp)
temp (.text (sel1 "span.units-value.temperature-value.temperature-value-unit-c"))]
(println (str temp "C (i.e., the correct units :P)"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment