#+SETUPFILE: setup.org * boot.properties ~boot.properties~ file is used by *Boot* to link your *Clojure/ClojureScript* project to a particular version of *Boot* executing by a particular version of *Clojure*. #+NAME: boot.properties #+BEGIN_SRC sh :tangle ../boot.properties :noweb yes #http://boot-clj.com #<> BOOT_CLOJURE_NAME=org.clojure/clojure BOOT_CLOJURE_VERSION=<> BOOT_VERSION=<> #+END_SRC * build.boot ~build.boot~ file is executed by *Boot* upon running the following command src_sh{boot task}, where ~task~ is a name of *Boot-task* to execute. Project's tasks are defined below in a corresponding sections. #+NAME: build.boot #+BEGIN_SRC clojure :tangle ../build.boot :noweb yes :exports none (require '[clojure.java.io :refer [file]]) <> <> <> <> <> <> <> #+END_SRC Setting up corresponding project directories if they are defined in [[#project-specification][the project specification table]] and exist on build machine disk. #+NAME: set-project-paths #+BEGIN_SRC clojure (def paths [ [:source-paths "<>"] [:source-paths "<>"] [:resource-paths "<>"] [:asset-paths "<>"] ] ) (doseq [[ env-key path ] paths] (if (and (seq path) (not ((get-env env-key) path))) (let [dir (file path)] (if (.isDirectory dir) (set-env! env-key #(conj % (.getName dir))))))) #+END_SRC If dependency from *Clojure* is defined in [[#project-specification][the project specification table]], i.e. value ~yes~ is given against parameter ~Clojure~, than adding ~org.clojure/clojure~ dependency. #+NAME: set-project-clojure-dependency #+BEGIN_SRC clojure (set-env! :dependencies #(conj % '[org.clojure/clojure "<>"])) #+END_SRC If dependency from *ClojureScript* is defined in [[#project-specification][the project specification table]], i.e. value ~yes~ is given against parameter ~ClojureScript~, than adding ~org.clojure/clojurescript~ dependency. #+NAME: set-project-clojurescript-dependency #+BEGIN_SRC clojure (set-env! :dependencies #(conj % '[org.clojure/clojurescript "<>"])) #+END_SRC Adding project dependencies defined in [[#project-dependencies][the project dependencies table]]. #+NAME: set-project-user-dependencies #+BEGIN_SRC clojure (let [deps '[ <> ]] (set-env! :dependencies #(into % deps))) #+END_SRC ** Clojure related project's Boot-tasks These tasks will be added into resulting ~build.boot~ file, if ~Clojure~ parameter is set to ~yes~ in [[#project-specification][the project specification table]] All blocks of code defining *Boot-tasks* for *Clojure* must have ~boot-clojure-task~ name. Each task defined in code block with ~boot-clojure-task~ name will be added into resulting ~build.boot~ file. #+NAME: boot-clojure-tasks #+BEGIN_SRC clojure :noweb yes :exports none <> #+END_SRC *** clj-build :PROPERTIES: :CUSTOM_ID: clj-build :END: This task builds project's uberjar which might be run with src_sh[:dir ".." :noweb yes]{java -jar <>/project.jar} #+NAME: boot-clojure-task #+BEGIN_SRC clojure (deftask clj-build "Builds project's uberjar" [] (comp (pom :project '<> :version "<>") (aot :all true) (uber) (jar :main '<>.<>) (target :dir #{"<>"}))) #+END_SRC To execute the task run: src_sh[:dir ".."]{boot clj-build} *** clj-run This task executes project's ~main~ function in the *Boot's* *Java* environment. #+NAME: boot-clojure-task #+BEGIN_SRC clojure (deftask clj-run "Runs the project's main function" [] (require '<>.<>) (let [main-fn (resolve '<>.<>/-main)] (comp (aot :all true) (with-pass-thru _ (main-fn))))) #+END_SRC To execute the task run: src_sh[:dir ".."]{boot clj-run} ** ClojureScript related project's Boot-tasks These tasks will be added into resulting ~build.boot~ file, if ~ClojureScript~ parameter is set to ~yes~ in [[#project-specification][the project specification table]] All blocks of code defining *Boot-tasks* for *Clojure* must have ~boot-clojurescript-task~ name. Each task defined in a code block with ~boot-clojurescript-task~ name will be added into resulting ~build.boot~ file. #+NAME: boot-clojurescript-tasks #+BEGIN_SRC clojure :noweb yes :exports none <> #+END_SRC *** cljs-figwheel This task is an interface to *[[https://github.com/bhauman/lein-figwheel][figwheel]]*, to execute it run src_sh[:dir "."]{boot cljs-figwheel}.\\ The task compiles *ClojureScript* files, runs HTTP-server serving project's public resources directory, runs changes monitor and automaticaly recompiles and reloads the project upon ~*.cljs~ files change, runs *nRepl* server. To run a *ClojureScript* *repl* one has to go through "9 steps to success": 1. run src_sh{boot cljs-figwheel} 2. wait for *Clojure* *repl* prompt 3. look for address and port of a run web-server (usually http://localhost:3449) in the console output 4. open a browser, novigate to web-server address:port URL, open browser's developer tools console and make sure there's "Opened Websocket REPL connection" message present 5. look address and port of a *nRepl* server, in the console output and pass it to ~(cider-connect)~ call at the next step 6. execute src_emacs-lisp{(cider-connect HOST PORT)} or ~M-x cider-connect~ and input *nRepl* HOST and PORT, though, it appears as if *cider* is able to take the values needed from ~.nrepl-port~ file, so one can just press ENTER twice 7. execute src_clojure{(cljs-repl)} in *repl*-buffer to run a *ClojureScript* *REPL* 8. execute src_clojure{(.log js/console "OK!")} in *repl*-buffer and make sure there's "OK!" message present in the brower's developer tools console. 9. done! #+NAME: boot-clojurescript-task #+BEGIN_SRC clojure (set-env! :dependencies #(into % '[[ajchemist/boot-figwheel "0.5.4-6" :scope "test"] [org.clojure/tools.nrepl "0.2.12" :scope "test"] [com.cemerick/piggieback "0.2.1" :scope "test"] [figwheel-sidecar "0.5.7" :scope "test"]])) (require '[boot-figwheel :refer [figwheel start-figwheel! stop-figwheel! start-autobuild stop-autobuild cljs-repl fig-status]]) ;; This is for (cider-connect) to work. ;; NOTE: do not use (cider-jack-in), use (cider-connect) instead ;; --------------------------- ;; Start of cider related code (swap! boot.repl/*default-dependencies* concat '[[cider/cider-nrepl "<>"]]) (swap! boot.repl/*default-middleware* conj 'cider.nrepl/cider-middleware) ;; End of cider related code (deftask cljs-figwheel "Compiles ClojureScript, serves it, autobuilds" [] (comp (figwheel :build-ids ["dev"] ;:once-build ["advanced"] :all-builds [{:id "dev" :source-paths (seq (get-env :source-paths)) :compiler {:main '<>.<> :optimizations :none :source-map true :output-to "app.js"} :figwheel {:build-id "dev" :on-jsload '<>.<>/-main :heads-up-display true :autoload true :debug false}}] :figwheel-options {:http-server-root "public" :open-file-command "emacsclient" :repl false} :target-path "<>") (speak) (repl))) #+END_SRC ** User's Boot-tasks All code blocks defining user's *Boot-tasks* must have ~boot-user-task~ name. Each tasks defined in a code block with ~boot-user-task~ name will be included into resulting ~build.boot~ file.