add ! for side-effect-full functions

master
jem 5 years ago
parent fe5b94c61c
commit 1bdb53d4e3

@ -82,13 +82,13 @@
(doseq [path resource-paths] (doseq [path resource-paths]
(io/delete-file path)))) (io/delete-file path))))
(defn copy-file (defn copy-file!
[source-file [source-file
target-file] target-file]
(do (io/make-parents target-file) (do (io/make-parents target-file)
(io/copy source-file target-file))) (io/copy source-file target-file)))
(defn do-copy (defn do-copy!
[source-dir target-dir ignore-patterns] [source-dir target-dir ignore-patterns]
(loop [source-list (.list source-dir) (loop [source-list (.list source-dir)
file-path-prefix [""]] file-path-prefix [""]]
@ -98,7 +98,7 @@
source-file (io/file source-dir (str (first file-path-prefix) f))] source-file (io/file source-dir (str (first file-path-prefix) f))]
(if (.isFile source-file) (if (.isFile source-file)
(do (do
(copy-file source-file target-file) (copy-file! source-file target-file)
(when second? (when second?
(recur (drop 1 source-list) (drop 1 file-path-prefix)))) (recur (drop 1 source-list) (drop 1 file-path-prefix))))
(when (> (count (.list source-file)) 0) (when (> (count (.list source-file)) 0)
@ -106,18 +106,18 @@
(concat (repeat (count (.list source-file)) (str (first file-path-prefix) f "/")) (concat (repeat (count (.list source-file)) (str (first file-path-prefix) f "/"))
(drop 1 file-path-prefix)))))))) (drop 1 file-path-prefix))))))))
(defn copy-resources (defn copy-resources!
[fs-prefix source-path target-path ignore-patterns] [fs-prefix source-path target-path ignore-patterns]
(let [source-file (file-from-cp-or-filesystem fs-prefix source-path) (let [source-file (file-from-cp-or-filesystem fs-prefix source-path)
target-file (io/file target-path source-path) target-file (io/file target-path source-path)
is-source-dir? (.isDirectory source-file)] is-source-dir? (.isDirectory source-file)]
(if (nil? source-file) (if (nil? source-file)
(throw (IllegalArgumentException. (str "resource " source-path " not found"))) (throw (IllegalArgumentException. (str "resource " source-path " not found")))
(do-copy source-file target-file ignore-patterns)))) (do-copy! source-file target-file ignore-patterns))))
(defn copy-resources-from-theme (defn copy-resources-from-theme!
[fs-prefix theme target-path ignore-patterns] [fs-prefix theme target-path ignore-patterns]
(let [theme-path (str "templates/themes/" theme)] (let [theme-path (str "templates/themes/" theme)]
(copy-resources fs-prefix (str theme-path "/css") target-path ignore-patterns) (copy-resources! fs-prefix (str theme-path "/css") target-path ignore-patterns)
(copy-resources fs-prefix (str theme-path "/js") target-path ignore-patterns) (copy-resources! fs-prefix (str theme-path "/js") target-path ignore-patterns)
(copy-resources fs-prefix (str theme-path "/html/") target-path ignore-patterns))) (copy-resources! fs-prefix (str theme-path "/html/") target-path ignore-patterns)))

@ -56,7 +56,7 @@
(is (is
(do (do
(.mkdir (io/file (str "target/tmp" target))) (.mkdir (io/file (str "target/tmp" target)))
(sut/delete-resource-recursive! (str "target/tmp"target)) (sut/delete-resource-recursive! (str "target/tmp" target))
(not (verify-dir-exists (str "target/tmp" target)))))) (not (verify-dir-exists (str "target/tmp" target))))))
(deftest test-file-from-cp-or-filesystem (deftest test-file-from-cp-or-filesystem
@ -84,19 +84,19 @@
(.exists (sut/file-from-cp-or-filesystem (.exists (sut/file-from-cp-or-filesystem
"./" ".gitkeep")))) "./" ".gitkeep"))))
(deftest test-copy-resources-from-theme (deftest test-copy-resources-from-theme! (is (do
(is (do (sut/delete-resource-recursive! (str "target/tmp" target))
(sut/copy-resources-from-theme "./" theme target "") (sut/copy-resources-from-theme! "./" theme target "")
(and (verify-dir-exists (and (verify-dir-exists
(str target "/templates/themes/bootstrap4-test/js")) (str target "/templates/themes/bootstrap4-test/js"))
(verify-file-exists (verify-file-exists
(str target "/templates/themes/bootstrap4-test/js/dummy.js")) (str target "/templates/themes/bootstrap4-test/js/dummy.js"))
(verify-dir-exists (verify-dir-exists
(str target "/templates/themes/bootstrap4-test/js/subdir")) (str target "/templates/themes/bootstrap4-test/js/subdir"))
(verify-file-exists (verify-file-exists
(str target "/templates/themes/bootstrap4-test/js/subdir/subdummy.js")) (str target "/templates/themes/bootstrap4-test/js/subdir/subdummy.js"))
(verify-file-exists (verify-file-exists
(str target "/templates/themes/bootstrap4-test/css/dummy.css")) (str target "/templates/themes/bootstrap4-test/css/dummy.css"))
(verify-file-exists (verify-file-exists
(str target "/templates/themes/bootstrap4-test/html/404.html")) (str target "/templates/themes/bootstrap4-test/html/404.html"))
)))) ))))

Loading…
Cancel
Save