PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/atompit/devbuild.clj

https://gitlab.com/wunderwaffle/atompit
Clojure | 59 lines | 53 code | 6 blank | 0 comment | 1 complexity | de1df8b9e7b245b1fb23ea20f3296219 MD5 | raw file
  1. (ns atompit.devbuild
  2. (:require [clojure.java.io :as io]
  3. [me.raynes.conch.low-level :as sh]
  4. [hawk.core :as hawk]
  5. [com.stuartsierra.component :as c]
  6. [cljs.build.api :as cljs]
  7. [figwheel-sidecar.repl-api :as ra]))
  8. (def dev-build
  9. {:id "dev"
  10. :source-paths ["src" "dev" "test"]
  11. :compiler {:output-to "target/main.js"
  12. :output-dir "target/main.out"
  13. :asset-path "/static/main.out"
  14. :devcards true
  15. :main 'atompit.start
  16. :optimizations :none
  17. :source-map true
  18. :source-map-timestamp true}})
  19. (def prod-build
  20. {:id "prod"
  21. :source-paths ["src"]
  22. :compiler {:output-to "target/prod/main.js"
  23. :output-dir "target/prod.out"
  24. :main 'atompit.fe
  25. :optimizations :advanced
  26. :compiler-stats true}})
  27. (defn sh [& args]
  28. (let [proc (apply sh/proc args)]
  29. (future (sh/stream-to proc :out (System/out)))
  30. (future (sh/stream-to proc :err (System/err)))
  31. proc))
  32. (defn start-figwheel! []
  33. (ra/start-figwheel!
  34. {:figwheel-options {:open-file-command "figwheel-open"
  35. :css-dirs ["target"]}
  36. :all-builds [dev-build]
  37. :build-ids ["dev"]})
  38. (ra/cljs-repl))
  39. (defn start-sass! [src dst]
  40. (let [src-path (-> src io/resource .getPath)
  41. dst-path (-> (str "target/" dst) io/file .getAbsolutePath)
  42. compile (fn [_ _]
  43. (println "Compiling SCSS...")
  44. (sh "sassc" "-m" src-path dst-path))]
  45. (hawk/watch!
  46. [{:paths ["resources/scss"]
  47. :filter (fn [_ {:keys [file]}]
  48. (and (.isFile file)
  49. (re-find #".scss$" (.getName file))))
  50. :handler compile}])
  51. (compile nil nil)))
  52. (defn cljs-build [{:keys [source-paths compiler]}]
  53. (cljs/build (apply cljs/inputs source-paths) compiler))