Skip to content

Fix NullPointerException when processing externs files #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ same options as Figwheel.
:optimizations :none}}]}}
```

By default the library only takes into account files ending in ".css"
when processing the directories specified in the `:css-dirs` key. If
you want to process other files as CSS files, you can add the
`:css-files-pattern` key and specify a string that will be used as a
regular expression that the relevant files have to match.

Similarly only files ending in ".cljs" or "cljc" will be taken into
account when processing the directories specified in the
`:source-paths` key. Again, you can add a `:source-files-pattern` key
and specify a string that will be used as a regular expression that
the relevant files have to match. In this case, you need to specify
the key for each build you specify in the `:builds` vector.

Here is an example with the default patterns:

```edn
{:duct.server/figwheel
{:css-dirs ["dev/resources"]
:css-files-pattern "\\.css$"
:builds [{:id :dev
:source-paths ["src"]
:source-files-pattern "\\.clj[sc]$"
:build-options {:output-to "target/js/public/main.js"
:output-dir "target/js/public"
:optimizations :none}}]}}
```

See the [Figwheel README][] for more information.

[figwheel readme]: https://github.com/bhauman/lein-figwheel/blob/master/README.md
Expand Down
29 changes: 21 additions & 8 deletions src/duct/server/figwheel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
[org.httpkit.server :as httpkit]
[ring.middleware.cors :as cors]))

(def ^:const default-source-files-pattern "\\.clj[sc]$")
(def ^:const default-css-files-pattern "\\.css$")

(defrecord FigwheelBuild [])

(defrecord FigwheelServer []
Expand Down Expand Up @@ -51,8 +54,11 @@
server (figwheel-server state)]
(map->FigwheelServer (assoc state :http-server server))))

(defn- find-files [paths]
(mapcat (comp file-seq io/file) paths))
(defn- find-files [{:keys [paths files-pattern]}]
(let [files (mapcat (comp file-seq io/file) paths)]
(if files-pattern
(filter #(re-find (re-pattern files-pattern) (.getPath %)) files)
files)))

(defn- watch-paths [paths]
(let [time (volatile! 0)]
Expand All @@ -63,11 +69,14 @@
(vreset! time now)
(filter #(> (.lastModified %) then) (find-files paths)))))))

(defn- prep-build [{:keys [compiler-env source-paths] :as build}]
(defn- prep-build [{:keys [compiler-env source-paths source-files-pattern] :as build}]
(-> build
(dissoc :source-files-pattern)
(cond-> (not (fig-config/prepped? build)) fig-config/prep-build)
(cond-> (not compiler-env) fig-build/add-compiler-env)
(assoc :watcher (watch-paths source-paths))
(assoc :watcher (watch-paths {:paths source-paths
:files-pattern (or source-files-pattern
default-source-files-pattern)}))
(map->FigwheelBuild)))

(defn- clean-build [build]
Expand All @@ -83,8 +92,8 @@
"Tell a Figwheel server to rebuild all ClojureScript source files, and to
send the new code to the connected clients."
[{:keys [server prepped]}]
(doseq [{:keys [source-paths] :as build} prepped]
(let [files (map str (find-files source-paths))]
(doseq [{:keys [source-paths source-files-pattern] :as build} prepped]
(let [files (map str (find-files {:path source-paths, :files-pattern source-files-pattern}))]
(fig-util/clean-cljs-build* build)
(start-build build server files))))

Expand All @@ -101,10 +110,14 @@
[{:keys [server css-watch]}]
(fig-css/handle-css-notification {:figwheel-server server} (css-watch)) nil)

(defmethod ig/init-key :duct.server/figwheel [_ {:keys [builds css-dirs] :as opts}]
(defmethod ig/init-key :duct.server/figwheel [_ {:keys [builds css-dirs css-files-pattern] :as opts}]
(doto {:server (start-figwheel-server opts)
:prepped (mapv prep-build builds)
:css-watch (if css-dirs (watch-paths css-dirs) (fn []))}
:css-watch (if css-dirs
(watch-paths {:paths css-dirs
:files-pattern (or css-files-pattern
default-css-files-pattern)})
(fn []))}
(build-cljs)
(refresh-css)))

Expand Down