diff --git a/src/main/mastodon_bot/infra.cljs b/src/main/mastodon_bot/infra.cljs index c8ec4b6..a2f1bcf 100755 --- a/src/main/mastodon_bot/infra.cljs +++ b/src/main/mastodon_bot/infra.cljs @@ -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)) \ No newline at end of file