Skip to content

Commit

Permalink
chore: Tweak codes
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Feb 5, 2024
1 parent 2eb2431 commit 2eff7fa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .elin.edn
Original file line number Diff line number Diff line change
@@ -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 "."}}
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 6 additions & 7 deletions dev/elin/dev.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions src/elin/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}))
Expand Down
16 changes: 2 additions & 14 deletions src/elin/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down

0 comments on commit 2eff7fa

Please sign in to comment.