Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Boot: Build tooling for Clojure(script)

Boot: Build tooling for Clojure(script)

Talk given at ClojureD in Berlin in January 2015.

mklappstuhl

January 24, 2015
Tweet

More Decks by mklappstuhl

Other Decks in Programming

Transcript

  1. Hi

    View Slide

  2. WHAT'S BOOT?

    View Slide

  3. WHY ANOTHER
    BUILD TOOL?

    View Slide

  4. View Slide

  5. <br/>(page "index.html"<br/>(:refer-clojure :exclude [nth])<br/>;; A lot more ClojureScript<br/>








    View Slide

  6. NO ABSTRACTIONS FOR
    BUILD PROCESSES

    View Slide

  7. TIME PASSES...

    View Slide

  8. 2.0

    View Slide

  9. HOW

    View Slide

  10. TASKS
    ABSTRACTIONS FOR
    BUILD PROCESSES

    View Slide

  11. ;; build.boot
    (set-env!
    :source-paths #{"src"}
    :dependencies
    '[[pandeiro/boot-http "0.4.2"]
    ...])
    (require
    '[pandeiro.boot-http :refer [serve]]
    ...)
    (deftask run []
    (comp (serve) ; serve files
    (speak) ; audible notifications
    (watch) ; trigger new builds
    (cljs-repl) ; cljs REPL - hah!
    (reload) ; Figwheel style reloading
    (build)))

    View Slide

  12. ;; build.boot
    (set-env!
    :source-paths #{"src"}
    :dependencies
    '[[pandeiro/boot-http "0.4.2"]
    ...])
    (require
    '[pandeiro.boot-http :refer [serve]]
    ...)
    (deftask build []
    (comp (cljx)
    (cljs)
    (garden)))
    (deftask run []
    (comp (serve) ; serve files
    (speak) ; audible notifications
    (watch) ; trigger new builds
    (cljs-repl) ; cljs REPL - hah!
    (reload) ; Figwheel style reloading
    (build)))

    View Slide

  13. COMPOSE ALL THE THINGS

    View Slide

  14. BUT...
    SIDE EFFECTS
    EVERYWHERE?

    View Slide

  15. FILESET
    FILES AS VALUES

    View Slide

  16. DEPENDENCY
    ISOLATION

    View Slide

  17. PODS
    ISOLATED CLOJURE
    RUNTIMES

    View Slide

  18. TWO MORE QUICK THINGS

    View Slide

  19. TASK OPTIONS
    (boot (cljs :optimizations :advanced)) ; REPL

    View Slide

  20. TASK OPTIONS
    (boot (cljs :optimizations :advanced)) ; REPL
    CLI <> REPL SYMMETRY
    boot serve watch cljs -O advanced # SHELL
    (boot (serve) (watch) (cljs :optimizations :advanced)) ; REPL

    View Slide

  21. Demo

    View Slide

  22. (ns boot-garden.core
    {:boot/export-tasks true}
    (:require [clojure.java.io :as io]
    [boot.core :as boot :refer [deftask]]
    [boot.pod :as pod]
    [boot.file :as file]
    [boot.util :as util]))
    (def initial
    (atom true))
    (defn add-dep [env dep]
    (update-in env [:dependencies] (fnil conj []) dep))
    (defn ns-tracker-pod []
    (pod/make-pod (assoc-in (boot/get-env) [:dependencies] '[[ns-tracker "0.2.2"]])))
    (defn garden-pool []
    (pod/pod-pool (add-dep (boot/get-env) '[garden "1.2.5"])
    :init (fn [pod] (pod/require-in pod 'garden.core))))
    (deftask garden
    "compile garden"
    [o output-to PATH str "The output css file path relative to docroot."
    s styles-var SYM sym "The var containing garden rules"
    p pretty-print bool "Pretty print compiled CSS"
    v vendors [str] "Vendors to apply prefixed for"
    a auto-prefix [str] "Properties to auto-prefix with vendor-prefixes"]
    (let [output-path (or output-to "main.css")
    css-var styles-var
    ns-sym (symbol (namespace css-var))
    tmp (boot/temp-dir!)
    out (io/file tmp output-path)
    src-paths (vec (boot/get-env :source-paths))
    garden-pods (garden-pool)
    ns-pod (ns-tracker-pod)]
    (pod/with-eval-in ns-pod
    (require 'ns-tracker.core)
    (def cns (ns-tracker.core/ns-tracker ~src-paths)))
    (boot/with-pre-wrap fileset
    (when (or @initial (some #{ns-sym} (pod/with-eval-in ns-pod (cns))))
    (let [c-pod (garden-pods :refresh)]
    (if @initial (reset! initial false))
    (util/info "Compiling %s...\n" (.getName out))
    (io/make-parents out)
    (pod/with-eval-in c-pod
    (require '~ns-sym)
    (garden.core/css {:output-to ~(.getPath out)
    :pretty-print ~pretty-print
    :vendors ~vendors
    :auto-prefix ~(set auto-prefix)} ~css-var))))
    (-> fileset (boot/add-resource tmp) boot/commit!))))

    View Slide

  23. (ns boot-garden.core
    {:boot/export-tasks true}
    (:require [clojure.java.io :as io]
    [boot.core :as boot :refer [deftask]]
    [boot.pod :as pod]
    [boot.file :as file]
    [boot.util :as util]))

    View Slide

  24. ;; (ns boot-garden.core
    ;; {:boot/export-tasks true}
    ;; (:require [clojure.java.io :as io]
    ;; [boot.core :as boot :refer [deftask]]
    ;; [boot.pod :as pod]
    ;; [boot.file :as file]
    ;; [boot.util :as util]))
    (def initial
    (atom true))

    View Slide

  25. ;; ...
    ;; (def initial
    ;; (atom true))
    (defn add-dep [env dep]
    (update-in env [:dependencies] (fnil conj []) dep))
    (defn ns-tracker-pod []
    (pod/make-pod (assoc-in (boot/get-env) [:dependencies] '[[ns-tracker "0.2.2"]])))
    (defn garden-pool []
    (pod/pod-pool (add-dep (boot/get-env) '[garden "1.2.5"])
    :init (fn [pod] (pod/require-in pod 'garden.core))))

    View Slide

  26. ;; ...
    ;; (defn garden-pool []
    ;; (pod/pod-pool (add-dep (boot/get-env) '[garden "1.2.5"])
    ;; :init (fn [pod] (pod/require-in pod 'garden.core))))
    (deftask garden
    "compile garden"
    [o output-to PATH str "The output css file path relative to docroot."
    s styles-var SYM sym "The var containing garden rules"
    p pretty-print bool "Pretty print compiled CSS"
    v vendors [str] "Vendors to apply prefixed for"
    a auto-prefix [str] "Properties to auto-prefix with vendor-prefixes"]

    View Slide

  27. ;; ...
    ;; (deftask garden
    ;; "compile garden"
    ;; [o output-to PATH str "The output css file path relative to docroot."
    ;; s styles-var SYM sym "The var containing garden rules"
    ;; p pretty-print bool "Pretty print compiled CSS"
    ;; v vendors [str] "Vendors to apply prefixed for"
    ;; a auto-prefix [str] "Properties to auto-prefix with vendor-prefixes"]
    (let [output-path (or output-to "main.css")
    ns-sym (symbol (namespace styles-var))
    tmp (boot/temp-dir!)
    out (io/file tmp output-path)
    src-paths (vec (boot/get-env :source-paths))
    garden-pods (garden-pool)
    ns-pod (ns-tracker-pod)]

    View Slide

  28. ;; ...
    ;; (let [output-path (or output-to "main.css")
    ;; ns-sym (symbol (namespace styles-var))
    ;; tmp (boot/temp-dir!)
    ;; out (io/file tmp output-path)
    ;; src-paths (vec (boot/get-env :source-paths))
    ;; garden-pods (garden-pool)
    ;; ns-pod (ns-tracker-pod)]
    (pod/with-eval-in ns-pod
    (require 'ns-tracker.core)
    (def cns (ns-tracker.core/ns-tracker ~src-paths)))

    View Slide

  29. ;; ...
    ;; (pod/with-eval-in ns-pod
    ;; (require 'ns-tracker.core)
    ;; (def cns (ns-tracker.core/ns-tracker ~src-paths)))
    (boot/with-pre-wrap fileset
    (when (or @initial (some #{ns-sym} (pod/with-eval-in ns-pod (cns))))
    (let [c-pod (garden-pods :refresh)]
    (if @initial (reset! initial false))
    (util/info "Compiling %s...\n" (.getName out))
    (io/make-parents out)

    View Slide

  30. ;; ...
    ;; (boot/with-pre-wrap fileset
    ;; (when (or @initial (some #{ns-sym} (pod/with-eval-in ns-pod (cns))))
    ;; (let [c-pod (garden-pods :refresh)]
    ;; (if @initial (reset! initial false))
    ;; (util/info "Compiling %s...\n" (.getName out))
    ;; (io/make-parents out)
    (pod/with-eval-in c-pod
    (require '~ns-sym)
    (garden.core/css {:output-to ~(.getPath out)
    :pretty-print ~pretty-print
    :vendors ~vendors
    :auto-prefix ~(set auto-prefix)} ~css-var));))

    View Slide

  31. ;; ...
    ;; (boot/with-pre-wrap fileset
    ;; (when (or @initial (some #{ns-sym} (pod/with-eval-in ns-pod (cns))))
    ;; (let [c-pod (garden-pods :refresh)]
    ;; (if @initial (reset! initial false))
    ;; (util/info "Compiling %s...\n" (.getName out))
    ;; (io/make-parents out)
    ;; (pod/with-eval-in c-pod
    ;; (require '~ns-sym)
    ;; (garden.core/css {:output-to ~(.getPath out)
    ;; :pretty-print ~pretty-print
    ;; :vendors ~vendors
    ;; :auto-prefix ~(set auto-prefix)} ~css-var));))
    (-> fileset (boot/add-resource tmp) boot/commit!);)))

    View Slide

  32. Done!

    View Slide

  33. RESOURCES

    View Slide

  34. View Slide

  35. #HOPLON (IRC)

    View Slide

  36. TENZING
    lein new tenzing your-app

    View Slide

  37. FAZIT

    View Slide

  38. THANK YOU
    @martinklepsch

    View Slide

  39. QUESTIONS?
    @martinklepsch

    View Slide