-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommon.cljs
49 lines (40 loc) · 1.22 KB
/
common.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns common
(:require ["keyv$default" :as Keyv]
["path" :refer [basename]]))
(defn env [k & [default]]
(or (aget js/process.env k) default))
(def database-url (env "DATABASE" "sqlite://./database.sqlite"))
(defn kv [kv-ns]
(Keyv. database-url (clj->js {:namespace kv-ns})))
(defn client []
(->
(Keyv. database-url)
(aget "opts" "store")))
(defmacro plet
[bindings & body]
(let [binding-pairs (reverse (partition 2 bindings))
body (cons 'do body)]
(reduce (fn [body [sym expr]]
(let [expr (list '.resolve 'js/Promise expr)]
(list '.then expr (list 'clojure.core/fn (vector sym)
body))))
body
binding-pairs)))
(defn get-pin-image [pin]
(try
(let [embed (aget pin "embed")]
(if embed
(aget embed "src")
(-> (aget pin "images" "564x" "url") (.replace "564x" "originals"))))
(catch :default e)))
(defn now []
(-> (js/Date.)
(.toISOString)
(.split ".")
first
(.replace "T" " ")))
(defn log [file-path & args]
(apply print (conj (conj args (str (basename file-path) ":")) (now))))
(defn bail [msg]
(js/console.error msg)
(js/process.exit 1))