Skip to content
Permalink
Browse files

Merge branch 'feature/nodejs-working-directory' of https://github.com…

…/eploko/prerenderer into eploko-feature/nodejs-working-directory
  • Loading branch information...
pupeno committed Dec 11, 2015
2 parents 5f1efc0 + e0a0775 commit 191ba4f679c9d24d9c29b36ced4c359cb5d6807e
Showing with 27 additions and 12 deletions.
  1. +8 −0 README.md
  2. +19 −12 src/clj/prerenderer/core.clj
@@ -140,6 +140,13 @@ request to `localhost:3000`. You can define both of this by passing `:default-aj
For an actual example of this, look at [Ninja Tool's core.clj, around line 23](https://github.com/carouselapps/ninjatools/blob/master/src/clj/ninjatools/core.clj#L23).
You want them to point to where the Clojure server is running. In many cases for example, the port will be random.
Also, you may want to specify the working directory for the Node.js process like this:
```clojure
(reset! js-engine (prerenderer/run {:path "js/server-side.js"
:working-directory "target"})))
```
After that, prerendering happens by simply doing:
```clojure
@@ -305,6 +312,7 @@ to your uberjar profile. You can get some background about this issue in
### v0.2.0
- Changed the ClojureScript API to hide NodeJS details.
- New re-frame implementation that depends on re-frame 0.6.0 but not on a fork.
- Added an option to specify the working directory for the JavaScript engine.
- Added Function to stop JavaScript engine.
- Renamed run to start! to match stop!
- Added option :noop-when-stopped that will make prerenderer just issue a warning when the JavaScript engine is not
@@ -10,16 +10,19 @@
(defn ensure-javascript-exists
([js-engine] (ensure-javascript-exists js-engine false))
([js-engine notify-about-file-appearing]
(if (not (.exists (io/as-file (:path js-engine))))
(let [message (str "File " (:path js-engine) " for prerendering is not present. Did you compile your JavaScript? 'lein cljsbuild auto' maybe?")]
(if (:wait js-engine)
(do
(println message "Waiting until it appears...")
(Thread/sleep 100)
(recur js-engine true))
(throw (Exception. message))))
(when notify-about-file-appearing
(println "File" (:path js-engine) "appeared. Pfiuuu!")))))
(let [path (:path js-engine)
working-directory (:working-directory js-engine ".")
full-path (.getAbsolutePath (java.io.File. working-directory path))]
(if-not (.exists (io/as-file full-path))
(let [message (str "File " full-path " for prerendering is not present. Did you compile your JavaScript? 'lein cljsbuild auto' maybe?")]
(if (:wait js-engine)
(do
(println message "Waiting until it appears...")
(Thread/sleep 100)
(recur js-engine true))
(throw (Exception. message))))
(when notify-about-file-appearing
(println "File" full-path "appeared. Pfiuuu!"))))))

(defn read-port-file [js-engine]
(slurp (:port-file js-engine)))
@@ -59,7 +62,8 @@
"--port-file" (:port-file js-engine)
"--default-ajax-host" (:default-ajax-host js-engine)
"--default-ajax-port" (str (:default-ajax-port js-engine))])
.inheritIO))
.inheritIO
(.directory (io/file (:working-directory js-engine)))))

(defn start! [options]
(let [js-engine (merge {:path nil
@@ -70,10 +74,13 @@
.deleteOnExit))
:start-timeout 5000
:wait false
:noop-when-stopped false}
:noop-when-stopped false
:working-directory "."}
options)]
(if (nil? (:path js-engine))
(throw (Exception. "Path should be specified when starting a pre-rendering engine.")))
(if-not (.exists (io/as-file (:working-directory js-engine)))
(throw (Exception. "Working directory should exist when starting a pre-rendering engine.")))
(ensure-javascript-exists js-engine)
(blank-port-file! js-engine)
(let [process (.start (create-process-builder js-engine))

0 comments on commit 191ba4f

Please sign in to comment.
You can’t perform that action at this time.