Skip to content

Commit

Permalink
Do the reloading workflow via tools.namespace stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
zk committed Jan 7, 2014
1 parent 2ecfcf3 commit 0157a45
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Procfile.dev
@@ -1,7 +1,7 @@
web: lein repl :headless
web: lein with-profile +nrepl repl :headless
sass: sass --watch src/scss:resources/public/css
cljs: lein trampoline cljsbuild auto dev
mongo: mongod

# Refresh 1st tab of chrome when fs changes are seen
refresher: lein run -m tools.refresher chrome src/clj src/md resources
refresher: lein run -m tools.refresher chrome src/md resources
39 changes: 39 additions & 0 deletions dev/user.clj
@@ -0,0 +1,39 @@
(ns user
(:require [clojure.tools.namespace.repl
:refer (refresh refresh-all)]
[clojuredocs.main]
[clojure.java.shell :as sh]))

(defn refresh-chrome
"Refreshes first tab of chrome"
[]
(->> ["osascript"
"tell application \"Google Chrome\" to tell the first tab of its first window"
"reload"
"end tell"]
(interpose "-e")
(apply sh/sh)))

(defonce system nil)

(defn init []
(alter-var-root #'system
(constantly (clojuredocs.main/create-app))))

(defn start []
(alter-var-root #'system clojuredocs.main/start))

(defn stop []
(alter-var-root #'system
(fn [s]
(when s
(clojuredocs.main/stop s)))))

(defn go []
(init)
(start)
(refresh-chrome))

(defn restart []
(stop)
(refresh :after 'user/go))
12 changes: 8 additions & 4 deletions project.clj
Expand Up @@ -22,10 +22,14 @@
[mysql/mysql-connector-java "5.1.25"]
#_[lein-light-nrepl "0.0.9"]
[congomongo "0.4.1"]
[unk "0.9.1"]]
:repl-options {:init (do (require 'clojuredocs.main)
(clojuredocs.main/-main))
:port 7888
[unk "0.9.1"]
[cljsbuild "1.0.1"]
[org.clojure/core.async "0.1.267.0-0d7780-alpha"]
[org.clojure/core.logic "0.8.5"]]
:profiles {:nrepl {:source-paths ["dev"]
:dependencies [[org.clojure/tools.namespace "0.2.4"]]
:repl-options {:init (user/restart)}}}
:repl-options {:port 7888
:nrepl-middleware [#_lighttable.nrepl.handler/lighttable-ops]}
:plugins [[lein-cljsbuild "1.0.0"]] ;; required for heroku deploy
:cljsbuild {:builds
Expand Down
36 changes: 23 additions & 13 deletions src/clj/clojuredocs/main.clj
@@ -1,17 +1,10 @@
(ns clojuredocs.main
(:require [ring.adapter.jetty :as jetty]
[aleph.http :as ah]
(:require [aleph.http :as ah]
[somnium.congomongo :as mon]
[clojuredocs.env :as env]
[clojuredocs.entry :as entry]
[clojuredocs.config :as config]))

(mon/set-connection!
(mon/make-connection (env/str :mongo-url)))

(mon/add-index! :examples [:ns :name :library-url])
(mon/add-index! :vars [:ns :name :library-url])

(defn start-http-server [entry-point opts]
(ah/start-http-server
(ah/wrap-ring-handler
Expand All @@ -38,10 +31,27 @@
(println)
#_(System/exit 1))))

(defn create-app []
{:port (env/int :port 8080)
:entry entry/routes
:mongo-url (env/str :mongo-url)})

(defn start [{:keys [port mongo-url entry] :as opts}]
(mon/set-connection! (mon/make-connection mongo-url))
(mon/add-index! :examples [:ns :name :library-url])
(mon/add-index! :vars [:ns :name :library-url])
(let [stop-server (start-http-server entry
{:port port :join? false})]
(println (format "Server running on port %d" port))
(merge
opts
{:stop-server stop-server})))

(defn stop [{:keys [stop-server] :as opts}]
(when stop-server
@(stop-server))
(dissoc opts :stop-server))

(defn -main []
(valid-env-or-exit)
(let [port (env/int :port 8080)]
(start-http-server
(var entry/routes)
{:port port :join? false})
(println (format "Server running on port %d" port))))
(start (create-app)))

0 comments on commit 0157a45

Please sign in to comment.