|
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-]execute" {:doc "Parse and execute the first :exec-fn found in aliases"}]) |
57 | 58 |
|
58 | 59 | (def library-versions |
59 | 60 | (:deps (edn/read-string (slurp (io/resource "launchpad/deps.edn"))))) |
|
364 | 365 | (catch Exception e |
365 | 366 | (println "(user/go) failed" e)))))) |
366 | 367 |
|
367 | | -(defn run-nrepl-server [{:keys [nrepl-port nrepl-bind middleware] :as ctx}] |
| 368 | +(defn nrepl-server-eval-forms [{:keys [nrepl-port nrepl-bind middleware] :as ctx}] |
368 | 369 | (-> ctx |
369 | 370 | (update :requires conj 'nrepl.cmdline) |
370 | 371 | (update :eval-forms (fnil conj []) |
371 | 372 | `(nrepl.cmdline/-main "--port" ~(str nrepl-port) |
372 | 373 | "--bind" ~(str nrepl-bind) |
373 | 374 | "--middleware" ~(pr-str middleware))))) |
374 | 375 |
|
| 376 | +(defn exec-fn-eval-forms [{:keys [aliases deps-edn] :as ctx}] |
| 377 | + (let [{:keys [alias exec-fn exec-args]} |
| 378 | + (->> aliases |
| 379 | + ;; we use only the first alias where :exec-fn is defined |
| 380 | + (some #(when (get-in deps-edn [:aliases % :exec-fn]) |
| 381 | + (-> (get-in deps-edn [:aliases %]) |
| 382 | + (assoc :alias %)))))] |
| 383 | + (assert (and exec-fn (symbol? exec-fn)) |
| 384 | + "Launchpad could not find any valid :exec-fn symbol, aborting...") |
| 385 | + (info (format "Executing %s from the %s alias" exec-fn alias)) |
| 386 | + (-> ctx |
| 387 | + (update :requires conj (symbol (namespace exec-fn))) |
| 388 | + (update :eval-forms (fnil conj []) `(~exec-fn ~exec-args))))) |
| 389 | + |
375 | 390 | (defn register-watch-handlers [ctx handlers] |
376 | 391 | (update ctx |
377 | 392 | :watch-handlers |
|
559 | 574 | (System/exit exit)) |
560 | 575 | ctx)))))) |
561 | 576 |
|
562 | | -(defn start-clojure-process [{:keys [aliases nrepl-port] :as ctx}] |
| 577 | +(defn start-clojure-process [ctx] |
563 | 578 | (let [args (clojure-cli-args ctx)] |
564 | 579 | (apply debug (map shellquote args)) |
565 | 580 | ((run-process {:cmd args |
|
583 | 598 | inject-aliases-as-property |
584 | 599 | include-watcher |
585 | 600 | print-summary |
586 | | - run-nrepl-server]) |
| 601 | + nrepl-server-eval-forms]) |
587 | 602 |
|
588 | 603 | (def after-steps [wait-for-nrepl |
589 | 604 | ;; stuff that happens after the server is up |
|
593 | 608 | [start-clojure-process] |
594 | 609 | after-steps)) |
595 | 610 |
|
| 611 | +(def execute-steps [handle-cli-args |
| 612 | + ;; extra java flags |
| 613 | + disable-stack-trace-elision |
| 614 | + inject-aliases-as-property |
| 615 | + print-summary |
| 616 | + exec-fn-eval-forms |
| 617 | + start-clojure-process]) |
| 618 | + |
596 | 619 | (def ^:deprecated start-process start-clojure-process) |
597 | 620 |
|
598 | 621 | (defn find-project-root [] |
|
626 | 649 | end-steps |
627 | 650 | pre-steps |
628 | 651 | post-steps] :as ctx}] |
629 | | - (let [ctx (process-steps |
| 652 | + (let [default-steps |
| 653 | + (if-not (:execute ctx) |
| 654 | + (concat |
| 655 | + start-steps |
| 656 | + before-steps |
| 657 | + pre-steps |
| 658 | + [start-clojure-process] |
| 659 | + post-steps |
| 660 | + after-steps |
| 661 | + end-steps) |
| 662 | + execute-steps) |
| 663 | + ctx (process-steps |
630 | 664 | (update ctx :aliases concat (map keyword (::cli/argv ctx))) |
631 | | - (or steps |
632 | | - (concat |
633 | | - start-steps |
634 | | - before-steps |
635 | | - pre-steps |
636 | | - [start-clojure-process] |
637 | | - post-steps |
638 | | - after-steps |
639 | | - end-steps))) |
| 665 | + (or steps default-steps)) |
640 | 666 | processes (:processes ctx)] |
641 | 667 | (System/exit (apply min (for [p processes] |
642 | 668 | (.waitFor p)))))) |
|
0 commit comments