Use Stuart Sierra reloaded workflow
This commit is contained in:
parent
8ef1522c1e
commit
7b3b509eaf
4 changed files with 52 additions and 9 deletions
25
dev/user.clj
Normal file
25
dev/user.clj
Normal file
|
@ -0,0 +1,25 @@
|
|||
(ns user
|
||||
(:require [grub.core :as system]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[clojure.pprint :refer (pprint)]
|
||||
[clojure.repl :refer :all]
|
||||
[clojure.test :as test]
|
||||
[clojure.tools.namespace.repl :refer (refresh refresh-all)]))
|
||||
|
||||
(def system nil)
|
||||
|
||||
(defn start
|
||||
"Starts the current development system."
|
||||
[]
|
||||
(alter-var-root #'system system/start system/dev-config))
|
||||
|
||||
(defn stop
|
||||
"Shuts down and destroys the current development system."
|
||||
[]
|
||||
(alter-var-root #'system
|
||||
(fn [s] (when s (system/stop s)))))
|
||||
|
||||
(defn reset []
|
||||
(stop)
|
||||
(refresh :after 'user/start))
|
|
@ -21,7 +21,10 @@
|
|||
[com.cognitect/transit-clj "0.8.259"]
|
||||
[com.cognitect/transit-cljs "0.8.188"]]
|
||||
:profiles {:uberjar {:aot :all}
|
||||
:dev {:dependencies [[midje "1.6.3"]]}}
|
||||
:dev {:source-paths ["dev"]
|
||||
:dependencies [[midje "1.6.3"]
|
||||
[org.clojure/tools.namespace "0.2.3"]
|
||||
[org.clojure/java.classpath "0.2.0"]]}}
|
||||
:min-lein-version "2.1.2"
|
||||
:plugins [[lein-cljsbuild "1.0.3"]
|
||||
[lein-ring "0.8.6"]
|
||||
|
|
|
@ -40,11 +40,13 @@
|
|||
|
||||
(def prod-config
|
||||
{:index prod-index-page
|
||||
:database-name "grub"})
|
||||
:db {:name "grub"}
|
||||
:port 3000})
|
||||
|
||||
(def dev-config
|
||||
{:index dev-index-page
|
||||
:database-name "grub-dev"})
|
||||
:db {:name "grub-dev"}
|
||||
:port 3000})
|
||||
|
||||
(defn handle-websocket [handler]
|
||||
(fn [{:keys [websocket?] :as request}]
|
||||
|
@ -69,12 +71,21 @@
|
|||
(handle-root index)
|
||||
(handle-websocket)))
|
||||
|
||||
(defn start [{:keys [port database-name] :as config}]
|
||||
(defn start [current {:keys [port db] :as config}]
|
||||
(let [to-db (chan)
|
||||
db (db/connect-and-handle-events to-db database-name)]
|
||||
(state/init-server to-db (db/get-current-state db))
|
||||
(println "Starting server on localhost:" port)
|
||||
(httpkit/run-server (make-handler config) {:port port})))
|
||||
db (db/connect-and-handle-events to-db (:name db))
|
||||
states (state/init-server to-db (db/get-current-state (:db db)))
|
||||
stop-server (httpkit/run-server (make-handler config) {:port port})]
|
||||
(println "Started server on localhost:" port)
|
||||
(assoc config
|
||||
:db (merge (:db config) db)
|
||||
:stop-server stop-server
|
||||
:states states)))
|
||||
|
||||
(defn stop [{:keys [db stop-server] :as system}]
|
||||
(stop-server)
|
||||
(db/disconnect (:conn db))
|
||||
system)
|
||||
|
||||
(defn usage [options-summary]
|
||||
(->> ["Usage: grub [options] action"
|
||||
|
|
|
@ -30,4 +30,8 @@
|
|||
(do (update-db! db state)
|
||||
(recur))
|
||||
(println "Database disconnected")))
|
||||
db))
|
||||
{:conn conn
|
||||
:db db}))
|
||||
|
||||
(defn disconnect [conn]
|
||||
(m/disconnect conn))
|
||||
|
|
Loading…
Reference in a new issue