Added edn2json.
This commit is contained in:
parent
dda25dbdc4
commit
80095ceed3
@ -17,4 +17,8 @@
|
|||||||
{:target :node-test
|
{:target :node-test
|
||||||
:output-to "out/node-tests.js"
|
:output-to "out/node-tests.js"
|
||||||
;;:ns-regexp "-spec$"
|
;;:ns-regexp "-spec$"
|
||||||
:autorun true}}}
|
:autorun true}
|
||||||
|
:edn2json
|
||||||
|
{:target :node-script
|
||||||
|
:main lemondronor.edn2json/main
|
||||||
|
:output-to "out/edn2json.js"}}}
|
||||||
|
39
src/main/lemondronor/edn2json.cljs
Normal file
39
src/main/lemondronor/edn2json.cljs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
(ns lemondronor.edn2json
|
||||||
|
(:require
|
||||||
|
["fs" :as fs]
|
||||||
|
[kitchen-async.promise :as p]
|
||||||
|
[cljs.reader :as reader]
|
||||||
|
[fipp.edn :as fippedn]))
|
||||||
|
|
||||||
|
(def fs-promises (.-promises fs))
|
||||||
|
|
||||||
|
|
||||||
|
(defn read-file [path options]
|
||||||
|
(.readFile fs-promises path (clj->js options)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn write-file [path data options]
|
||||||
|
(.writeFile fs-promises path data (clj->js options)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn read-file-json [path]
|
||||||
|
(p/let [json-str (read-file path {:encoding "utf-8"})
|
||||||
|
db (js->clj (.parse js/JSON json-str))]
|
||||||
|
db))
|
||||||
|
|
||||||
|
(defn write-file-json [db path]
|
||||||
|
(write-file path (.stringify js/JSON (clj->js db) nil " ") {:encoding "utf-8"}))
|
||||||
|
|
||||||
|
(defn read-file-edn [path]
|
||||||
|
(p/let [edn-str (read-file path {:encoding "utf-8"})
|
||||||
|
db (reader/read-string edn-str)]
|
||||||
|
db))
|
||||||
|
|
||||||
|
|
||||||
|
(defn now []
|
||||||
|
(.getTime (js/Date.)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn main [& args]
|
||||||
|
(p/let [db (read-file-edn (nth args 0))
|
||||||
|
done (write-file-json db (nth args 1))]))
|
Loading…
Reference in New Issue
Block a user