Added Luminus app skeleton; added ADL.
This commit is contained in:
parent
8a923c1b33
commit
f3c0e728a4
52 changed files with 1761 additions and 0 deletions
77
env/dev/clj/pastoralist/core.clj
vendored
Normal file
77
env/dev/clj/pastoralist/core.clj
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
(ns pastoralist.core
|
||||
(:require
|
||||
[pastoralist.handler :as handler]
|
||||
[pastoralist.nrepl :as nrepl]
|
||||
[luminus.http-server :as http]
|
||||
[luminus-migrations.core :as migrations]
|
||||
[pastoralist.config :refer [env]]
|
||||
[clojure.tools.cli :refer [parse-opts]]
|
||||
[clojure.tools.logging :as log]
|
||||
[mount.core :as mount])
|
||||
(:gen-class))
|
||||
|
||||
;; log uncaught exceptions in threads
|
||||
(Thread/setDefaultUncaughtExceptionHandler
|
||||
(reify Thread$UncaughtExceptionHandler
|
||||
(uncaughtException [_ thread ex]
|
||||
(log/error {:what :uncaught-exception
|
||||
:exception ex
|
||||
:where (str "Uncaught exception on" (.getName thread))}))))
|
||||
|
||||
(def cli-options
|
||||
[["-p" "--port PORT" "Port number"
|
||||
:parse-fn #(Integer/parseInt %)]])
|
||||
|
||||
(mount/defstate ^{:on-reload :noop} http-server
|
||||
:start
|
||||
(http/start
|
||||
(-> env
|
||||
(assoc :handler (handler/app))
|
||||
(update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
|
||||
(update :port #(or (-> env :options :port) %))))
|
||||
:stop
|
||||
(http/stop http-server))
|
||||
|
||||
(mount/defstate ^{:on-reload :noop} repl-server
|
||||
:start
|
||||
(when (env :nrepl-port)
|
||||
(nrepl/start {:bind (env :nrepl-bind)
|
||||
:port (env :nrepl-port)}))
|
||||
:stop
|
||||
(when repl-server
|
||||
(nrepl/stop repl-server)))
|
||||
|
||||
|
||||
(defn init-jndi []
|
||||
(System/setProperty "java.naming.factory.initial"
|
||||
"org.apache.naming.java.javaURLContextFactory")
|
||||
(System/setProperty "java.naming.factory.url.pkgs"
|
||||
"org.apache.naming"))
|
||||
|
||||
(defn start-app [args]
|
||||
(init-jndi)
|
||||
(doseq [component (-> args
|
||||
(parse-opts cli-options)
|
||||
mount/start-with-args
|
||||
:started)]
|
||||
(log/info component "started"))
|
||||
(.addShutdownHook (Runtime/getRuntime) (Thread. handler/destroy)))
|
||||
|
||||
(defn -main [& args]
|
||||
(mount/start #'pastoralist.config/env)
|
||||
(cond
|
||||
(nil? (:database-url env))
|
||||
(do
|
||||
(log/error "Database configuration not found, :database-url environment variable must be set before running")
|
||||
(System/exit 1))
|
||||
(some #{"init"} args)
|
||||
(do
|
||||
(migrations/init (select-keys env [:database-url :init-script]))
|
||||
(System/exit 0))
|
||||
(migrations/migration? args)
|
||||
(do
|
||||
(migrations/migrate args (select-keys env [:database-url]))
|
||||
(System/exit 0))
|
||||
:else
|
||||
(start-app args)))
|
||||
|
||||
11
env/dev/clj/pastoralist/dev_middleware.clj
vendored
Normal file
11
env/dev/clj/pastoralist/dev_middleware.clj
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(ns pastoralist.dev-middleware
|
||||
(:require
|
||||
[ring.middleware.reload :refer [wrap-reload]]
|
||||
[selmer.middleware :refer [wrap-error-page]]
|
||||
[prone.middleware :refer [wrap-exceptions]]))
|
||||
|
||||
(defn wrap-dev [handler]
|
||||
(-> handler
|
||||
wrap-reload
|
||||
wrap-error-page
|
||||
(wrap-exceptions {:app-namespaces ['pastoralist]})))
|
||||
15
env/dev/clj/pastoralist/env.clj
vendored
Normal file
15
env/dev/clj/pastoralist/env.clj
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
(ns pastoralist.env
|
||||
(:require
|
||||
[selmer.parser :as parser]
|
||||
[clojure.tools.logging :as log]
|
||||
[pastoralist.dev-middleware :refer [wrap-dev]]))
|
||||
|
||||
(def defaults
|
||||
{:init
|
||||
(fn []
|
||||
(parser/cache-off!)
|
||||
(log/info "\n-=[pastoralist started successfully using the development profile]=-"))
|
||||
:stop
|
||||
(fn []
|
||||
(log/info "\n-=[pastoralist has shut down successfully]=-"))
|
||||
:middleware wrap-dev})
|
||||
12
env/dev/clj/pastoralist/figwheel.clj
vendored
Normal file
12
env/dev/clj/pastoralist/figwheel.clj
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
(ns pastoralist.figwheel
|
||||
(:require [figwheel-sidecar.repl-api :as ra]))
|
||||
|
||||
(defn start-fw []
|
||||
(ra/start-figwheel!))
|
||||
|
||||
(defn stop-fw []
|
||||
(ra/stop-figwheel!))
|
||||
|
||||
(defn cljs []
|
||||
(ra/cljs-repl))
|
||||
|
||||
64
env/dev/clj/user.clj
vendored
Normal file
64
env/dev/clj/user.clj
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
(ns user
|
||||
"Userspace functions you can run by default in your local REPL."
|
||||
(:require
|
||||
[pastoralist.config :refer [env]]
|
||||
[clojure.pprint]
|
||||
[clojure.spec.alpha :as s]
|
||||
[expound.alpha :as expound]
|
||||
[mount.core :as mount]
|
||||
[pastoralist.figwheel :refer [start-fw stop-fw cljs]]
|
||||
[pastoralist.core :refer [start-app]]
|
||||
[pastoralist.db.core]
|
||||
[conman.core :as conman]
|
||||
[luminus-migrations.core :as migrations]))
|
||||
|
||||
(alter-var-root #'s/*explain-out* (constantly expound/printer))
|
||||
|
||||
(add-tap (bound-fn* clojure.pprint/pprint))
|
||||
|
||||
(defn start
|
||||
"Starts application.
|
||||
You'll usually want to run this on startup."
|
||||
[]
|
||||
(mount/start-without #'pastoralist.core/repl-server))
|
||||
|
||||
(defn stop
|
||||
"Stops application."
|
||||
[]
|
||||
(mount/stop-except #'pastoralist.core/repl-server))
|
||||
|
||||
(defn restart
|
||||
"Restarts application."
|
||||
[]
|
||||
(stop)
|
||||
(start))
|
||||
|
||||
(defn restart-db
|
||||
"Restarts database."
|
||||
[]
|
||||
(mount/stop #'pastoralist.db.core/*db*)
|
||||
(mount/start #'pastoralist.db.core/*db*)
|
||||
(binding [*ns* 'pastoralist.db.core]
|
||||
(conman/bind-connection pastoralist.db.core/*db* "sql/queries.sql")))
|
||||
|
||||
(defn reset-db
|
||||
"Resets database."
|
||||
[]
|
||||
(migrations/migrate ["reset"] (select-keys env [:database-url])))
|
||||
|
||||
(defn migrate
|
||||
"Migrates database up for all outstanding migrations."
|
||||
[]
|
||||
(migrations/migrate ["migrate"] (select-keys env [:database-url])))
|
||||
|
||||
(defn rollback
|
||||
"Rollback latest database migration."
|
||||
[]
|
||||
(migrations/migrate ["rollback"] (select-keys env [:database-url])))
|
||||
|
||||
(defn create-migration
|
||||
"Create a new up and down migration file with a generated timestamp and `name`."
|
||||
[name]
|
||||
(migrations/create name (select-keys env [:database-url])))
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue