Skip to content

Commit 4956781

Browse files
committed
Update README
1 parent 12f8d47 commit 4956781

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,73 @@ At this point in Emacs you'll see this pop up:
181181

182182
For other editors connect to the given port manually.
183183

184+
## Writing custom steps
185+
186+
Launchpad performs a number of steps, currently these are
187+
188+
- `read-deps-edn` : Read in `deps.edn`, `~/.clojure/deps.edn`, and `deps.local.edn`
189+
- `handle-cli-args` : Parse CLI arguments
190+
- `get-nrepl-port` : Figure out the nREPL port, either from a CLI argument or use a free port
191+
- `get-nrepl-bind` : Figure out which device to bind to
192+
- `compute-middleware` : Figure out the nREPL middleware to use (optionally CIDER, refactor-nrepl, and whatever else is configured)
193+
- `compute-extra-deps` : Add additional dependencies if needed, like nREPL, CIDER, refactor-nrepl
194+
- `include-hot-reload-deps` : Add `lambdaisland.classpath` and set it up for hot reloading deps.edn
195+
- `include-launchpad-deps` : Add launchpad itself as a dependency, since it contains runtime helpers for dotenv and shadow-cljs handling
196+
- `watch-dotenv` : Setup watch handlers to hot-reload `.env` and `.env.local`
197+
- `start-shadow-build` : Start the shadow-cljs build process, if necessary
198+
- `maybe-go` : Add `(user/go)` to the list of code to run on startup
199+
- `disable-stack-trace-elision` : Add `-XX:-OmitStackTraceInFastThrow` to the JVM flags
200+
- `inject-aliases-as-property` : Add `-Dlambdaisland.launchpad.aliases` as a JVM flag, so we know at runtime which aliases we started with
201+
- `include-watcher` : Start up the main watcher which will handle deps.edn/.env watching
202+
- `run-nrepl-server` : Add startup code to start nREPL
203+
- `print-summary` : Print an overview of aliases and extra dependencies that are being included
204+
- `start-process` : This is where we actually start Clojure
205+
- `wait-for-nrepl` : Wait for nREPL to be available
206+
- `maybe-connect-emacs` : Instruct Emacs to connect to nREPL
207+
208+
Each steps works on a context (`ctx`) map, mostly what you do is add stuff into
209+
that context, which gets used to construct the final clojure/JVM startup
210+
command. These are some of the keys in the context that you can read, set, or
211+
update:
212+
213+
- `:java-args` : sequence of JVM arguments, without the leading `-J`
214+
- `:requires` : namespaces to load (sequence of symbols)
215+
- `:eval-forms` : code to evaluate (sequence of forms)
216+
- `:options` : the result of parsing command line flags (map)
217+
- `:watch-handlers` : map from file path to filesystem change handler function
218+
- `:extra-deps` : additional dependencies to load, map from artifact name (symbol), to deps.edn coordinates map
219+
- `:env` : environment variables to set (gets populated with `.env`/`.env.local`)
220+
- `:middleware` : nREPL middleware to include, sequence of fully qualified symbols
221+
- `:shadow-cljs/build-ids` : shadow-cljs build-ids to start
222+
- `:shadow-cljs/connect-ids` : shadow-cljs build-ids to connect a REPL to
223+
- `:clojure-process` : the Java Process object, once Clojure has started
224+
- `:nrepl-port` : nREPL TCP port
225+
- `:nrepl-bind` : nREPL device IP
226+
- `:aliases` : deps.edn aliases in use
227+
- `:main-opts` : CLI command line options (seq of string)
228+
- `:deps-edn` : merged deps.edn map
229+
- `:paths` : paths to add to the classpath
230+
231+
Most of the time you want to add extra steps either right before, or right after
232+
`start-process`. The vars `before-steps` and `after-steps` are useful for that.
233+
234+
```clj
235+
(require '[lambdaisland.launchpad :as launchpad]
236+
'[babashka.process :refer [process]])
237+
238+
(defn npm-install [ctx]
239+
(process '[npm install] {:out :inherit
240+
:err :inherit})
241+
ctx)
242+
243+
(launchpad/main
244+
{:steps
245+
(concat launchpad/before-steps
246+
[npm-install
247+
launchpad/start-process]
248+
launchpad/after-steps)})
249+
```
250+
184251
<!-- opencollective -->
185252
## Lambda Island Open Source
186253

src/lambdaisland/launchpad.clj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@
398398
(:extra-deps ctx)))
399399
ctx)
400400

401-
(def before-steps [
402-
read-deps-edn
401+
(def before-steps [read-deps-edn
403402
handle-cli-args
404403
get-nrepl-port
405404
get-nrepl-bind
@@ -414,7 +413,6 @@
414413
;; extra java flags
415414
disable-stack-trace-elision
416415
inject-aliases-as-property
417-
;; start the actual process
418416
include-watcher
419417
run-nrepl-server
420418
print-summary])

0 commit comments

Comments
 (0)