From f5413204d45cd2eeccc140de403dbfd884aca3c6 Mon Sep 17 00:00:00 2001 From: Felipe-gsilva Date: Thu, 26 Sep 2024 21:22:18 -0300 Subject: [PATCH] feat: copy the css file from .jar (on build hook) --- src/dev/shadow/hooks.clj | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/dev/shadow/hooks.clj b/src/dev/shadow/hooks.clj index 8e012d5..8f42d31 100644 --- a/src/dev/shadow/hooks.clj +++ b/src/dev/shadow/hooks.clj @@ -1,11 +1,50 @@ (ns dev.shadow.hooks (:require [babashka.process :as proc] + [clojure.java.shell :as shell] [clojure.java.io :as io] [clojure.string :as str] [shadow.build :as build] [shadow.cljs.util :as s.util])) +(def file (io/file "resources/public/assets/css/target.css")) + +(defn retrieve-css + ([] + (retrieve-css nil)) + ([css-path] + (let [css-file (if (nil? css-path) + file + (io/file css-path))] + css-file))) + +(defn file-exists? [file] + (.exists file)) + +(defn copy-from-jar [jar-path file dest-dir] + (let [cmd (str "jar xf " jar-path " " file " | mv target.css " (str dest-dir "/target.css"))] + (shell/sh "sh" "-c" cmd))) + +(defn list-jar [jar-path] + (let [ cmd (str "jar tf " jar-path " | grep target.css")] + (shell/sh "sh" "-c" cmd))) + +(defn target-css [{::build/keys [mode] :as build-state} + {:keys [path] + :or {path "resources/public/assets/css/target.css"}}] + (let [css-file (retrieve-css path) + css-jar-file (str/replace "\n" "" (:out (list-jar "target/mockingbird-0.0.1.jar")))] + + (if (file-exists? css-file) + (prn "CSS file already exists. No action needed.") + (do + (prn "CSS file does not exist. Copying from .jar...") + (copy-from-jar "target/mockingbird-0.0.1.jar" css-jar-file path) + (prn "CSS file copied."))))) + +(target-css {} {:path "public/react.css"}) + + (defn build-css {:shadow.build/stage :configure} [{::build/keys [mode] :as build-state} watch? src dst]