Skip to content

Add bb tasks and update deps #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:lint-as {reagent.core/with-let clojure.core/let}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ profiles.clj
/resources/public/js/*
/resources/public/css/*
.DS_Store
.vnodeenv/
.vpyenv/
80 changes: 80 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{:paths ["bb"]
:deps {org.babashka/http-server {:mvn/version "0.1.11"}
org.babashka/cli {:mvn/version "0.7.53"}}
:pods {clj-kondo/clj-kondo {:version "2023.01.20"}}
:tasks
{:requires ([babashka.cli :as cli]
[babashka.fs :as fs]
[pod.borkdude.clj-kondo :as clj-kondo])
:init
(do
(def lint-paths
["bb.edn" "deps.edn" "bb" "src"]))

hooks
{:doc "Hook related commands"
:requires ([git-hooks :as gh])
:task (apply gh/hooks *command-line-args*)}

clean
(shell "rm -rf .vpyenv .vnodeenv node_modules")

lint
{:doc "Lint all code directories with clj-kondo."
:task (do (clj-kondo/print!
(clj-kondo/run! {:lint lint-paths}))
(clojure "-Ttools install-latest :lib io.github.weavejester/cljfmt :as cljfmt")
(clojure (str "-Tcljfmt check :paths '" (prn-str lint-paths) "'")))}

format
{:doc "Format all code with cljfmt."
:task (do (clojure "-Ttools install-latest :lib io.github.weavejester/cljfmt :as cljfmt")
(clojure (str "-Tcljfmt fix :paths '" (prn-str lint-paths) "'")))}

upgrade
{:doc "Upgrade all code with antq."
:task (do (clojure "-Ttools install-latest :lib com.github.liquidz/antq :as antq")
(clojure "-Tantq outdated :check-clojure-tools true :upgrade true"))}

watson
{:doc "Scan for vulnerable direct/transitive dependencies with clj-watson."
:task (do (clojure "-Ttools install-latest :lib io.github.clj-holmes/clj-watson :as clj-watson")
(clojure "-Tclj-watson scan '{:output \"stdout\" :dependency-check-properties nil :fail-on-result true :deps-edn-path \"deps.edn\" :suggest-fix true :aliases [\"*\"] :database-strategy \"dependency-check\"}'"))}

-vpyenv-install
(if-not (fs/exists? ".vpyenv")
(do
(shell "python3 -m venv .vpyenv")
(shell "bash -c" "source .vpyenv/bin/activate && pip install -q --upgrade pip")))

-vnodeenv-install
{:depends [-vpyenv-install]
:task (if-not (fs/exists? ".vpyenv/bin/nodeenv")
(shell "bash -c" "source .vpyenv/bin/activate && pip install -q nodeenv"))}

-node-install
{:depends [-vnodeenv-install]
:task (if-not (fs/exists? ".vnodeenv")
(shell "bash -c" "source .vpyenv/bin/activate && nodeenv -q .vnodeenv"))}

-npm-install
{:depends [-node-install]
:task (shell "bash -c" "source .vnodeenv/bin/activate && npm install -q")}

build
{:depends [-npm-install]
:doc "Runs build for clojurescript + tailwind."
:task (do
(shell "bash -c 'source .vnodeenv/bin/activate && npx browserslist@latest --update-db'")
(shell "bash -c 'source .vnodeenv/bin/activate && npm audit fix'")
(shell "bash -c 'source .vnodeenv/bin/activate && npm run build'"))}

watch
{:depends [build]
:doc "Runs start for `shadow-cljs` with `watch` option."
:task (shell "bash -c 'source .vnodeenv/bin/activate && npm start'")}

styles-watch
{:depends [build]
:doc "Runs styles-watch for tailwind with autorebuild."
:task (shell "bash -c 'source .vnodeenv/bin/activate && npm run styles-watch'")}}}
62 changes: 62 additions & 0 deletions bb/git_hooks.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(ns git-hooks
(:require
[babashka.fs :as fs]
[babashka.pods :as pods]
[babashka.tasks :as tasks]
[clojure.java.shell :refer [sh]]
[clojure.string :as str]))

(pods/load-pod "clj-kondo")
(require '[pod.borkdude.clj-kondo :as clj-kondo])

(defn ^:private changed-files
[]
(->> (sh "git" "diff" "--name-only" "--cached" "--diff-filter=ACM")
:out
str/split-lines
(filter seq)
seq))

(def ^:private clj-extensions
#{"clj" "cljx" "cljc" "cljs" "edn"})

(defn ^:private clj?
[s]
(when s
(let [extension (last (str/split s #"\."))]
(clj-extensions extension))))

(defn ^:private hook-text
[hook]
(format "#!/bin/sh
# Installed by babashka task on %s

bb hooks %s" (java.util.Date.) hook))

(defn ^:private spit-hook
[hook]
(println "Installing hook: " hook)
(let [file (str ".git/hooks/" hook)]
(spit file (hook-text hook))
(fs/set-posix-file-permissions file "rwx------")
(assert (fs/executable? file))))

(defmulti hooks
"Multimethod for Git hook commands"
(fn [& args] (first args)))

(defmethod hooks "install" [& _]
(tasks/clojure "-Ttools install-latest :lib io.github.weavejester/cljfmt :as cljfmt")
(spit-hook "pre-commit"))

(defmethod hooks "pre-commit" [& _]
(println "Running pre-commit hook")
(when-let [files (changed-files)]
;; clojure
(when-let [clj-files (seq (filter clj? files))]
(clj-kondo/print!
(clj-kondo/run! {:lint clj-files}))
(tasks/clojure (str "-Tcljfmt check :paths '" (prn-str clj-files) "'")))))

(defmethod hooks :default [& args]
(println "Unknown command:" (first args)))
25 changes: 17 additions & 8 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{:paths ["src" "resources"]

:deps
{markdown-clj/markdown-clj {:mvn/version "1.10.8"}
metosin/reitit {:mvn/version "0.5.16"}
org.babashka/sci {:mvn/version "0.3.0"}
reagent/reagent {:mvn/version "1.1.0"}
thheller/shadow-cljs {:mvn/version "2.17.3"}}

{markdown-clj/markdown-clj {:mvn/version "1.11.7"
exclusions [org.yaml/snakeyaml]}
metosin/reitit {:mvn/version "0.6.0"}
org.clojure/clojure {:mvn/version "1.11.1"}
org.babashka/sci {:mvn/version "0.8.40"}
reagent/reagent {:mvn/version "1.2.0"}
thheller/shadow-cljs {:mvn/version "2.26.0"
:exclusions [com.fasterxml.jackson.core/jackson-databind
com.google.guava/guava
commons-fileupload/commons-fileupload]}
com.fasterxml.jackson.core/jackson-databind #:mvn{:version "2.16.0-rc1"}
com.google.guava/guava #:mvn{:version "32.1.3-jre"}
commons-fileupload/commons-fileupload #:mvn{:version "1.5"}
org.yaml/snakeyaml {:mvn/version "2.2"}}

:aliases
{:dev
{:extra-deps {cider/cider-nrepl {:mvn/version "0.28.2"}}}}}
{:extra-deps {cider/cider-nrepl {:mvn/version "0.43.3"}}}}}
Loading