Skip to content
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

Add output-dir option #65

Merged
merged 1 commit into from Mar 24, 2016
Merged
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
12 changes: 7 additions & 5 deletions src/adzerk/boot_reload.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
(adzerk.boot-reload.server/send-visual!
~messages))))

(defn- send-changed! [pod asset-path changed]
(defn- send-changed! [pod asset-path cljs-asset-path changed]
(when-not (empty? changed)
(pod/with-call-in pod
(adzerk.boot-reload.server/send-changed!
~(get-env :target-path)
~asset-path
{:target-path ~(get-env :target-path)
:asset-path ~asset-path
:cljs-asset-path ~cljs-asset-path}
~changed))))

(defn- add-init!
Expand Down Expand Up @@ -98,7 +99,8 @@
;; Other Configuration
j on-jsload SYM sym "The callback to call when JS files are reloaded. (optional)"
_ asset-host HOST str "The asset-host where to load files from. Defaults to host of opened page. (optional)"
a asset-path PATH str "The asset-path. This is removed from the start of reloaded urls. (optional)"
a asset-path PATH str "Sets the output directory for temporary files used during compilation. (optional)"
c cljs-asset-path PATH str "The actual asset path. This is added to the start of reloaded urls. (optional)"
o open-file COMMAND str "The command to run when warning or exception is clicked on HUD. Passed to format. (optional)"
v disable-hud bool "Toggle to disable HUD. Defaults to false (visible)."]

Expand Down Expand Up @@ -141,6 +143,6 @@
; Only send changed files when there are no warnings
; As prev is updated only when changes are sent, changes are queued untill they can be sent
(when (empty? warnings)
(send-changed! @pod asset-path (changed @prev fileset static-files))
(send-changed! @pod asset-path cljs-asset-path (changed @prev fileset static-files))
(reset! prev fileset))
fileset))))))
30 changes: 18 additions & 12 deletions src/adzerk/boot_reload/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@
(defn set-options [opts]
(reset! options opts))

(defn web-path [protocol rel-path tgt-path asset-path]
(if-not (= "file:" protocol)
(str "/"
(if asset-path
(string/replace rel-path (re-pattern (str "^" (string/replace asset-path #"^/" "") "/")) "")
rel-path))
(.getCanonicalPath (io/file tgt-path rel-path))))
(defn web-path
([rel-path] (web-path {} rel-path))
([opts rel-path]
(let [{:keys [protocol target-path asset-path cljs-asset-path]} opts]
(if (= "file:" protocol)
(.getCanonicalPath (io/file target-path rel-path))
(str
(if cljs-asset-path (str cljs-asset-path "/") "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Deraen @esessoms I think this introduced a bug: paths are no longer starting with / breaking reloading from pushState locations. Should this line perhaps be:

(str cljs-asset-path "/" ...)

So that the slash is always present?

(string/replace rel-path
(re-pattern (str "^" (string/replace (or asset-path "") #"^/" "") "/"))
""))))))

(defn send-visual! [messages]
(doseq [[channel _] @clients]
(http/send! channel (pr-str (merge {:type :visual}
messages)))))

(defn send-changed! [tgt-path asset-path changed]
(doseq [[channel {:keys [protocol]}] @clients]
(http/send! channel
(pr-str {:type :reload
:files (map #(web-path protocol % tgt-path asset-path) changed)}))))
(defn send-changed!
([changed] (send-changed! {} changed))
([opts changed]
(doseq [[channel {:keys [protocol]}] @clients]
(http/send! channel
(pr-str {:type :reload
:files (map #(web-path (assoc opts :protocol protocol) %) changed)})))))

(defmulti handle-message (fn [channel message] (:type message)))

Expand Down
18 changes: 12 additions & 6 deletions test/adzerk/boot_reload/server_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@

(deftest web-path-test
(testing "Basic"
(is (= "/js/out/saapas/core.js"
(web-path "http:" "js/out/saapas/core.js" "target" nil))))
(is (= "js/out/saapas/core.js"
(web-path {:protocol "http:" :target-path "target"} "js/out/saapas/core.js"))))

(testing "Asset-path"
(is (= "js/out/saapas/core.js"
(web-path "http:" "public/js/out/saapas/core.js" nil "public")))
(web-path {:protocol "http:" :asset-path "public"} "public/js/out/saapas/core.js")))

(is (= "js/out/saapas/core.js"
(web-path "http:" "public/js/out/saapas/core.js" nil "/public")))
(web-path {:protocol "http:" :asset-path "/public"} "public/js/out/saapas/core.js")))

(is (= "public/js/out/saapas/core.js"
(web-path "http:" "public/js/out/saapas/core.js" nil "foobar")))
))
(web-path {:protocol "http:" :asset-path "foobar"} "public/js/out/saapas/core.js"))))

(testing "Cljs-asset-path"
(is (= "js/saapas.out/saapas/core.js"
(web-path {:protocol "http:"
:asset-path "resources/public/js/saapas.out"
:cljs-asset-path "js/saapas.out"}
"resources/public/js/saapas.out/saapas/core.js")))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a real use case?

Writing files to resources directory doesn't make much sense, and even if it was the target directory it wouldn't make much sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same use case whether or not the "resources/" is there.