move more functions to infra for better testability

This commit is contained in:
jem 2020-05-14 08:53:49 +02:00
parent 2187df1058
commit af85887931

View file

@ -1,4 +1,7 @@
(ns mastodon-bot.infra)
(ns mastodon-bot.infra
(:require
[cljs.reader :as edn]
["fs" :as fs]))
(defn js->edn [data]
(js->clj data :keywordize-keys true))
@ -6,3 +9,14 @@
(defn exit-with-error [error]
(js/console.error error)
(js/process.exit 1))
(defn find-config []
(let [config (or (first *command-line-args*)
(-> js/process .-env .-MASTODON_BOT_CONFIG)
"config.edn")]
(if (fs/existsSync config)
config
(exit-with-error (str "failed to read config: " config)))))
(defn load-config []
(-> (find-config) (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string))