From 652f5d1744d1a0ec294acce471ce53b22d288888 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Thu, 18 Jan 2024 18:09:01 +0100 Subject: [PATCH] Small logging improvement --- deps.edn | 5 +---- statyk | 51 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/deps.edn b/deps.edn index b7c6dc1..82054f4 100644 --- a/deps.edn +++ b/deps.edn @@ -3,8 +3,5 @@ ring/ring-jetty-adapter {:mvn/version "1.11.0"} babashka/fs {:mvn/version "0.5.20"} ;; logs for jetty - org.slf4j/slf4j-api {:mvn/version "2.0.9"} - ch.qos.logback/logback-classic {:mvn/version "1.4.11"} - net.logstash.logback/logstash-logback-encoder {:mvn/version "7.4"} - ch.codesmith/logger {:mvn/version "0.7.108"} + org.slf4j/slf4j-simple {:mvn/version "2.0.11"} }} diff --git a/statyk b/statyk index fb55cfe..7b659a5 100755 --- a/statyk +++ b/statyk @@ -12,10 +12,7 @@ ring/ring-jetty-adapter {:mvn/version "1.11.0"} babashka/fs {:mvn/version "0.5.20"} ;; logs for jetty - org.slf4j/slf4j-api {:mvn/version "2.0.9"} - ch.qos.logback/logback-classic {:mvn/version "1.4.11"} - net.logstash.logback/logstash-logback-encoder {:mvn/version "7.4"} - ch.codesmith/logger {:mvn/version "0.7.108"} + org.slf4j/slf4j-simple {:mvn/version "2.0.11"} }} ' @@ -171,7 +168,7 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@" (defn generate-static-files [] - (doseq [src-file (file-seq (:source-directory config))] + (doseq [src-file (file-seq (io/file (:source-directory config)))] (let [{:keys [ext dst-file]} (dst-file-name-and-ext src-file)] (when (is-newer? src-file dst-file) (build src-file dst-file ext))))) @@ -182,7 +179,7 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@" ["Usage: statyk [] []" "Where commands:" "- serve serve the directory _site" - "- gen generate the files from the sources" + "- build build the site from the sources" "- clean delete generated files in _site"])) (System/exit 0)) @@ -207,8 +204,27 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@" (cp-resource ".statyk" f)) (doseq [f ["index.html" "post.html"]] - (cp-resource (:templates-directory config) f)) - ) + (cp-resource (:templates-directory config) f))) + +(defn do-command + [command options] + (case command + "serve" (do + (println "Serve: http://127.0.0.1:13375") + (run-jetty serve-dest-dir-handler + {:port 13375 + :host "127.0.0.1"})) + "build" (generate-static-files) + "init" (init-site options) + (show-help) + (err! (format "unknown command %s" command)))) + +(defn initialized? + "Returns false if the current directory does not conform to an initalized statyk dir." + [] + (and + (fs/exists? (:source-directory config)) + (fs/exists? (:dest-directory config)))) (defn -main [& args] (let [{:keys [options arguments summary errors] @@ -218,17 +234,14 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@" (doseq [err errors] (pr-err! err) (System/exit 1))) - (let [command (first arguments)] - (condp = command - "serve" (do - (println "Serve: http://127.0.0.1:13375") - (run-jetty serve-dest-dir-handler - {:port 13375 - :host "127.0.0.1"})) - "gen" (generate-static-files) - "init" (init-site options) - (show-help) - (err! (format "unknown command %s" command)))))) + (if-let [command (first arguments)] + (do-command command options) + (do + (when-not (initialized?) + (do-command "init" options)) + + (future (do-command "serve" options)) + (do-command "watch" options))))) (apply -main *command-line-args*)