Skip to content

Commit afff4b8

Browse files
Josef Pospíšilarichiardi
authored andcommitted
Separate tasks for cljs devtools and dirac
* Separate tasks for cljs devtools and dirac * Fix cljs-devtools task * Change cljs-devtools and dirac versions in README * Add both separated tasks to README * Fix formatting and versions in README * Refactor preloads' adding Also removed redundant make-parents
1 parent 40ead05 commit afff4b8

2 files changed

Lines changed: 59 additions & 16 deletions

File tree

README.org

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,57 @@
11
* boot-cljs-devtools
22
** About
3-
[[https://github.com/boot-clj/boot][Boot]] task introducing enhancements to CLJS development in Chrome, specifically [[https://github.com/binaryage/cljs-devtools][CLJS DevTools]] and [[https://github.com/binaryage/dirac][Dirac]].
3+
[[https://github.com/boot-clj/boot][Boot]] tasks introducing enhancements to CLJS development in Chrome, specifically [[https://github.com/binaryage/cljs-devtools][CLJS DevTools]] and [[https://github.com/binaryage/dirac][Dirac]].
44
** Installation
55
Latest version:
66

77
[[https://clojars.org/powerlaces/boot-cljs-devtools][https://img.shields.io/clojars/v/powerlaces/boot-cljs-devtools.svg]]
88

99
In order to install it, add the following to your =build.boot= dependencies:
1010
#+BEGIN_SRC clojure
11-
[binaryage/devtools "0.8.2" :scope "test"]
12-
[binaryage/dirac "0.7.1" :scope "test"]
11+
[binaryage/devtools "X.X.X" :scope "test"] ;; when you want cljd-devtools or both, replace X.X.X for current version
12+
[binaryage/dirac "X.X.X" :scope "test"] ;; when you want dirac or both, replace X.X.X for current version
1313
[powerlaces/boot-cljs-devtools "0.X.X" :scope "test"]
1414
[org.clojure/clojurescript "1.9.293"] ;; see below
1515
#+END_SRC
1616
Note that boot-cljs-devtools requires ClojureScript version 1.9.89 or later for its =:preloads= feature.
1717

18-
In addition require the task, specifically =cljs-devtools=.
18+
In addition require the task, specifically =cljs-devtools=:
1919
#+BEGIN_SRC clojure
2020
(require '[powerlaces.boot-cljs-devtools :refer [cljs-devtools]])
2121
#+END_SRC
22+
23+
or specifically =dirac=:
24+
#+BEGIN_SRC clojure
25+
(require '[powerlaces.boot-cljs-devtools :refer [dirac]])
26+
#+END_SRC
27+
28+
or both =cljs-devtools= and =dirac=:
29+
#+BEGIN_SRC clojure
30+
(require '[powerlaces.boot-cljs-devtools :refer [cljs-devtools dirac]])
31+
#+END_SRC
32+
2233
Currently files may be generated in the =out= directory, so it would be advisable to add that to someplace like in a =.gitignore=.
2334
** Usage
2435
Ensure that this task runs before the =cljs= and after the =watch= task and that you include a =.cljs.edn= file according to [[https://github.com/adzerk-oss/boot-cljs/wiki/Usage#multiple-builds][this]].
25-
Task example:
36+
37+
Task example for cljs-devtools:
2638
#+BEGIN_SRC clojure
2739
(deftask dev []
2840
(comp (watch) (cljs-devtools) (cljs)))
2941
#+END_SRC
42+
43+
Task example for dirac:
44+
#+BEGIN_SRC clojure
45+
(deftask dev []
46+
(comp (watch) (dirac) (cljs)))
47+
#+END_SRC
48+
49+
Task example for both cljs-devtools and dirac:
50+
#+BEGIN_SRC clojure
51+
(deftask dev []
52+
(comp (watch) (cljs-devtools) (dirac) (cljs)))
53+
#+END_SRC
54+
3055
File =your-ns.cljs.edn= example:
3156
#+BEGIN_SRC clojure
3257
{:require [your-ns.core]

src/powerlaces/boot_cljs_devtools.clj

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010
(def ^:private deps '#{binaryage/devtools binaryage/dirac})
1111

12-
(defn- add-preloads! [in-file out-file]
13-
(let [preloads ['devtools.preload 'dirac.runtime.preload]
14-
spec (-> in-file slurp read-string)]
12+
(def ^:private preloads {:cljs-devtools 'devtools.preload :dirac 'dirac.runtime.preload})
13+
14+
(defn- add-preload! [lib in-file out-file]
15+
(let [spec (-> in-file slurp read-string)
16+
preload (get preloads lib)]
1517
(when (not= :nodejs (-> spec :compiler-options :target))
1618
(util/info
1719
"Adding :preloads %s to %s...\n"
18-
preloads (.getName in-file))
20+
preload (.getName in-file))
1921
(io/make-parents out-file)
2022
(-> spec
21-
(update-in [:compiler-options :preloads] #(into preloads %))
23+
(update-in [:compiler-options :preloads] #(conj % preload))
2224
pr-str
2325
((partial spit out-file))))))
2426

@@ -52,10 +54,27 @@
5254
:middleware ['dirac.nrepl/middleware]})
5355

5456
(boot/deftask cljs-devtools
55-
"Add Chrome Devtool enhancements for ClojureScript development."
56-
[b ids BUILD_IDS #{str} "Only inject devtools into these builds (= .cljs.edn files)"
57-
n nrepl-opts NREPL_OPTS edn "Options passed to boot's `repl` task."
58-
d dirac-opts DIRAC_OPTS edn "Options passed to dirac."]
57+
"Add Chrome cljs-devtools enhancements for ClojureScript development."
58+
[b ids BUILD_IDS #{str} "Only inject devtools into these builds (= .cljs.edn files)"]
59+
(let [tmp (boot/tmp-dir!)
60+
prev (atom nil)]
61+
(comp
62+
(boot/with-pre-wrap fileset
63+
(doseq [f (relevant-cljs-edn @prev fileset ids)]
64+
(let [path (boot/tmp-path f)
65+
in-file (boot/tmp-file f)
66+
out-file (io/file tmp path)]
67+
(add-preload! :cljs-devtools in-file out-file)))
68+
(reset! prev fileset)
69+
(-> fileset
70+
(boot/add-resource tmp)
71+
(boot/commit!))))))
72+
73+
(boot/deftask dirac
74+
"Add dirac enhancements for ClojureScript development."
75+
[b ids BUILD_IDS #{str} "Only inject devtools into these builds (= .cljs.edn files)"
76+
n nrepl-opts NREPL_OPTS edn "Options passed to boot's `repl` task."
77+
d dirac-opts DIRAC_OPTS edn "Options passed to dirac."]
5978
(let [tmp (boot/tmp-dir!)
6079
prev (atom nil)
6180
nrepl-opts (cond-> (merge nrepl-defaults nrepl-opts)
@@ -75,8 +94,7 @@
7594
(let [path (boot/tmp-path f)
7695
in-file (boot/tmp-file f)
7796
out-file (io/file tmp path)]
78-
(io/make-parents out-file)
79-
(add-preloads! in-file out-file)))
97+
(add-preload! :dirac in-file out-file)))
8098
(reset! prev fileset)
8199
(-> fileset
82100
(boot/add-resource tmp)

0 commit comments

Comments
 (0)