Last active
January 25, 2016 20:27
-
-
Save vise890/15e8b1b69ea00605dea4 to your computer and use it in GitHub Desktop.
shebang support for clojurescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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