|
45 | 45 | (defn error [& args] (apply println (java.util.Date.) "[ERROR]" args))
|
46 | 46 |
|
47 | 47 | (defn shellquote [a]
|
48 |
| - (cond |
49 |
| - (and (str/includes? a "\"") |
50 |
| - (str/includes? a "'")) |
51 |
| - (str "'" |
52 |
| - (str/replace a "'" "'\"'\"'") |
53 |
| - "'") |
54 |
| - |
55 |
| - (str/includes? a "'") |
56 |
| - (str "\"" a "\"") |
57 |
| - |
58 |
| - (re-find #"\s|\"" a) |
59 |
| - (str "'" a "'") |
60 |
| - |
61 |
| - :else |
62 |
| - a)) |
| 48 | + (let [a (str a)] |
| 49 | + (cond |
| 50 | + (and (str/includes? a "\"") |
| 51 | + (str/includes? a "'")) |
| 52 | + (str "'" |
| 53 | + (str/replace a "'" "'\"'\"'") |
| 54 | + "'") |
| 55 | + |
| 56 | + (str/includes? a "'") |
| 57 | + (str "\"" a "\"") |
| 58 | + |
| 59 | + (re-find #"\s|\"" a) |
| 60 | + (str "'" a "'") |
| 61 | + |
| 62 | + :else |
| 63 | + a))) |
| 64 | + |
| 65 | +(def ansi-fg-color-codes |
| 66 | + {:black 30 |
| 67 | + :red 31 |
| 68 | + :green 32 |
| 69 | + :yellow 33 |
| 70 | + :blue 34 |
| 71 | + :magenta 35 |
| 72 | + :cyan 36 |
| 73 | + :white 37}) |
| 74 | + |
| 75 | +(defn ansi-bold [& parts] |
| 76 | + (str "\u001b[1m" (str/join " " parts) "\u001b[0m")) |
| 77 | + |
| 78 | +(defn ansi-fg [color & parts] |
| 79 | + (str "\u001b[" (if (keyword? color) |
| 80 | + (get ansi-fg-color-codes color) |
| 81 | + color) "m" |
| 82 | + (str/join " " parts) |
| 83 | + "\u001b[0m")) |
63 | 84 |
|
64 | 85 | (defn free-port
|
65 | 86 | "Find a free TCP port"
|
|
396 | 417 | ctx)
|
397 | 418 |
|
398 | 419 | (defn print-summary [ctx]
|
399 |
| - (println "Aliases:") |
400 |
| - (doseq [a (:aliases ctx)] (println "-" a)) |
401 |
| - #_(apply println "Java flags: " (:java-args ctx)) |
402 |
| - (println "\nMiddleware: " ) |
403 |
| - (doseq [a (:middleware ctx)] (println "-" a)) |
404 |
| - (print "\nExtra Deps:") |
405 |
| - (pprint/print-table (map (fn [[k v]] |
406 |
| - {:lib k |
407 |
| - :coords v}) |
408 |
| - (:extra-deps ctx))) |
| 420 | + (println (ansi-fg :green "Launching") |
| 421 | + (ansi-bold (ansi-fg :green "Clojure")) |
| 422 | + (ansi-fg :green "on nREPL port") |
| 423 | + (ansi-fg :cyan (:nrepl-port ctx))) |
| 424 | + ;; (println "Aliases:") |
| 425 | + ;; (doseq [a (:aliases ctx)] (println "-" a)) |
| 426 | + ;; #_(apply println "Java flags: " (:java-args ctx)) |
| 427 | + ;; (println "\nMiddleware: " ) |
| 428 | + ;; (doseq [a (:middleware ctx)] (println "-" a)) |
| 429 | + ;; (print "\nExtra Deps:") |
| 430 | + ;; (pprint/print-table (map (fn [[k v]] |
| 431 | + ;; {:lib k |
| 432 | + ;; :coords v}) |
| 433 | + ;; (:extra-deps ctx))) |
409 | 434 | ctx)
|
410 | 435 |
|
411 | 436 | (defn pipe-process-output
|
|
443 | 468 | (.directory working-dir))
|
444 | 469 | _ (.putAll (.environment proc-builder) (or env (:env ctx)))
|
445 | 470 | color (mod (hash (or prefix (first cmd))) 8)
|
446 |
| - prefix (str "\u001b[" (+ 30 color) "m[" (or prefix (first cmd)) "]\u001b[0m ") |
| 471 | + prefix (ansi-fg (+ 30 color) (str "[" (or prefix (first cmd)) "] ")) |
447 | 472 | process (pipe-process-output (.start proc-builder) prefix)
|
448 | 473 | ctx (update ctx :processes (fnil conj []) process)]
|
| 474 | + (apply println (str prefix "$") (map shellquote cmd)) |
449 | 475 | (if background?
|
450 | 476 | ctx
|
451 | 477 | (let [exit (if timeout-ms
|
|
522 | 548 | (defn process-steps [ctx steps]
|
523 | 549 | (reduce #(%2 %1) ctx steps))
|
524 | 550 |
|
525 |
| -(defn main [{:keys [steps] :or {steps default-steps} :as opts}] |
526 |
| - (let [ctx (process-steps (initial-context opts) steps) |
| 551 | +(defn main [{:keys [steps |
| 552 | + start-steps |
| 553 | + end-steps |
| 554 | + pre-steps |
| 555 | + post-steps] :as opts}] |
| 556 | + (let [ctx (process-steps (initial-context opts) |
| 557 | + (or steps |
| 558 | + (concat |
| 559 | + start-steps |
| 560 | + before-steps |
| 561 | + pre-steps |
| 562 | + [start-clojure-process] |
| 563 | + post-steps |
| 564 | + after-steps |
| 565 | + end-steps))) |
527 | 566 | processes (:processes ctx)]
|
528 | 567 | (.addShutdownHook (Runtime/getRuntime)
|
529 | 568 | (Thread. (fn [] (run! #(.destroy %) processes))))
|
|
0 commit comments