Skip to content

Commit

Permalink
Improve lein aliases (especially dev and repl), server and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
heralden committed Sep 27, 2019
1 parent 26a83ca commit 54c0617
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 25 deletions.
7 changes: 7 additions & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This namespace starts figwheel as part of the aliases:
;; lein dev
;; lein repl
(ns user
(:require [figwheel-sidecar.repl-api :refer [start-figwheel!]]))

(start-figwheel!)
27 changes: 20 additions & 7 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@
* Latest supported [npm](https://www.npmjs.com/)
* InterMine version 1.8+ (version 2.0 recommended)


## Download NPM dependencies

npm install

## Quickstart

These commands are explained in more depth below, but if you know what you want here's a quick reference of the most useful ones.

lein dev # start dev server with hot-reloading
lein repl # start dev server with hot-reloading and nrepl
lein prod # start prod server
lein deploy # build prod release and deploy to clojars

lein format # run cljfmt to fix code indentation
lein kaocha # run unit tests
npx cypress run # run cypress ui tests

## Running a dev environment

You can start a complete developer environment with automatic compilation of Less CSS and hot-reloading of code changes by running:
Expand Down Expand Up @@ -40,8 +52,10 @@ Note: even that you will not see a prompt telling you when it's complete, the br

### Make Leiningen reload code changes in the browser


lein figwheel dev

Note: if you use `lein run` or any alias calling it like `dev` or `repl`, Figwheel will be started automatically.

### Start the web server

Expand Down Expand Up @@ -91,9 +105,10 @@ Most of the time, we develop with uncompressed files - it's faster for hot reloa

Sometimes the Closure compiler is overzealous and removes something we actually wanted to keep. To check what your work looks like in a minified build, run this in the terminal (I'd recommend closing any existing lein run / lein figwheel sessions first).

lein cljsbuild once min + lein run
lein with-profile prod cljsbuild once min
lein with-profile prod run

There is also a shortcut:
There is also a shortcut that in addition cleans and compiles CSS.

lein prod

Expand Down Expand Up @@ -138,11 +153,9 @@ Official BlueGenes releases can be deployed to [Clojars](https://clojars.org/),

When deploying BlueGenes to Clojars, the JAR file should include all compiled assets: this includes JavaScript, less, and vendor libraries. This allows other projects to include BlueGenes as a dependency and deploy the client and server without needing to compile BlueGenes.

To deploy a compiled JAR to clojars, include the `uberjar` profile when running the `lein deploy clojars` command:

$ lein with-profile +uberjar deploy clojars

To deploy a compiled JAR to Clojars, simply use the `deploy` alias which automatically includes the `uberjar` profile and targets Clojars.

$ lein deploy

# Troubleshooting

Expand Down
24 changes: 15 additions & 9 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,21 @@
:cljfmt {:indents {wait-for [[:inner 0]]}}

:aliases {"dev" ["do" "clean"
["less" "once"]
["trampoline" "run"]
["trampoline" "figwheel" "dev"]]
["pdo"
["less" "auto"]
["run"]]]
"repl" ["do" "clean"
["pdo"
["less" "auto"]
["repl"]]]
"build" ["do" "clean"
["less" "once"]
["cljsbuild" "once" "min"]]
["with-profile" "prod" "cljsbuild" "once" "min"]]
"prod" ["do" "build"
["with-profile" "prod" "run"]]
"deploy" ["with-profile" "+uberjar" "deploy"]
"deploy" ["with-profile" "+uberjar" "deploy" "clojars"]
"format" ["cljfmt" "fix"]
"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]}
"kaocha" ["with-profile" "kaocha" "run" "-m" "kaocha.runner"]}

:min-lein-version "2.8.1"

Expand All @@ -112,18 +116,20 @@
:less {:source-paths ["less"]
:target-path "resources/public/css"}

:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]
:init (-main)}

:profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
[day8.re-frame/re-frame-10x "0.4.2"]
[figwheel-sidecar "0.5.19"]
[cider/piggieback "0.4.1"]]
:resource-paths ["config/dev" "tools" "config/defaults"]
:plugins [[lein-figwheel "0.5.19"]
[lein-doo "0.1.8"]]}
[lein-doo "0.1.8"]]
:source-paths ["dev"]}
:kaocha {:dependencies [[lambdaisland/kaocha "0.0-541"]
[lambdaisland/kaocha-cljs "0.0-59"]]}
:repl {:source-paths ["env/dev"]}
:repl {:source-paths ["dev"]}
:prod {:resource-paths ["config/prod" "tools" "config/defaults"]}
:uberjar {:resource-paths ["config/prod" "config/defaults"]
:prep-tasks ["build" "compile"]
Expand Down
27 changes: 18 additions & 9 deletions src/clj/bluegenes/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [bluegenes.handler :refer [handler]]
[config.core :refer [env]]
[ring.adapter.jetty :refer [run-jetty]]
[taoensso.timbre :as timbre :refer [infof errorf]])
[taoensso.timbre :as timbre :refer [infof]])
(:gen-class))

(defn ->int
Expand All @@ -13,13 +13,22 @@
(int? n) n
:else n))

(defonce web-server_ (atom nil))
(defn stop-web-server! [] (when-let [stop-fn @web-server_] (stop-fn)))
(defn start-web-server!
"Parses the port from the configuration file, environment variables, or default to 5000
(\"PORT\" is often the default value for app serving platforms such as Heroku and Dokku)
and start the Jetty server by passing in the URL routes defined in `handler`."
[]
(stop-web-server!)
(let [port (->int (or (:server-port env) (:port env) 5000))
server (run-jetty handler {:port port :join? false})
stop-fn #(.stop server)]
(infof "=== Bluegenes server started on port: %s" port)
(reset! web-server_ stop-fn)))

(defn -main
"Start the BlueGenes server. This is the main entry point for the application"
[& args]
; Parse the port from the configuration file, environment variables, or default to 5000
; "PORT" is often the default value for app serving platforms such as Heroku and Dokku
(let [port (->int (or (:server-port env) (:port env) 5000))]
(timbre/set-level! :info) ; Enable Logging
; Start the Jetty server by passing in the URL routes defined in 'handler'
(run-jetty handler {:port port :join? false})
(infof "=== Bluegenes server started on port: %s" port)))
[& _args]
(timbre/set-level! :info) ; Enable Logging
(start-web-server!))

0 comments on commit 54c0617

Please sign in to comment.