Skip to content

Commit

Permalink
Read from raw project for inherit-raw and inherit-leaky-raw
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Hanlon committed Sep 26, 2020
1 parent 2f96399 commit a640bf0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/lein_monolith/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
are loaded to check for the `:monolith` entry."
[project]
(if (:monolith project)
project
(assoc-in project [:monolith :raw] (project/read-raw (str (:root project))))
(some (fn check-project
[file]
(lein/debug "Reading candidate project file" (str file))
(let [super (project/read-raw (str file))]
(when (:monolith super)
super)))
(assoc-in (project/init-project super) [:monolith :raw] super))))
(find-up (:root project) "project.clj"))))


Expand Down
60 changes: 37 additions & 23 deletions src/lein_monolith/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"This namespace runs inside of Leiningen on all projects and handles profile
creation for `with-all` and `inherit` functionality."
(:require
[clojure.string :as str]
[lein-monolith.config :as config]
[lein-monolith.dependency :as dep]
[leiningen.core.main :as lein]
Expand Down Expand Up @@ -46,27 +47,32 @@
"Constructs a profile map containing the inherited properties from a parent
project map."
[monolith inherit-key setting]
(when-let [base-properties (get-in monolith [:monolith inherit-key])]
(cond
; Don't inherit anything
(not setting)
nil

; Inherit the base properties specified in the parent.
(true? setting)
(select-keys monolith base-properties)

; Provide additional properties to inherit, or replace if metadata is set.
(vector? setting)
(->> (if (:replace (meta setting))
setting
(distinct (concat base-properties setting)))
(select-keys monolith))

:else
(throw (ex-info (str "Unknown value type for monolith inherit setting: "
(pr-str setting))
{:inherit setting})))))
(let [raw? (str/ends-with? (name inherit-key) "-raw")
source (if raw?
(get-in monolith [:monolith :raw])
monolith)
base-properties (get-in source [:monolith inherit-key])]
(when base-properties
(cond
; Don't inherit anything
(not setting)
nil

; Inherit the base properties specified in the parent.
(true? setting)
(select-keys source base-properties)

; Provide additional properties to inherit, or replace if metadata is set.
(vector? setting)
(->> (if (:replace (meta setting))
setting
(distinct (concat base-properties setting)))
(select-keys source))

:else
(throw (ex-info (str "Unknown value type for monolith inherit setting: "
(pr-str setting))
{:inherit setting}))))))


(defn build-inherited-profiles
Expand All @@ -75,12 +81,20 @@
(let [inherit-profile (inherited-profile
monolith :inherit
(:monolith/inherit subproject))
inherit-raw-profile (inherited-profile
monolith :inherit-raw
(:monolith/inherit-raw subproject))
leaky-profile (inherited-profile
monolith :inherit-leaky
(:monolith/leaky subproject (boolean (:monolith/inherit subproject))))]
(:monolith/leaky subproject (boolean (:monolith/inherit subproject))))
leaky-raw-profile (inherited-profile
monolith :inherit-leaky-raw
(:monolith/leaky-raw subproject (boolean (:monolith/inherit-raw subproject))))]
(cond-> nil
inherit-profile (assoc :monolith/inherited inherit-profile)
leaky-profile (assoc :monolith/leaky (vary-meta leaky-profile assoc :leaky true)))))
inherit-raw-profile (assoc :monolith/inherited-raw inherit-raw-profile)
leaky-profile (assoc :monolith/leaky (vary-meta leaky-profile assoc :leaky true))
leaky-raw-profile (assoc :monolith/leaky-raw (vary-meta leaky-raw-profile assoc :leaky true)))))



Expand Down

0 comments on commit a640bf0

Please sign in to comment.