Skip to content

Instantly share code, notes, and snippets.

@maxp
Created August 23, 2020 07:07
Show Gist options
  • Save maxp/5607d56630c954acc45469b0c141c0dd to your computer and use it in GitHub Desktop.
Save maxp/5607d56630c954acc45469b0c141c0dd to your computer and use it in GitHub Desktop.
babashka based maker
#!/usr/bin/env bb
(require 'babashka.classpath)
(babashka.classpath/add-classpath "./tools")
(ns bmk.main
(:require
[bmk.core :refer [print-lines cmd sh-c]]))
;=
;; (def APP_NAME "bmk") ;; babashka based 'make' runner
(def DEV_RES "./build/dev")
(def PROD_RES "./build/prod")
(defn cssdev [_]
(let [publ (str DEV_RES "/public/")]
(cmd "mkdir" "-p" publ)
(sh-c (str "cp -r assets/* " publ))
(cmd "npx" "tailwindcss" "build" "assets/css/styles.css"
"-o" (str publ "css/styles.css"))))
;;
;; - - - - - - - - - - - - - - - - - - -
(declare COMMANDS)
(defn help [_]
(println "\nbmk <command>\n")
(doseq [c COMMANDS]
(println " " (:id c) "-" (:descr c)))
(println)
(System/exit 1))
;;
(def COMMANDS
[
{:id :help :handler help :descr "display help"}
{:id :cssdev :handler cssdev :descr "tailwind css processor in dev mode"}])
;;
(defn- find-command-handler [cmd]
(or
(some #(when (= cmd (:id %)) %) COMMANDS)
{:handler help}))
;-
;; - - - - - - - - - main - - - - - - - - - -
(defn main [args]
(let [arg1 (first args)
cmd (if (= \: (first arg1))
(keyword (subs arg1 1))
(keyword arg1))
;
{f :handler}
(find-command-handler cmd)]
;
(print-lines (f args))
(System/exit 0)))
;;
(main *command-line-args*)
;;.
; prod_assets:
; @echo "prod assets"
; @mkdir -p ${PROD_RES}/public
; @cp -r assets/* ${PROD_RES}/public
; tailwindcss: export NODE_ENV = production
; tailwindcss:
; @echo "build css"
; @npx tailwindcss build assets/css/styles.css -o ${PROD_RES}/public/css/styles.css
; build_js:
; @npx shadow-cljs release prod
; prodpack: prod_assets build_js tailwindcss
; @echo "prod: assets, js, css."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment