From 2eff7fa0c9bb4afd4c424cdb077d9dc39fd8002c Mon Sep 17 00:00:00 2001 From: liquidz Date: Mon, 5 Feb 2024 22:54:49 +0900 Subject: [PATCH] chore: Tweak codes --- .elin.edn | 5 ++++- bb.edn | 2 +- dev/elin/dev.clj | 13 ++++++------- src/elin/config.clj | 3 +++ src/elin/core.clj | 16 ++-------------- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.elin.edn b/.elin.edn index 2daba2f4..417d4da0 100644 --- a/.elin.edn +++ b/.elin.edn @@ -1 +1,4 @@ -{:log {:level :debug}} +{:log {:level :debug} + :interceptor {:includes [elin.interceptor.debug/interceptor-context-checking-interceptor + elin.interceptor.debug/nrepl-debug-interceptor]} + :env {:cwd "."}} diff --git a/bb.edn b/bb.edn index 2ee4c1c3..0108ff9c 100644 --- a/bb.edn +++ b/bb.edn @@ -9,7 +9,7 @@ rewrite-clj/rewrite-clj {:mvn/version "1.1.47"}} :tasks - {start-server {:task (shell "bb -m elin.core localhost 12233 .")} + {start-server {:task (shell "bb -m elin.core '{\"server\": {\"host\": \"localhost\", \"port\": 12233}, \"env\": {\"cwd\": \".\"}}'")} repl {:override-builtin true :extra-paths ["dev" "test"] :requires ([elin.dev] diff --git a/dev/elin/dev.clj b/dev/elin/dev.clj index 85ffde02..1013bc56 100644 --- a/dev/elin/dev.clj +++ b/dev/elin/dev.clj @@ -3,6 +3,8 @@ [clojure.edn :as edn] [clojure.java.io :as io] [com.stuartsierra.component :as component] + [elin.config :as e.config] + [medley.core :as medley] [elin.constant.interceptor :as e.c.interceptor] [elin.log :as e.log] [elin.system :as e.system] @@ -17,13 +19,10 @@ ctx)}) (def config - (let [f (io/file "dev" "elin" "config.edn")] - (merge {:server {:host "nvim" - :port 12233} - :interceptor {:interceptors [store-last-message-interceptor]}} - (if (.exists f) - (edn/read-string (slurp f)) - {})))) + (medley/deep-merge + {:server {:host "nvim" + :port 12233}} + (e.config/load-config "."))) (def system-map (e.system/new-system config)) diff --git a/src/elin/config.clj b/src/elin/config.clj index 2c1aae51..e5719b2c 100644 --- a/src/elin/config.clj +++ b/src/elin/config.clj @@ -14,6 +14,9 @@ (mt/transformer mt/default-value-transformer)) +(m/=> load-config [:function + [:=> [:cat string?] e.s.config/?Config] + [:=> [:cat string? map?] e.s.config/?Config]]) (defn load-config ([dir] (load-config dir {})) diff --git a/src/elin/core.clj b/src/elin/core.clj index d303990a..5cf611e9 100644 --- a/src/elin/core.clj +++ b/src/elin/core.clj @@ -4,23 +4,11 @@ [com.stuartsierra.component :as component] [elin.config :as e.config] [elin.log :as e.log] - [elin.schema.config :as e.s.config] - [elin.system :as e.system] - [malli.core :as m] - [malli.error :as m.error])) - -(defn- parse-json-config - [json-config] - (let [res (json/parse-string json-config keyword)] - (when-let [err (some->> res - (m/explain e.s.config/?Config) - (m.error/humanize))] - (throw (ex-info "Invalid server config" err))) - res)) + [elin.system :as e.system])) (defn -main [json-config] - (let [{:as config :keys [env]} (parse-json-config json-config) + (let [{:as config :keys [env]} (json/parse-string json-config keyword) config (e.config/load-config (:cwd env) config) sys-map (e.system/new-system config)]