Skip to content

Commit

Permalink
initial pinned version
Browse files Browse the repository at this point in the history
  • Loading branch information
burn2delete committed May 29, 2020
1 parent 2d947b0 commit 78783ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/degree9/env.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,39 @@

;; Env Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- read-file [path]
(when (.existsSync fs path)
(.readFileSync fs path #js{:encoding "utf8"})))
(debug "Reading file from path %s" path)
(.readFileSync fs path #js{:encoding "utf8"}))

(defn- env-file [dir]
(debug "Resolve path to .env file %s" dir)
(.resolve path dir ".env"))

(defn- split-kv [kvstr]
(debug "Split key/value pair from %s" kvstr)
(cstr/split kvstr #"=" 2))

(defn- split-config [config]
(->> (cstr/split-lines config)
(map split-kv)
(into {})))
(debug "Split lines from %s" config)
(map split-kv (cstr/split-lines config)))

(defn- dot-env [path]
(-> (env-file path)
(read-file)
(split-config)))
(debug "Checking for .env file within %s" path)
(let [env (env-file path)]
(when (.existsSync fs env)
(debug "Loading .env file from %s" env)
(->> (read-file env)
(split-config)
(into {})))))

(defn- node-env [env]
(debug "Loading node environment" env)
(->> (js-keys env)
(map (fn [key] [key (obj/get env key)]))
(into {})))

(defn- populate-env! [env]
(doseq [[k v] env]
(debug "Populate the node environment with %s" env)
(doseq [[k v] (into [] env)]
(obj/set js/process.env k v)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down
1 change: 1 addition & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=0.1.0

0 comments on commit 78783ff

Please sign in to comment.