Skip to content

Commit

Permalink
with :only instead of :file
Browse files Browse the repository at this point in the history
This is what was suggested in the ticket and I think it works much
better than specifying a single file. It's not clear what should happen
when you have :only and no files?
  • Loading branch information
seancorfield committed Nov 28, 2021
1 parent 58d7731 commit b80dff9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/org/corfield/new.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(s/def ::template-fn symbol?)
(s/def ::files (s/map-of string? string?))
(s/def ::open-close (s/tuple string? string?))
(s/def ::opts #{:file :raw})
(s/def ::opts #{:only :raw})
(s/def ::dir-spec (s/cat :src string?
:target (s/? string?)
:files (s/? ::files)
Expand All @@ -30,7 +30,7 @@
(comment
(s/conform ::transform [["root"]])
(s/conform ::transform [["raw" "images" {} :raw]])
(s/conform ::transform [["raw" "images" {} :file :raw]])
(s/conform ::transform [["raw" "images" {} :only :raw]])
(s/conform ::template {:transform [["resources" "resources"]
["images" "img" {"logo.png" "{{logo}}/main.png"} :raw]]})
)
Expand Down
13 changes: 6 additions & 7 deletions src/org/corfield/new/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@
(let [target (when target (str "/" (substitute target data)))
opts (set opts)
raw (:raw opts)
file (:file opts)
only (:only opts)
file-data (let [[open close] delims]
(if (and open close)
(adjust-subst-map data open close)
data))]
(if (seq files)
;; TODO: can't have files and single file
(let [intermediate (-> (Files/createTempDirectory
"deps-new" (into-array FileAttribute []))
(.toFile)
(doto .deleteOnExit)
(.getCanonicalPath))
inter-target (str intermediate target)]
;; first we just copy the raw files with no substitutions:
(b/copy-dir {:target-dir inter-target
:src-dirs [(str template-dir "/" src)]})
(when (not only)
(b/copy-dir {:target-dir inter-target
:src-dirs [(str template-dir "/" src)]}))
;; now we process the named files, substituting paths:
(run! (fn [[from to]]
(b/delete {:path (str inter-target "/" from)})
Expand All @@ -125,9 +125,8 @@
:src-dirs [intermediate]}
(not raw)
(assoc :replace file-data))))
(if file
(b/copy-file {:src (str template-dir "/" src)
:target (str target-dir "/" target)})
(if only
nil ; what should happen for :only with no files?
(b/copy-dir (cond-> {:target-dir (str target-dir target)
:src-dirs [(str template-dir "/" src)]}
(not raw)
Expand Down

0 comments on commit b80dff9

Please sign in to comment.