From c7006a8477b8a5d1794bc7a547fa7f5eb6b2fa54 Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 13 Dec 2019 15:01:07 +0100 Subject: [PATCH] wip --- project.clj | 3 +- src/cryogen_core/classpath_able_io.clj | 38 +++++++++++++------- test/cryogen_core/classpath_able_io_test.clj | 34 ++++++++++++++---- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/project.clj b/project.clj index 41462bb..3dd9311 100644 --- a/project.clj +++ b/project.clj @@ -14,7 +14,8 @@ [io.aviso/pretty "0.1.37"] [me.raynes/fs "1.4.6"] [pandect "0.6.1"] - [selmer "1.12.17"]] + [selmer "1.12.17"] + [prismatic/schema "1.1.12"]] :deploy-repositories [["snapshots" :clojars] ["releases" :clojars]] :source-paths ["src"] diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 9c93c81..2f6ec4e 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -8,7 +8,8 @@ (ns cryogen-core.classpath-able-io (:require [clojure.java.io :as io] - [clojure.string :as s])) + [clojure.string :as s] + [schema.core :as s])) (def public "resources/public") @@ -22,21 +23,32 @@ (defn filter-for-ignore-patterns [ignore-patterns source-list] - (filter #(not (re-matches ignore-patterns %)) source-list)) + (filter #(not (re-matches ignore-patterns %)) source -list)) ; TODO: Datenstruktur [s/Str] -(defn delete-file-recursive - [folders] - (when (not (empty? folders)) - (let [file-to-work-with (first folders) - ; TODO: .list fehlt noch - file-list (filter #(.isFile %) file-to-work-with) - dir-list (filter #(not (.isFile %)) file-to-work-with)] - (doseq [file file-list] (io/delete-file file)) - (when (not (empty? dir-list)) - (recur (drop 1 dir-list))) - (io/delete-file file-to-work-with)))) +(s/defn get-file-paths-recursive :- [s/Str] + [base-path :- s/Str + paths :- [s/Str]] + (loop [paths paths + result []] + (when (not (empty? paths)) + (let [path-to-work-with (first paths) + path-content (.list (io/file (str base-path "/" path-to-work-with))) + file-list (filter #(.isFile %) path-content) + dir-list (filter #(not (.isFile %)) path-content)])))) + +; (defn delete-file-recursive +; [folders] +; (when (not (empty? folders)) +; (let [file-to-work-with (first folders) +; ; TODO: .list fehlt noch +; file-list (filter #(.isFile %) file-to-work-with) +; dir-list (filter #(not (.isFile %)) file-to-work-with)] +; (doseq [file file-list] (io/delete-file file)) +; (when (not (empty? dir-list)) +; (recur (drop 1 dir-list))) +; (io/delete-file file-to-work-with)))) (defn file-from-cp [resource-path] diff --git a/test/cryogen_core/classpath_able_io_test.clj b/test/cryogen_core/classpath_able_io_test.clj index 3e188af..91e8e4e 100644 --- a/test/cryogen_core/classpath_able_io_test.clj +++ b/test/cryogen_core/classpath_able_io_test.clj @@ -12,6 +12,8 @@ [clojure.java.io :as io] [cryogen-core.classpath-able-io :as sut])) +(set-fn-validation! true) + (def theme "bootstrap4-test") (def target "target/tmp") @@ -23,12 +25,30 @@ (and (verify-file-exists path) (.isDirectory (io/file path)))) -(deftest test-wipe-public-folder - (is - (do - (.mkdir (io/file target)) - (sut/delete-file-recursive (seq (io/file target))) - (not (verify-dir-exists target))))) +(deftest test-get-file-paths-recursive + (is (= + ["js/dummy.js"] + (sut/get-file-paths-recursive "templates/themes/bootstrap4-test" ["js/dummy.js"])) + (is (= + ["/css/dummy.css" + "css" + "/html/404.html" + "/html/403.html" + "/html" + "html" + "js/subdir/subdummy.js" + "js/subdir/test.js" + "js/subdir" + "js/dummy.js" + "js"] + (sut/get-file-paths-recursive "templates/themes/bootstrap4-test" [""]))))) + +; (deftest test-delete-file-recursive +; (is +; (do +; (.mkdir (io/file target)) +; (sut/delete-file-recursive (seq (io/file target))) +; (not (verify-dir-exists target))))) (deftest test-file-from-cp-or-filesystem (is @@ -70,4 +90,4 @@ (str target "/templates/themes/bootstrap4-test/css/dummy.css")) (verify-file-exists (str target "/templates/themes/bootstrap4-test/html/404.html")) - )))) \ No newline at end of file + ))))