Skip to content

Commit 1c84022

Browse files
committed
Add bb tasks and update deps
1 parent 47c448f commit 1c84022

File tree

9 files changed

+239
-1644
lines changed

9 files changed

+239
-1644
lines changed

.clj-kondo/config.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:lint-as {reagent.core/with-let clojure.core/let}}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ profiles.clj
2424
/resources/public/js/*
2525
/resources/public/css/*
2626
.DS_Store
27+
.vnodeenv/
28+
.vpyenv/

bb.edn

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{:paths ["bb"]
2+
:deps {org.babashka/http-server {:mvn/version "0.1.11"}
3+
org.babashka/cli {:mvn/version "0.7.51"}}
4+
:pods {clj-kondo/clj-kondo {:version "2023.01.20"}}
5+
:tasks
6+
{:requires ([babashka.cli :as cli]
7+
[babashka.fs :as fs]
8+
[pod.borkdude.clj-kondo :as clj-kondo])
9+
:init
10+
(do
11+
(def lint-paths
12+
["bb.edn" "deps.edn" "bb" "src"]))
13+
14+
hooks
15+
{:doc "Hook related commands"
16+
:requires ([git-hooks :as gh])
17+
:task (apply gh/hooks *command-line-args*)}
18+
19+
clean
20+
(shell "rm -rf .vpyenv .vnodeenv node_modules")
21+
22+
lint
23+
{:doc "Lint all code directories with clj-kondo."
24+
:task (do (clj-kondo/print!
25+
(clj-kondo/run! {:lint lint-paths}))
26+
(clojure (str "-Tcljfmt check :paths '" (prn-str lint-paths) "'")))}
27+
28+
format
29+
{:doc "Format all code with cljfmt."
30+
:task (do (clojure "-Ttools install-latest :lib io.github.weavejester/cljfmt :as cljfmt")
31+
(clojure (str "-Tcljfmt fix :paths '" (prn-str lint-paths) "'")))}
32+
33+
upgrade
34+
{:doc "Upgrade all code with antq."
35+
:task (do (clojure "-Ttools install-latest :lib com.github.liquidz/antq :as antq")
36+
(clojure "-Tantq outdated :check-clojure-tools true :upgrade true"))}
37+
38+
watson
39+
{:doc "Scan for vulnerable direct/transitive dependencies with clj-watson."
40+
:task (do (clojure "-Ttools install-latest :lib io.github.clj-holmes/clj-watson :as clj-watson")
41+
(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\"}'"))}
42+
43+
-vpyenv-install
44+
(if-not (fs/exists? ".vpyenv")
45+
(do
46+
(shell "python3 -m venv .vpyenv")
47+
(shell "bash -c" "source .vpyenv/bin/activate && pip install -q --upgrade pip")))
48+
49+
-vnodeenv-install
50+
{:depends [-vpyenv-install]
51+
:task (if-not (fs/exists? ".vpyenv/bin/nodeenv")
52+
(shell "bash -c" "source .vpyenv/bin/activate && pip install -q nodeenv"))}
53+
54+
-node-install
55+
{:depends [-vnodeenv-install]
56+
:task (if-not (fs/exists? ".vnodeenv")
57+
(shell "bash -c" "source .vpyenv/bin/activate && nodeenv -q .vnodeenv"))}
58+
59+
-npm-install
60+
{:depends [-node-install]
61+
:task (shell "bash -c" "source .vnodeenv/bin/activate && npm install -q")}
62+
63+
build
64+
{:depends [-npm-install]
65+
:doc "Runs build for clojurescript + tailwind."
66+
:task (do
67+
(shell "bash -c 'source .vnodeenv/bin/activate && npx browserslist@latest --update-db'")
68+
(shell "bash -c 'source .vnodeenv/bin/activate && npm run build'"))}
69+
70+
watch
71+
{:depends [build]
72+
:doc "Runs start for `shadow-cljs` with `watch` option."
73+
:task (shell "bash -c 'source .vnodeenv/bin/activate && npm start'")}
74+
75+
styles-watch
76+
{:depends [build]
77+
:doc "Runs styles-watch for tailwind with autorebuild."
78+
:task (shell "bash -c 'source .vnodeenv/bin/activate && npm run styles-watch'")}}}

bb/git_hooks.clj

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(ns git-hooks
2+
(:require
3+
[babashka.fs :as fs]
4+
[babashka.pods :as pods]
5+
[babashka.tasks :as tasks]
6+
[clojure.java.shell :refer [sh]]
7+
[clojure.string :as str]))
8+
9+
(pods/load-pod "clj-kondo")
10+
(require '[pod.borkdude.clj-kondo :as clj-kondo])
11+
12+
(defn ^:private changed-files
13+
[]
14+
(->> (sh "git" "diff" "--name-only" "--cached" "--diff-filter=ACM")
15+
:out
16+
str/split-lines
17+
(filter seq)
18+
seq))
19+
20+
(def ^:private clj-extensions
21+
#{"clj" "cljx" "cljc" "cljs" "edn"})
22+
23+
(defn ^:private clj?
24+
[s]
25+
(when s
26+
(let [extension (last (str/split s #"\."))]
27+
(clj-extensions extension))))
28+
29+
(defn ^:private hook-text
30+
[hook]
31+
(format "#!/bin/sh
32+
# Installed by babashka task on %s
33+
34+
bb hooks %s" (java.util.Date.) hook))
35+
36+
(defn ^:private spit-hook
37+
[hook]
38+
(println "Installing hook: " hook)
39+
(let [file (str ".git/hooks/" hook)]
40+
(spit file (hook-text hook))
41+
(fs/set-posix-file-permissions file "rwx------")
42+
(assert (fs/executable? file))))
43+
44+
(defmulti hooks
45+
"Multimethod for Git hook commands"
46+
(fn [& args] (first args)))
47+
48+
(defmethod hooks "install" [& _]
49+
(tasks/clojure "-Ttools install-latest :lib io.github.weavejester/cljfmt :as cljfmt")
50+
(spit-hook "pre-commit"))
51+
52+
(defmethod hooks "pre-commit" [& _]
53+
(println "Running pre-commit hook")
54+
(when-let [files (changed-files)]
55+
;; clojure
56+
(when-let [clj-files (seq (filter clj? files))]
57+
(clj-kondo/print!
58+
(clj-kondo/run! {:lint clj-files}))
59+
(tasks/clojure (str "-Tcljfmt check :paths '" (prn-str clj-files) "'")))))
60+
61+
(defmethod hooks :default [& args]
62+
(println "Unknown command:" (first args)))

deps.edn

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
{:paths ["src" "resources"]
2-
2+
33
:deps
4-
{markdown-clj/markdown-clj {:mvn/version "1.10.8"}
5-
metosin/reitit {:mvn/version "0.5.16"}
6-
org.babashka/sci {:mvn/version "0.3.0"}
7-
reagent/reagent {:mvn/version "1.1.0"}
8-
thheller/shadow-cljs {:mvn/version "2.17.3"}}
9-
4+
{markdown-clj/markdown-clj {:mvn/version "1.11.4"
5+
exclusions [org.yaml/snakeyaml]}
6+
metosin/reitit {:mvn/version "0.6.0"}
7+
org.babashka/sci {:mvn/version "0.7.39"}
8+
reagent/reagent {:mvn/version "1.2.0"}
9+
thheller/shadow-cljs {:mvn/version "2.23.3"
10+
:exclusions [commons-fileupload/commons-fileupload
11+
io.undertow/undertow-core
12+
org.jboss.xnio/xnio-api
13+
org.jboss.xnio/xnio-nio]}
14+
commons-fileupload/commons-fileupload #:mvn{:version "1.5"}
15+
io.undertow/undertow-core #:mvn{:version "2.3.7.Final"}
16+
org.jboss.xnio/xnio-api #:mvn{:version "3.8.9.Final"}
17+
org.jboss.xnio/xnio-nio #:mvn{:version "3.8.9.Final"}
18+
org.yaml/snakeyaml {:mvn/version "2.0"}}
19+
1020
:aliases
1121
{:dev
12-
{:extra-deps {cider/cider-nrepl {:mvn/version "0.28.2"}}}}}
22+
{:extra-deps {cider/cider-nrepl {:mvn/version "0.30.0"}}}}}

0 commit comments

Comments
 (0)