This repository has been archived on 2023-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-bot/src/main/mastodon_bot/infra.cljs

25 lines
No EOL
651 B
Clojure
Executable file

(ns mastodon-bot.infra
(:require
[cljs.reader :as edn]
["fs" :as fs]))
(defn js->edn [data]
(js->clj data :keywordize-keys true))
(defn exit-with-error [error]
(js/console.error error)
(js/process.exit 1))
(defn find-config [config-location]
(let [config (or config-location
(-> 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 [config-location]
(-> config-location
(find-config)
(fs/readFileSync #js {:encoding "UTF-8"})
edn/read-string))