Fork me on GitHub
#babashka
<
2021-09-25
>
mmer21:09:30

Hi, I was wondering if it is possible to take a jvm clojure based set of files and move them to be based on babashka? Is there a path to do this?

borkdude21:09:07

@mmer Can you give an example?

mmer21:09:32

I have a lein project, with several files, it is a cli based application so would do really well to migrate to babashka. Is there a way to do this. I tried to use native-image from graalvm and I ended up with messages that just did not mean anything? I am using the following libraries: io.forward/yaml babashka/fs tools.cli com.wallbrew/clj-xml

mmer21:09:42

I am presuming that I will have to change it to a deps.edn based file - I am expecting to swap out the yaml library as I think babashka uses a different one.

borkdude21:09:15

ah like that

borkdude21:09:30

so babashka/fs and tools.cli are already included in bb

borkdude21:09:37

it uses clj-yaml as the yaml library

borkdude21:09:42

and clojure.data.xml for xml

borkdude21:09:50

both are built-in

mmer21:09:08

I think I can swap those libraries fairly easily

borkdude21:09:49

I see the clj-xml is built on top of clojure.data.xml. Perhaps it works

borkdude21:09:29

if you want to try that, you need to make a bb.edn with:

{:deps {com.wallbrew/clj-xml {:mvn/version "1.6.2"}}}

mmer21:09:29

That is a very minor part of the project - I would be happy to have a simple script to convert from xml to yaml anyway

borkdude21:09:46

it's better to use the built in libs directly for speed

mmer21:09:28

OK - so I guess I need to go an look at the getting started and work from there?

mmer21:09:19

I am presuming that I could use something like vscode to edit and run the code? if so is there a place that explains how to develop bb scripts in an IDE?

borkdude21:09:08

@mmer There are docs around that here: https://github.com/exercism/babashka/blob/main/docs/editors.md But just executing the script from the command line while editing is fine too, if that's too steep of a learning curve for now :)

borkdude21:09:32

Are you using multiple files in your project or is it just one file?

borkdude21:09:58

Babashka support nREPL so you can basically connect to that from any editor which understands it

borkdude21:09:55

Personally, but that's just me, I hardly use this feature and test script just by running them, since it's already fast enough. But lots of people do use the REPL stuff

borkdude21:09:17

Cursive recently also got babashka script support

borkdude21:09:28

So you can navigate around. So did #lsp (which is used in Calva)

borkdude21:09:34

Hmm @pez, perhaps it would be nice to add a little section to the Calva docs how to develop a bb script, similar to this https://github.com/exercism/babashka/blob/main/docs/editors.md

borkdude21:09:39

@ericdallo When does Calva/LSP recognize a bb script? Is this when it sees a bb.edn?

ericdallo22:09:50

Actually some clojure-lsp features are already available if the file is a .clj one, but for fully support, it needs a bb.edn on the project root

borkdude21:09:59

@mmer https://book.babashka.org/#_nrepl That's actually the section you should read.

borkdude21:09:42

I modernized the way of firing up an nREPL server a bit here. Make a bb.edn:

{:tasks
 {:requires ([babashka.fs :as fs]
             [babashka.process :as p :refer [process]]
             [babashka.wait :as wait])
  nrepl (let [port (with-open [sock (java.net.ServerSocket. 0)] (.getLocalPort sock))
              proc (process (str "bb nrepl-server " port) {:inherit true})]
          (wait/wait-for-port "localhost" port)
          (spit ".nrepl-port" port)
          (fs/delete-on-exit ".nrepl-port")
          (deref proc))}}

borkdude21:09:46

And then run bb nrepl

borkdude21:09:54

And then your editor should recognize the port

borkdude21:09:28

I'll update the book - done

mmer12:09:15

Hi - I manage to convert from clojure to bb with a simple change to the bb yaml option. Very easy. Thanks

borkdude12:09:46

cool, thanks for letting me know