|
53 | 53 | "--[no-]debug-repl" {:doc "Include gfredericks/debug-repl dependency and middleware"}
|
54 | 54 | "--[no-]go" {:doc "Call (user/go) on boot"}
|
55 | 55 | "--[no-]namespace-maps" {:doc "Disable *print-namespace-maps* through nREPL middleware"}
|
56 |
| - "--[no-]prefix" {:doc "Disable per-process prefix"}]) |
| 56 | + "--[no-]prefix" {:doc "Disable per-process prefix"} |
| 57 | + "--[no-]exec-fn" {:doc "Parse and execute the first :exec-fn found"}]) |
57 | 58 |
|
58 | 59 | (def library-versions
|
59 | 60 | (:deps (edn/read-string (slurp (io/resource "launchpad/deps.edn")))))
|
|
349 | 350 | (catch Exception e
|
350 | 351 | (println "(user/go) failed" e))))))
|
351 | 352 |
|
352 |
| -(defn run-nrepl-server [{:keys [nrepl-port nrepl-bind middleware] :as ctx}] |
| 353 | +(defn nrepl-server-eval-forms [{:keys [nrepl-port nrepl-bind middleware] :as ctx}] |
353 | 354 | (-> ctx
|
354 | 355 | (update :requires conj 'nrepl.cmdline)
|
355 | 356 | (update :eval-forms (fnil conj [])
|
356 | 357 | `(nrepl.cmdline/-main "--port" ~(str nrepl-port)
|
357 | 358 | "--bind" ~(str nrepl-bind)
|
358 | 359 | "--middleware" ~(pr-str middleware)))))
|
359 | 360 |
|
| 361 | +(defn exec-fn-eval-forms [{:keys [aliases deps-edn] :as ctx}] |
| 362 | + (let [{:keys [alias exec-fn exec-args]} |
| 363 | + (->> aliases |
| 364 | + ;; we use only the first alias where :exec-fn is defined |
| 365 | + (some #(when (get-in deps-edn [:aliases % :exec-fn]) |
| 366 | + (-> (get-in deps-edn [:aliases %]) |
| 367 | + (assoc :alias %)))))] |
| 368 | + (assert (and exec-fn (symbol? exec-fn)) |
| 369 | + "Launchpad could not find any valid :exec-fn symbol, aborting...") |
| 370 | + (info (format "Executing %s from the %s alias" exec-fn alias)) |
| 371 | + (-> ctx |
| 372 | + (update :requires conj (symbol (namespace exec-fn))) |
| 373 | + (update :eval-forms (fnil conj []) `(~exec-fn ~exec-args))))) |
| 374 | + |
360 | 375 | (defn register-watch-handlers [ctx handlers]
|
361 | 376 | (update ctx
|
362 | 377 | :watch-handlers
|
|
544 | 559 | (System/exit exit)))
|
545 | 560 | ctx))))))
|
546 | 561 |
|
547 |
| -(defn start-clojure-process [{:keys [aliases nrepl-port] :as ctx}] |
| 562 | +(defn start-clojure-process [ctx] |
548 | 563 | (let [args (clojure-cli-args ctx)]
|
549 | 564 | (apply debug (map shellquote args))
|
550 | 565 | ((run-process {:cmd args
|
|
566 | 581 | inject-aliases-as-property
|
567 | 582 | include-watcher
|
568 | 583 | print-summary
|
569 |
| - run-nrepl-server]) |
| 584 | + nrepl-server-eval-forms]) |
570 | 585 |
|
571 | 586 | (def after-steps [wait-for-nrepl
|
572 | 587 | ;; stuff that happens after the server is up
|
|
576 | 591 | [start-clojure-process]
|
577 | 592 | after-steps))
|
578 | 593 |
|
| 594 | +(def exec-fn-steps [handle-cli-args |
| 595 | + ;; extra java flags |
| 596 | + disable-stack-trace-elision |
| 597 | + inject-aliases-as-property |
| 598 | + print-summary |
| 599 | + exec-fn-eval-forms |
| 600 | + start-clojure-process]) |
| 601 | + |
579 | 602 | (def ^:deprecated start-process start-clojure-process)
|
580 | 603 |
|
581 | 604 | (defn find-project-root []
|
|
609 | 632 | end-steps
|
610 | 633 | pre-steps
|
611 | 634 | post-steps] :as ctx}]
|
612 |
| - (let [ctx (process-steps |
| 635 | + (let [default-steps |
| 636 | + (if-not (:exec-fn ctx) |
| 637 | + (concat |
| 638 | + start-steps |
| 639 | + before-steps |
| 640 | + pre-steps |
| 641 | + [start-clojure-process] |
| 642 | + post-steps |
| 643 | + after-steps |
| 644 | + end-steps) |
| 645 | + exec-fn-steps) |
| 646 | + ctx (process-steps |
613 | 647 | (update ctx :aliases concat (map keyword (::cli/argv ctx)))
|
614 |
| - (or steps |
615 |
| - (concat |
616 |
| - start-steps |
617 |
| - before-steps |
618 |
| - pre-steps |
619 |
| - [start-clojure-process] |
620 |
| - post-steps |
621 |
| - after-steps |
622 |
| - end-steps))) |
| 648 | + (or steps default-steps)) |
623 | 649 | processes (:processes ctx)]
|
624 | 650 | (System/exit (apply min (for [p processes]
|
625 | 651 | (.waitFor p))))))
|
|
0 commit comments