From f448684b302334c7a872af14877e3cd81806281f Mon Sep 17 00:00:00 2001 From: Luciano Laratelli Date: Fri, 14 Mar 2025 16:48:59 -0400 Subject: [PATCH] jar stuff. rename ns --- .gitignore | 2 + Makefile | 6 +- build.clj | 24 +++++ deps.edn | 6 +- dev/user.clj | 4 +- resources/config.edn | 3 +- src/com/biffweb/my_project.clj | 6 +- src/com/biffweb/my_project/settings.clj | 3 - src/com/score_the_pigs.clj | 91 +++++++++++++++++++ .../my_project => score_the_pigs}/app.clj | 8 +- .../middleware.clj | 2 +- src/com/score_the_pigs/settings.clj | 3 + .../my_project => score_the_pigs}/ui.clj | 4 +- .../my_project => score_the_pigs}/util/db.clj | 2 +- 14 files changed, 144 insertions(+), 20 deletions(-) create mode 100644 build.clj delete mode 100644 src/com/biffweb/my_project/settings.clj create mode 100644 src/com/score_the_pigs.clj rename src/com/{biffweb/my_project => score_the_pigs}/app.clj (98%) rename src/com/{biffweb/my_project => score_the_pigs}/middleware.clj (98%) create mode 100644 src/com/score_the_pigs/settings.clj rename src/com/{biffweb/my_project => score_the_pigs}/ui.clj (97%) rename src/com/{biffweb/my_project => score_the_pigs}/util/db.clj (87%) diff --git a/.gitignore b/.gitignore index e3e7a24..547999f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ .clj-kondo/ .lsp/ .portal/ +*.jar +*.db diff --git a/Makefile b/Makefile index a78e38b..faa220c 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ tidy: .PHONY: storage/site.db storage/site.db: - rm -f storage/* + rm -f storage/site.db* sqlite3 storage/site.db 'PRAGMA journal_mode=WAL;' clj -M dev/migration.clj uv run dev/sqlite-history.py @@ -14,3 +14,7 @@ db: storage/site.db repl: storage/site.db clj -M:dev dev + +jar: db + clojure -T:build uberjar + mv target/*.jar . diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..46cc037 --- /dev/null +++ b/build.clj @@ -0,0 +1,24 @@ +(ns build + (:require [clojure.tools.build.api :as b] + [clojure.edn :as edn])) + +(def class-dir "target/classes") + +(def basis (delay (b/create-basis {:project "deps.edn"}))) + +(def jar-file "target/score-the-pigs.jar") + +(defn clean [_] + (b/delete {:path "target"})) + +(defn uberjar [_] + (clean nil) + (b/copy-dir {:src-dirs ["src" "resources"] + :target-dir class-dir}) + (b/compile-clj {:basis @basis + :src-dirs ["src"] + :class-dir class-dir}) + (b/uber {:class-dir class-dir + :uber-file jar-file + :basis @basis + :main 'com.score-the-pigs})) diff --git a/deps.edn b/deps.edn index 86ecc00..8777f2b 100644 --- a/deps.edn +++ b/deps.edn @@ -43,4 +43,8 @@ :prod {:jvm-opts ["-XX:-OmitStackTraceInFastThrow" "-XX:+CrashOnOutOfMemoryError" "-Dbiff.env.BIFF_PROFILE=prod"] - :main-opts ["-m" "com.biffweb.my-project"]}}} + :main-opts ["-m" "com.biffweb.my-project"]} + :build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.7" + :git/sha "573711e"} + slipset/deps-deploy {:mvn/version "0.2.2"}} + :ns-default build}}} diff --git a/dev/user.clj b/dev/user.clj index cdbdbd9..2bf3c09 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -3,8 +3,8 @@ [clojure.java.io :as io] [clojure.tools.logging :as log] [clojure.tools.namespace.repl :as tn-repl] - [com.biffweb.my-project :as main :refer [system]] - [com.biffweb.my-project.util.db :as db] + [com.score-the-pigs :as main :refer [system]] + [com.score-the-pigs.util.db :as db] [honey.sql :as sql] [honey.sql.helpers :refer [drop-table]] [next.jdbc :as jdbc])) diff --git a/resources/config.edn b/resources/config.edn index edd254c..cd4e951 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -6,8 +6,7 @@ :default "localhost"} :biff/port 8080 - :example/db-url #profile {:prod "jdbc:sqlite:storage/site.db" - :dev "jdbc:sqlite:storage/site.db"} + :example/db-url "jdbc:sqlite:storage/site.db" :biff.beholder/enabled #profile {:dev true :default false} diff --git a/src/com/biffweb/my_project.clj b/src/com/biffweb/my_project.clj index 3cb631c..4af4c6b 100644 --- a/src/com/biffweb/my_project.clj +++ b/src/com/biffweb/my_project.clj @@ -2,9 +2,9 @@ (:require [clojure.test :as test] [com.biffweb :as biff] - [com.biffweb.my-project.app :as app] - [com.biffweb.my-project.middleware :as mid] - [com.biffweb.my-project.ui :as ui] + [com.score-the-pigs.app :as app] + [com.score-the-pigs.middleware :as mid] + [com.score-the-pigs.ui :as ui] [migratus.core :as migratus] [next.jdbc :as jdbc] [nrepl.cmdline :as nrepl-cmd] diff --git a/src/com/biffweb/my_project/settings.clj b/src/com/biffweb/my_project/settings.clj deleted file mode 100644 index 27377cd..0000000 --- a/src/com/biffweb/my_project/settings.clj +++ /dev/null @@ -1,3 +0,0 @@ -(ns com.biffweb.my-project.settings) - -(def app-name "my_project") diff --git a/src/com/score_the_pigs.clj b/src/com/score_the_pigs.clj new file mode 100644 index 0000000..4503487 --- /dev/null +++ b/src/com/score_the_pigs.clj @@ -0,0 +1,91 @@ +(ns com.score-the-pigs + (:require + [clojure.pprint :as pp] + [clojure.test :as test] + [com.biffweb :as biff] + [com.score-the-pigs.app :as app] + [com.score-the-pigs.middleware :as mid] + [com.score-the-pigs.ui :as ui] + [migratus.core :as migratus] + [next.jdbc :as jdbc] + [nrepl.cmdline :as nrepl-cmd] + [taoensso.telemere.timbre :as log]) + (:gen-class)) + +(def modules + [app/module]) + +(def routes [["" {:middleware [mid/wrap-site-defaults]} + (keep :routes modules)] + ["" {:middleware [mid/wrap-api-defaults]} + (keep :api-routes modules)]]) + +(def handler (-> (biff/reitit-handler {:routes routes}) + mid/wrap-base-defaults)) + +(def static-pages (apply biff/safe-merge (map :static modules))) + +(defn generate-assets! [_ctx] + (biff/export-rum static-pages "target/resources/public") + (biff/delete-old-files {:dir "target/resources/public" + :exts [".html"]})) + +(defn on-save [ctx] + (biff/add-libs) + (biff/eval-files! ctx) + (generate-assets! ctx) + (biff/catchall (require 'com.biffweb.my-project-test)) + (test/run-all-tests #"com.biffweb.my-project.*-test")) + +(def initial-system + {:biff/modules #'modules + :biff/merge-context-fn identity + :biff/handler #'handler + :biff.beholder/on-save #'on-save + :biff.middleware/on-error #'ui/on-error + :example/chat-clients (atom {})}) + +(defonce system (atom {})) + +(defn ctx->migratus-config [ctx] + {:store :database + :migration-dir "migrations/" + :db {:connection (jdbc/get-connection (:example/db-url ctx)) + :managed-connection? true}}) + +(defn use-sqlite [ctx] + (let [db-url (get ctx :example/db-url) + ds (jdbc/get-datasource db-url) + ;; migration-config (ctx->migratus-config ctx) + ] + + ;; (migratus/init migration-config) + ;; (migratus/migrate migration-config) + (assoc ctx :example/ds ds))) + +(def components + [biff/use-aero-config + use-sqlite + biff/use-queues + biff/use-htmx-refresh + biff/use-jetty + biff/use-chime + biff/use-beholder]) + +(defn start [] + (let [new-system (reduce (fn [system component] + (pp/pprint system) + (log/info "starting:" (str component)) + (component system)) + initial-system + components)] + (reset! system new-system) + (generate-assets! new-system) + (log/info "System started.") + (log/info "Go to" (:biff/base-url new-system)) + new-system)) + +(defn -main [] + (let [{:keys [biff.nrepl/args]} (start)] + (apply nrepl-cmd/-main args))) + diff --git a/src/com/biffweb/my_project/app.clj b/src/com/score_the_pigs/app.clj similarity index 98% rename from src/com/biffweb/my_project/app.clj rename to src/com/score_the_pigs/app.clj index fa1eb1a..db75602 100644 --- a/src/com/biffweb/my_project/app.clj +++ b/src/com/score_the_pigs/app.clj @@ -1,10 +1,10 @@ -(ns com.biffweb.my-project.app +(ns com.score-the-pigs.app (:require [clojure.string :as str] [com.biffweb :as biff] - [com.biffweb.my-project.middleware :refer [wrap-clean-up-param-vals]] - [com.biffweb.my-project.settings :as settings] - [com.biffweb.my-project.ui :as ui] + [com.score-the-pigs.middleware :refer [wrap-clean-up-param-vals]] + [com.score-the-pigs.settings :as settings] + [com.score-the-pigs.ui :as ui] [honey.sql :as sql] [next.jdbc :as jdbc] [org.sqids.clojure :as sqids] diff --git a/src/com/biffweb/my_project/middleware.clj b/src/com/score_the_pigs/middleware.clj similarity index 98% rename from src/com/biffweb/my_project/middleware.clj rename to src/com/score_the_pigs/middleware.clj index 76466e4..cb1c89c 100644 --- a/src/com/biffweb/my_project/middleware.clj +++ b/src/com/score_the_pigs/middleware.clj @@ -1,4 +1,4 @@ -(ns com.biffweb.my-project.middleware +(ns com.score-the-pigs.middleware (:require [camel-snake-kebab.core :as csk] [clojure.pprint :as pp] diff --git a/src/com/score_the_pigs/settings.clj b/src/com/score_the_pigs/settings.clj new file mode 100644 index 0000000..b1bbcdb --- /dev/null +++ b/src/com/score_the_pigs/settings.clj @@ -0,0 +1,3 @@ +(ns com.score-the-pigs.settings) + +(def app-name "my_project") diff --git a/src/com/biffweb/my_project/ui.clj b/src/com/score_the_pigs/ui.clj similarity index 97% rename from src/com/biffweb/my_project/ui.clj rename to src/com/score_the_pigs/ui.clj index 799e182..e568489 100644 --- a/src/com/biffweb/my_project/ui.clj +++ b/src/com/score_the_pigs/ui.clj @@ -1,7 +1,7 @@ -(ns com.biffweb.my-project.ui +(ns com.score-the-pigs.ui (:require [cheshire.core :as cheshire] - [com.biffweb.my-project.settings :as settings] + [com.score-the-pigs.settings :as settings] [ring.middleware.anti-forgery :as csrf] [rum.core :as rum])) diff --git a/src/com/biffweb/my_project/util/db.clj b/src/com/score_the_pigs/util/db.clj similarity index 87% rename from src/com/biffweb/my_project/util/db.clj rename to src/com/score_the_pigs/util/db.clj index ddc5c8c..55a2c4d 100644 --- a/src/com/biffweb/my_project/util/db.clj +++ b/src/com/score_the_pigs/util/db.clj @@ -1,4 +1,4 @@ -(ns com.biffweb.my-project.util.db +(ns com.score-the-pigs.util.db (:require [next.jdbc :as jdbc]))