Skip to content

Commit

Permalink
chore: clean up the codebase
Browse files Browse the repository at this point in the history
Removing most of the stuff added by default by the practical.li
templates (while being very grateful to their authors for enabling me to
get started). Also re-architecturing the directory structure, and
changing the way we start the shadow-cljs build.
  • Loading branch information
goshatch committed Jan 30, 2025
1 parent 276bfc3 commit 3afe7f6
Show file tree
Hide file tree
Showing 51 changed files with 200 additions and 529 deletions.
4 changes: 2 additions & 2 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
((clojure-mode . ((cider-preferred-build-tool . clojure-cli)
(cider-default-cljs-repl . shadow)
(cider-shadow-default-options . "app")
(cider-shadow-default-options . "frontend")
(cider-offer-to-open-cljs-app-in-browser . nil)
(cider-clojure-cli-aliases . ":test/env:dev/reloaded"))))
(cider-clojure-cli-aliases . ":test/env"))))
31 changes: 8 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
# ------------------------
# Clojure Project Git Ignore file patterns
#
# Ignore all except patterns starting with !
# Add comments on separate lines, not same line as pattern
# ------------------------

# ------------------------
# Ignore everthing in root directory
/*

# ------------------------
# Common project files
!CHANGELOG.md
!README.md
!LICENSE

# ------------------------
# Include Clojure project & config
!build.clj
!deps.edn
!pom.xml
!dev/
!docs/
!src/
!test/
!config.edn

# Don't ignore resources
!resources/
# ...but ignore shadow-cljs build artifacts
resources/public/js

# ------------------------
# Public directory rules
!public/
# Handle js subdirectory specifically
!public/js/
public/js/*
!public/js/.keep

# ------------------------
# Include Clojure tools
Expand All @@ -43,7 +34,6 @@ resources/public/js

# ------------------------
# Frontend things
!cljs
!shadow-cljs.edn
!package.json
!bun.lockb
Expand All @@ -54,11 +44,6 @@ resources/public/js
!.gitignore
!.github/

# ------------------------
# Include ClojureScript Figwheel
!figwheel-main.edn
!*.cljs.edn

# ------------------------
# Include deployment related files
!config
Expand Down
22 changes: 0 additions & 22 deletions CHANGELOG.md

This file was deleted.

25 changes: 2 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
# ------------------------------------------
# Build and run Practicalli Gameboard API Service
#
# Author: Practicalli
#
# Builder image:
# Official Clojure Docker image with Java 17 (eclipse-temurin) and Clojure CLI
# https://hub.docker.com/_/clojure/
#
# Run-time image:
# Official Java Docker image with Java 17 (eclipse-temurin)
# https://hub.docker.com/_/eclipse-temurin
# ------------------------------------------


# ------------------------
# Setup Builder container

FROM clojure:temurin-17-alpine AS builder

# Set Clojure CLI version (defaults to latest release)
# ENV CLOJURE_VERSION=1.11.1.1413

# Create directory for project code (working directory)
RUN mkdir -p /build

Expand Down Expand Up @@ -94,7 +73,7 @@ USER clojure

# Copy service archive file from Builder image
WORKDIR /app
COPY --from=builder /build/target/tools-ifs-parts-standalone.jar /app/
COPY --from=builder /build/target/parts-standalone.jar /app/

# Optional: Add System Integration testing scripts
# RUN mkdir -p /app/test-scripts
Expand Down Expand Up @@ -136,7 +115,7 @@ ENV JDK_JAVA_OPTIONS="-XshowSettings:system -XX:+UseContainerSupport -XX:MaxRAMP
# Start service using dumb-init and java run-time
# (overrides `jshell` entrypoint - default in eclipse-temuring image)
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["java", "-jar", "/app/tools-ifs-parts-standalone.jar"]
CMD ["java", "-jar", "/app/parts-standalone.jar"]


# Docker Entrypoint documentation
Expand Down
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# - `:env/dev` to include `dev` directory on class path
# - `:env/test` to include `test` directory and libraries to support testing
# - `:test/run` to run kaocha kaocha test runner and supporting paths and dependencies
# - `:repl/rebel` to start a Rebel terminal UI
# - `:package/uberjar` to create an uberjar for the service
# - docker
# - mega-linter-runner
Expand All @@ -28,7 +27,8 @@
HELP-DESCRIPTION-SPACING := 24

# Tool variables
MEGALINTER_RUNNER = npx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
FORMATTER_RUNNER = bunx @chrisoakman/standard-clojure-style
MEGALINTER_RUNNER = bunx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
CLOJURE_TEST_RUNNER = clojure -M:test/env:test/run
CLOJURE_EXEC_TEST_RUNNER = clojure -X:test/env:test/run

Expand All @@ -48,15 +48,15 @@ help: ## Describe available tasks in Makefile
# ------------------------------------ #

# ------- Clojure Development -------- #
repl: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
$(info --------- Run Rebel REPL ---------)
clojure -M:test/env:repl/reloaded
repl: ## Run Clojure REPL
$(info --------- Run REPL with Shadow ---------)
clojure -M -m shadow.cljs.devtools.cli clj-repl

deps: deps.edn ## Prepare dependencies for test and dist targets
$(info --------- Download test and service libraries ---------)
clojure -P -X:build

dist: build-uberjar ## Build and package Clojure service
dist: build-frontend build-uberjar ## Build and package Clojure service
$(info --------- Build and Package Clojure service ---------)

# Remove files and directories after build tasks
Expand Down Expand Up @@ -101,6 +101,10 @@ build-jar: ## Build a jar archive of Clojure project
$(info --------- Build library jar ---------)
clojure -T:build/task jar

build-frontend: ## Build shadow-cljs frontend app
$(info --------- Build frontend ---------)
clojure -M -m shadow.cljs.devtools.cli release frontend

build-uberjar: ## Build a uberjar archive of Clojure project & Clojure runtime
$(info --------- Build service Uberjar ---------)
clojure -T:build/task uberjar
Expand All @@ -111,16 +115,17 @@ build-clean: ## Clean build assets or given directory
# ------------------------------------ #

# ------- Code Quality --------------- #
pre-commit-check: format-check lint test ## Run format, lint and test targets
pre-commit-check: format lint test ## Run format, lint and test targets

format-check: ## Run cljstyle to check the formatting of Clojure code
format: ## Run cljstyle to check the formatting of Clojure code
$(info --------- standard-clojure-style-js Runner ---------)
standard-clj check .
$(FORMATTER_RUNNER) check .

format-fix: ## Run cljstyle and fix the formatting of Clojure code
$(info --------- standard-clojure-style-js Runner ---------)
standard-clj fix .
$(FORMATTER_RUNNER) fix .

# TODO: Reconsider how useful this is
lint: ## Run MegaLinter with custom configuration (node.js required)
$(info --------- MegaLinter Runner ---------)
$(MEGALINTER_RUNNER)
Expand Down
9 changes: 3 additions & 6 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
(def project-config
"Project configuration to support all tasks"
{:class-directory "target/classes"
:main-namespace 'tools.ifs/parts
:main-namespace 'parts/server
:project-basis (build-api/create-basis)
:uberjar-file "target/tools-ifs-parts-standalone.jar"})
:uberjar-file "target/parts-standalone.jar"})

(defn config
"Display build configuration"
Expand Down Expand Up @@ -63,7 +63,7 @@
(let [config (merge project-config options)
{:keys [class-directory main-namespace project-basis uberjar-file]} config]
(clean "target")
(build-api/copy-dir {:src-dirs ["src" "resources"]
(build-api/copy-dir {:src-dirs ["src/main" "resources" "public"]
:target-dir class-directory})

(build-api/compile-clj {:basis project-basis
Expand All @@ -74,6 +74,3 @@
:class-dir class-directory
:main main-namespace
:uber-file uberjar-file})))

;; End of Build tasks
;; ---------------------------------------------------------
Binary file modified bun.lockb
Binary file not shown.
32 changes: 0 additions & 32 deletions cljs/tools/ifs/parts/core.cljs

This file was deleted.

2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: "parts"

services:
# --- Clojure Service --- #
parts-ifs-tools:
parts:
platform: linux/amd64
# Build using Dockerfile - relative path or Git repository
build:
Expand Down
68 changes: 26 additions & 42 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{;; ---------------------------------------------------------
:paths
["src" "resources" "cljs"]
;; ---------------------------------------------------------

;; ---------------------------------------------------------
{:paths ["src/main" "src/dev" "resources"]
:deps
{;; Service
org.clojure/clojure {:mvn/version "1.12.0"}
com.brunobonacci/mulog {:mvn/version "0.9.0"}
{org.clojure/clojure {:mvn/version "1.12.0"}
http-kit/http-kit {:mvn/version "2.8.0"}
metosin/reitit {:mvn/version "0.7.2"}
metosin/muuntaja {:mvn/version "0.6.10"}
;;
;; Auth-related things
buddy/buddy-auth {:mvn/version "3.0.323"}
buddy/buddy-hashers {:mvn/version "2.0.167"}
com.github.seancorfield/next.jdbc {:mvn/version "1.3.955"}
org.xerial/sqlite-jdbc {:mvn/version "3.47.0.0"}
;;
;; Database-related things
com.github.seancorfield/next.jdbc {:mvn/version "1.3.981"}
org.xerial/sqlite-jdbc {:mvn/version "3.48.0.0"}
migratus/migratus {:mvn/version "1.6.3"}
com.github.seancorfield/honeysql {:mvn/version "2.6.1203"}
com.github.seancorfield/honeysql {:mvn/version "2.6.1270"}

ring/ring-json {:mvn/version "0.5.1"}
ring/ring-mock {:mvn/version "0.4.0"}
;; Simple logging implementation using by Buddy for ex

;; Logging
org.slf4j/slf4j-simple {:mvn/version "2.0.16"}
com.brunobonacci/mulog {:mvn/version "0.9.0"}
;;
;; A small library for explicit, intentful configuration.
;; https://github.com/juxt/aero
Expand All @@ -30,37 +29,30 @@
;; secure default configurations of Ring middleware for both websites and HTTP
;; APIs.
;; https://github.com/ring-clojure/ring-defaults
ring/ring-defaults {:mvn/version "0.5.0"}
ring/ring-defaults {:mvn/version "0.6.0"}
;;
;; Hiccup is a library for representing HTML in Clojure. It uses vectors to
;; represent elements, and maps to represent an element's attributes.
;; https://github.com/weavejester/hiccup
hiccup/hiccup {:mvn/version "2.0.0-RC3"}
hiccup/hiccup {:mvn/version "2.0.0-RC4"}
;;
;; Clojurescript
;; https://github.com/clojure/clojurescript
org.clojure/clojurescript {:mvn/version "1.11.132"}}
org.clojure/clojurescript {:mvn/version "1.11.132"}
;;
;; shadow-cljs
;; https://code.thheller.com/blog/shadow-cljs/2024/10/18/fullstack-cljs-workflow-with-shadow-cljs.html
thheller/shadow-cljs {:mvn/version "2.28.20"}
cider/cider-nrepl {:mvn/version "0.51.1"}
refactor-nrepl/refactor-nrepl {:mvn/version "3.10.0"}}

;; ---------------------------------------------------------
:aliases
{;; ------------
;; Clojure.main execution of application
:run/app
{:main-opts ["-m" "tools.ifs.parts"]}
{:run/app
{:main-opts ["-m" "parts.server"]}

;; Clojure.exec execution of specified function
:run/greet
{:exec-fn tools.ifs.parts/greet
:exec-args {:name "Clojure"}}
;; ------------

;; ------------
;; Add libraries and paths to support additional test tools
:test/env
{}

;; Test runner - local and CI
;; call with :watch? true to start file watcher and re-run tests on saved changes
:test/run
{:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
Expand All @@ -69,20 +61,12 @@
:exec-fn kaocha.runner/exec-fn
:exec-args {:randomize? false
:fail-fast? false}}
;; ------------

;; ------------
;; tools.build `build.clj` built script
:build/task
{:replace-paths ["."]
:replace-deps {io.github.clojure/tools.build {:mvn/version "0.10.5"}}
:replace-deps {io.github.clojure/tools.build {:mvn/version "0.10.6"}}
:ns-default build}
;; ------------

;; ------------
;; Updating dependencies with clojure -M:antq --upgrade
:antq
{:deps {com.github.liquidz/antq {:mvn/version "2.10.1241"}}
{:deps {com.github.liquidz/antq {:mvn/version "2.11.1264"}}
:main-opts ["-m" "antq.core"]}}}
;; ------------
;; ---------------------------------------------------------
Loading

0 comments on commit 3afe7f6

Please sign in to comment.