This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-02
Channels
- # announcements (13)
- # babashka (42)
- # beginners (29)
- # calva (39)
- # cider (15)
- # clerk (10)
- # clojure (67)
- # clojure-europe (18)
- # clojure-hungary (2)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-uk (7)
- # clojuredesign-podcast (14)
- # clojurescript (19)
- # datalevin (1)
- # datascript (5)
- # emacs (4)
- # events (2)
- # fulcro (5)
- # graalvm (5)
- # hyperfiddle (23)
- # incanter (3)
- # jobs (2)
- # lsp (8)
- # missionary (15)
- # off-topic (45)
- # portal (41)
- # practicalli (1)
- # re-frame (3)
- # reitit (6)
- # releases (2)
- # remote-jobs (1)
- # sci (1)
- # shadow-cljs (35)
- # solo-full-stack (8)
- # tools-deps (4)
Hey folks, just a quick question: is there a way to create shareable executables from babashka scripts? Maybe via GraalVM? I’m aware of bbin, but was looking for a way to share with colleagues without them having to know about babashka 😅
You can try this: https://github.com/babashka/babashka/wiki/Self-contained-executable But note that you have to package a binary for every OS that your colleague is using, which can be quite annoying.
Thx, will look at that
Hm, since I’m only interested in macOS and Linux for now, shouldn’t be a big issue
if you are packaging for other linux amd64 systems I'd definitely pick the -static one
(-> uberjar exec) sounds good to me
I just wanted to say the process of bb uberjar and then caca sounds good. Just tried to be cool and obviously failed 😅
Executable… don’t all the cool kids use shorthand’s? But reading it now it’s really misguiding. Sorry
Next time I try to be funny I’ll have more coffee first 😂
I'm doing a bunch of search-and-replace across a monorepo, and rather than deal with sed
/`perl` idiosyncrasies I'd like to use bb to those string replaces 🧵
Here's my best version for now
git ls-files '**/deps.edn' | xargs bb -e '((fn [f] (doseq [fname *command-line-args*] (spit fname (f (slurp fname))))) #(clojure.string/replace % #"(thheller/shadow-cljs \{:mvn/version \")(.*?)(\"\})" (fn [m] (str (get m 1) "2.25.5" (get m 3)))))'
(Updates shadow-cljs in all deps.edn)
This works well but is obviously a little unwieldy. How do others do this kind of thing from the CLI (no IDE/emacs please)? Any comments welcome
if you have a mono-repo why not make one deps.edn with your shared libs and just use local/root to depend on that one?
Right, that's all possible, but not really what my question was aimed at
I'm curious about the use of bb as a generic text search/replace tool, similar to perl -pie
or sed s/.../.../
, except much more familiar to a Clojure programmer
I like my solution because it • is composable (I can swap out git ls-files for find or something else) • uses code (which has less cognitive load than remembering how to escape regex)
But it's a little long, so I'm trying to simplify for the next 100 times I'm doing something like this
For example, I seem to remember had a function that did slurp, f and spit, but I can't find it now
jinx!
that's a lot nicer already
updating EDN using regex can be a bit error-prone, there is also https://github.com/borkdude/rewrite-edn which does it in a more sophisticated way
that's really cool - I'll use this when I need the extra robustness
I guess ls-files
(etc) could be wrapped in a bb lib as well
Here's the end result
#!/usr/bin/env bb
(require '[babashka.fs :as fs])
(require '[clojure.string :as str])
(require '[babashka.process :as process])
(defn ls-files [root & patterns]
(remove empty? (str/split-lines (:out (apply process/sh {:dir root} "git" "ls-files" "--" patterns)))))
(defn f [s]
(str/replace s
#"(\"shadow-cljs\": \")(.*?)(\")"
(fn [m] (str (get m 1) "2.25.5" (get m 3)))))
(defn main
[& args]
(doseq [fname (apply ls-files "." args)]
(println fname)
(fs/update-file fname f)))
(apply main *command-line-args*)
(For a similar but not the same problem)
Hello! I’m trying to use selmer/render-file in a script, but I get this:
----- Context ------------------------------------------------------------------
37: tree-data-map (tree-data-reducer grouped)]
38: tree-data-map))
39:
40: (defn show-page [graph-key]
41: (selmer/render-file
^--- resource-path for page.selmer returned nil, typically means the file doesn't exist in your classpath.
We don’t have this fn in babashka? I thought so because I saw it https://github.com/babashka/babashka/blob/ae01170f92a69b0e82124edbfbe6f088dc315e95/feature-selmer/babashka/impl/selmer.clj#L107:
Thanks in advance!the file needs to be on the classpath, which would typically mean the path should be valid relative to one of the directories in the :paths
key in bb.edn, or the classpath specified via other mechanisms as discussed in <https://book.babashka.org/#_classpath>