diff --git a/src/main/mastodon_bot/infra.cljs b/src/main/mastodon_bot/infra.cljs index f730e1e..f2f242f 100755 --- a/src/main/mastodon_bot/infra.cljs +++ b/src/main/mastodon_bot/infra.cljs @@ -20,15 +20,25 @@ (js/process.exit 1)) (defn find-config [config-location] - (let [config (or config-location - (-> js/process .-env .-MASTODON_BOT_CONFIG) - "config.edn")] + (or config-location + (-> js/process .-env .-MASTODON_BOT_CONFIG) + "config.edn")) + +(defn read-edn [config] + (if config (if (fs/existsSync config) - config - (exit-with-error (str "failed to read config: " config))))) + ;(edn/read-string (fs/readFileSync #js {:encoding "UTF-8"} config)) + (edn/read-string (fs/readFileSync config "UTF-8")) + (exit-with-error (str "config file does not exist: " config))) + nil)) -(defn load-config [config-location] +(defn load-credentials-config [] + (read-edn (-> js/process .-env .-MASTODON_BOT_CREDENTIALS))) + +(defn load-main-config [config-location] (-> config-location (find-config) - (fs/readFileSync #js {:encoding "UTF-8"}) - edn/read-string)) \ No newline at end of file + (read-edn))) + +(defn load-config [config-location] + (merge (load-main-config config-location) (load-credentials-config)))