Added edn2json.

This commit is contained in:
John Wiseman 2020-05-25 15:36:38 -07:00
parent dda25dbdc4
commit 80095ceed3
2 changed files with 44 additions and 1 deletions

View File

@ -17,4 +17,8 @@
{:target :node-test
:output-to "out/node-tests.js"
;;:ns-regexp "-spec$"
:autorun true}}}
:autorun true}
:edn2json
{:target :node-script
:main lemondronor.edn2json/main
:output-to "out/edn2json.js"}}}

View 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))]))