Babashka and Scripting

Babashka starts in milliseconds and includes many libraries (http-client, cheshire, fs, process, core.async, tools.cli). Pods extend it (databases, AWS, etc.). nbb runs ClojureScript scripts on Node.js; joyride scripts VS Code.

#!/usr/bin/env bb
;; count-lines.clj: native, fast-starting Clojure scripting (GraalVM)
(require '[clojure.java.io :as io]
         '[babashka.fs :as fs]
         '[babashka.process :refer [shell process]]
         '[clojure.string :as str])

(doseq [f (fs/glob "." "**.clj")]
  (println (str f) (count (str/split-lines (slurp (str f))))))

(shell "git status")                                    ; run a process
(-> (process ["ls" "-la"] {:out :string}) deref :out println)
(println (System/getenv "HOME"))
(println *command-line-args*)
;; bb.edn: project tasks (a Makefile replacement)
{:tasks
 {test {:doc "Run tests" :task (shell "clojure -X:test")}
  lint (shell "clj-kondo --lint src test")
  build {:depends [test] :task (shell "clojure -T:build uber")}}}
;; bb test, bb build, bb tasks