score-the-pigs/dev/tasks.clj
2025-03-14 16:12:36 -04:00

45 lines
1.6 KiB
Clojure

(ns tasks
(:require [com.biffweb.task-runner :refer [run-task]]
[com.biffweb.tasks :as tasks]
[com.biffweb.tasks.lazy.babashka.fs :as fs]
[com.biffweb.tasks.lazy.babashka.process :refer [shell]]
[com.biffweb.tasks.lazy.clojure.java.io :as io]
[com.biffweb.tasks.lazy.com.biffweb.config :as config]))
(def config (delay (config/use-aero-config {:biff.config/skip-validation true})))
(defn dev
"Starts the app locally.
After running, wait for the `System started` message. Connect your editor to
nrepl port 7888 (by default). Whenever you save a file, Biff will:
- Evaluate any changed Clojure files
- Regenerate static HTML files
- Run tests"
[]
(if-not (fs/exists? "target/resources")
;; This is an awful hack. We have to run the app in a new process, otherwise
;; target/resources won't be included in the classpath. Downside of not
;; using bb tasks anymore -- no longer have a lightweight parent process
;; that can create the directory before starting the JVM.
(do
(io/make-parents "target/resources/_")
(shell "clj" "-M:dev" "dev"))
(let [{:keys [biff.tasks/main-ns biff.nrepl/port] :as _ctx} @config]
(when-not (fs/exists? "config.env")
(run-task "generate-config"))
(when (fs/exists? "package.json")
(shell "npm install"))
(spit ".nrepl-port" port)
((requiring-resolve (symbol (str main-ns) "-main"))))))
;; Tasks should be vars (#'hello instead of hello) so that `clj -M:dev help` can
;; print their docstrings.
(def custom-tasks
{"dev" #'dev})
(def tasks (merge tasks/tasks custom-tasks))
(comment tasks)