Fork me on GitHub
#tools-deps
<
2018-05-21
>
borkdude10:05:07

Standalone script using tools.deps: https://github.com/borkdude/balcony

robert-stuttaford10:05:36

@alexmiller @dominicm thanks for TDEPS-9 - using Datomic PRO with clj is rad

dominicm10:05:22

@robert-stuttaford I setup the JUXT website last night, was nice 🙂

robert-stuttaford10:05:50

i recognise this may be a daft question, but is there perhaps a way to run two ‘mains’ at once from clj ? i see the docs say that it’ll run the last one encountered, but i’m hoping to get a boot-like thing going where i can run both figwheel-main and my 10-liner CIDER repl script in one process

dominicm10:05:16

@robert-stuttaford Update to cider 0.17 and use -e before your normal -m

dominicm10:05:02

^^ this might be useful to see what cider generates when it does jack-in, and hard-code it in 🙂

dominicm10:05:17

but you could implement cider-nrepl.main/init yourself.

robert-stuttaford10:05:54

i’ve got a working cider script:

(require '[clojure.tools.nrepl.server :refer [start-server]]
         '[refactor-nrepl.middleware :refer [wrap-refactor]])

(defn nrepl-handler []
  (require 'cider.nrepl)
  (ns-resolve 'cider.nrepl 'cider-nrepl-handler))

(def port 7800)

(spit ".nrepl-port" port)

(start-server :port port :handler (wrap-refactor (nrepl-handler)))
(println "Started nREPL on port" port)

(.addShutdownHook (Runtime/getRuntime)
                  (Thread. #( ".nrepl-port")))

robert-stuttaford10:05:14

i want to run it and figwheel-main together, in one process. right now i use two

dominicm10:05:28

Are you using cljs? That doesn't look like it will work with cljs. Unless you have a separate nrepl for figwheel?

robert-stuttaford10:05:22

hmm, i guess there’s no way around it; i’ll have to write a clj script that starts the nrepl-server and invokes the figwheel-main stuff afterwards

dominicm10:05:30

You can replace that whole file with:

clj -e "(require 'cider-nrepl.main) (cider-nrepl.main/init '[refactor-nrepl.middleware/wrap-refactor])"

dominicm10:05:43

I'm presuming that can go into the deps.edn somewhere.

dominicm10:05:04

@robert-stuttaford Apparently not, but mains can run other mains.

(defn -main [& args]
  (start-nrepl)
  (apply clojure.repl/main args))

robert-stuttaford12:05:28

turns out the figwheel-main api is super simple, this was a total non-issue

robert-stuttaford12:05:43

;; nREPL

(require '[clojure.tools.nrepl.server :refer [start-server]]
         '[refactor-nrepl.middleware :refer [wrap-refactor]])

(defn nrepl-handler []
  (require 'cider.nrepl)
  (ns-resolve 'cider.nrepl 'cider-nrepl-handler))

(def port 7800)

(spit ".nrepl-port" port)

(start-server :port port :handler (wrap-refactor (nrepl-handler)))
(println "Started nREPL on port" port)

(.addShutdownHook (Runtime/getRuntime)
                  (Thread. #( ".nrepl-port")))


;; Figwheel

(require '[figwheel.main :refer [start]])

(start "dev")

jeff.terrell19:05:58

With the new clojure CLI tool, can I have a standalone .clj script, i.e. apart from a src/ directory and without a corresponding deps.edn file, ideally invokable via a simple shebang line (`#!`) at the top of the file? If so, what would that shebang line be?

dominicm19:05:44

Digging it up now

dominicm19:05:16

@jeff.terrell

#!/bin/sh

"exec" "clojure" "-Sdeps" '{:deps {funcool/tubax {:mvn/version "0.2.0"}}}' "$0" "$@"

(println "5555")

jeff.terrell19:05:55

Impressive. Thanks, @dominicm! I'm assuming the :deps are optional?

dominicm19:05:17

@jeff.terrell what do you mean optional?

jeff.terrell19:05:43

As in, I don't need any deps. I can just leave that part out, right?

dominicm19:05:32

Oh, sure. In that case you can just do.

/usr/bin/env clojure

...

dominicm19:05:02

No args = shebang. Args = exec

jeff.terrell19:05:40

Ah perfect. I did that initially, but I was getting confused because I expected clojure to automatically call my -main function. But I see now that it was working fine. Thanks for the help!

jeff.terrell19:05:35

Nice trick! Thanks again.

jeff.terrell21:05:29

OK, followup question: how do I access command-line arguments to a #!/usr/bin/env clojure standalone script?

mfikes21:05:36

@jeff.terrell They will be in *command-line-args*

jeff.terrell21:05:36

That's it. Thanks!

mfikes21:05:36

@jeff.terrell If useful, some similar material to your FAQ is at http://planck-repl.org/dependencies.html under Shebang Deps

👍 4