Small logging improvement

This commit is contained in:
Yann Esposito (Yogsototh) 2024-01-18 18:09:01 +01:00
parent 78ab11b1cd
commit 652f5d1744
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
2 changed files with 33 additions and 23 deletions

View file

@ -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"}
}}

51
statyk
View file

@ -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 [<options>] <command> [<args>]"
"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*)