Skip to content

Instantly share code, notes, and snippets.

Last active January 25, 2023 23:52
What would you like to do?
Work bb.edn files
{:tasks {:requires ([babashka.fs :as fs])
:init (do (when (seq (fs/modified-since "deps.edn"
(shell {:dir ".."} "script/gen-deps.clj")))
;; Maintenance tasks
install {:doc "Install frontend dependencies from NPM"
:task (shell "npm install")}
clean {:doc "Clean all artifacts"
:task (do (fs/delete-tree "public/js")
(fs/delete-tree "public/css")
(fs/delete-tree "resources/vendor"))}
reqs {:doc "Check for Clojure dependencies that have newer versions"
:task (clojure "-M:outdated")}
;; Development tasks
dev-cljs {:depends [install]
:doc "Run frontend CLJS watcher"
:task (clojure "-M:frontend watch ontolog")}
dev-less {:depends [install]
:doc "Run frontend LESS watcher"
:task (shell "npm run dev")}
-dev {:depends [dev-cljs dev-less]}
dev {:doc "Run app in dev mode, watch CLJS and LESS files for changes"
:task (shell "bb run --parallel -dev")}
dev:clean {:doc "Run app in dev mode with clean slate"
:task (do (shell "bb clean")
(shell "bb dev"))}
;; Production build tasks
build-cljs {:depends [install]
:doc "Build production JS"
:task (clojure "-M:frontend release ontolog")}
build-less {:depends [install]
:doc "Build production CSS"
:task (shell "npm run release")}
-build {:depends [build-cljs build-less]}
build {:doc "Build all production files"
:task (do (shell "bb clean")
(shell "bb run --parallel -build"))}}}
;; NOTE: :tasks is an experimental feature in bb, still under development
;; Type bb tasks to see all tasks
;; Type bb <task-name> or bb run <task-name> to run a task
{:min-bb-version "0.3.7"
:paths ["script"]
:tasks {:requires ([babashka.fs :as fs])
:init (do (def platform-alias
(case (System/getProperty "")
"Mac OS X"
(when (seq (fs/modified-since "deps.edn"
(shell {:dir ".."} "script/gen-deps.clj")))
:leave (let [{:keys [:private :name]} (current-task)]
(when-not private
(binding [*out* *err*]
(println "✓" name))))
;; Helpers
clean {:doc "Cleans compiled assets."
(do (fs/delete-if-exists "frontend/public/js/app.js")
(fs/delete-tree "frontend/public/js/app.out")
(run! fs/delete-if-exists (fs/glob "frontend/public/css" "main*")))}
env {:doc "Prints environment using crispin using command line args as path."
:extra-deps {crispin/crispin {:mvn/version "0.3.8"}}
:requires ([crispin.core :as cc]
[clojure.edn :as edn])
:task (do
(cc/load-custom-cfg! "src/config.clj")
(prn (get-in (cc/cfg) (map edn/read-string *command-line-args*))))}
;; Development tasks
dev {:doc "Runs app in dev mode. Compiles cljs, less and runs JVM app in parallel."
:task (run '-dev {:parallel true})}
dev:clean {:doc "Runs dev task from clean slate."
:task (do (run 'clean)
(run 'dev))}
-dev {:depends [dev:cljs dev:less dev:backend]}
dev:cljs {:doc "Runs front-end compilation"
:task (clojure "-M:frontend:cljs/dev")}
dev:less {:doc "Compiles less"
:task (clojure "-M:frontend:less/dev")}
dev:backend {:doc "Runs backend in dev mode"
:task (clojure (str "-A:backend:backend/dev:" platform-alias)
"-X" "dre.standalone/start")}
;; Deployment
deploy:build {:doc "Builds production CLJS, less and app"
:task (shell "script/build")}
;; Running tests
test {:doc "Runs backend tests"
:task (clojure "-M:backend:test")}
;; DB migration
{:doc "Usage: up (default) / down."
:task (case (first *command-line-args*)
("up" nil)
(clojure "-X:backend:task dre.task.migrate/migrate :command up")
"-X:backend:task dre.task.migrate/migrate :command down :force true"))}
{:doc "Add migration file with title as first command line arg"
:task (clojure
"-A:backend -M -e" "(require '[migratus.core :as migratus])"
"-e" (format "(migratus/create {:migration-dir \"resources/migrations\"} \"%s\")"
(first *command-line-args*)))}
;; Publication types
pubtypes {:doc "Prints map of publication types. Used in names.cljs."
:task pubtypes/label-map}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment