Add tempfile
and with-tempfile
to CLJS.
We already have a nice library like this for CLJ (tempfile); this builds the same thing for CLJS, using Node.js's tmp.
This commit is contained in:
parent
0a312b4f40
commit
d5cfbeaa45
4 changed files with 33 additions and 1 deletions
|
@ -13,6 +13,7 @@
|
||||||
"ws": "1.1.1"
|
"ws": "1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"tmp": "0.0.28"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -41,7 +41,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
:profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.1"]
|
:profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.1"]
|
||||||
[org.clojure/tools.nrepl "0.2.10"]]
|
[org.clojure/tools.nrepl "0.2.10"]
|
||||||
|
[tempfile "0.2.0"]]
|
||||||
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
|
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
|
||||||
:plugins [[lein-cljsbuild "1.1.2"]
|
:plugins [[lein-cljsbuild "1.1.2"]
|
||||||
[lein-doo "0.1.6"]]
|
[lein-doo "0.1.6"]]
|
||||||
|
|
12
src/datomish/node_tempfile.cljs
Normal file
12
src/datomish/node_tempfile.cljs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
(ns datomish.node-tempfile
|
||||||
|
(:require
|
||||||
|
[cljs.nodejs :as nodejs]))
|
||||||
|
|
||||||
|
(def tmp (nodejs/require "tmp"))
|
||||||
|
|
||||||
|
(defn tempfile []
|
||||||
|
(.fileSync tmp)) ;; Cleaned up on process exit.
|
18
src/datomish/node_tempfile_macros.cljc
Normal file
18
src/datomish/node_tempfile_macros.cljc
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
(ns datomish.node-tempfile-macros)
|
||||||
|
|
||||||
|
(defmacro with-tempfile
|
||||||
|
"Uses a tempfile for some content and delete it immediately"
|
||||||
|
[bindings & body]
|
||||||
|
(cond
|
||||||
|
(= (count bindings) 0) `(do ~@body)
|
||||||
|
(symbol? (bindings 0)) `(let ~(subvec bindings 0 2)
|
||||||
|
(try
|
||||||
|
(with-tempfile ~(subvec bindings 2) ~@body)
|
||||||
|
(finally
|
||||||
|
(.removeCallback ~(bindings 0))))) ;; See Node.js tmp module.
|
||||||
|
:else (throw (java.lang.IllegalArgumentException.
|
||||||
|
"with-tempfile only allows Symbols in bindings"))))
|
Loading…
Reference in a new issue