Fork me on GitHub
#babashka
<
2022-05-18
>
martinklepsch10:05:57

what would be the easiest way to run something like this with a babashka task? I couldn’t quite get it to work with shell or bb.process

ls functions/index.js | entr -r node functions/index.js

borkdude10:05:15

I would use the babashka fswatcher pod here probably

borkdude10:05:32

I'll send the process invocation later for what you have right now (on the phone now) but you can probably go via bash -c to the whole thing via bash

borkdude11:05:37

Why are you doing ls functions/index.js?That's always going to return one file right?

martinklepsch11:05:20

yes, I think it could also be echo or something, just need to pipe something into entr

borkdude11:05:26

OK, the way to do this with process or shell:

(shell {:in "functions/index.js\n"} "entr -r node functions/index.js")

borkdude11:05:37

(not sure if the newline is necessary)

borkdude11:05:52

You can also consider using:

martinklepsch11:05:55

oh that’s sweet with just shell

borkdude11:05:12

seems to also work without the newline

martinklepsch11:05:17

the fswatcher thing is also interesting, I may give this a go as well

martinklepsch11:05:50

because I think I may want to delete functions/index.js at the start of this just to make sure I’m not running a wrongly configured file

borkdude11:05:41

Here is a full setup with bb tasks:

{:pods {org.babashka/fswatcher {:version "0.0.3"}}
 :tasks {watch {:requires ([pod.babashka.fswatcher :as fw])
                :task (do (fw/watch "project.clj"
                                    (fn [event]
                                      (when (#{:write :write|chmod} (:type event))
                                        (shell "echo hello"))))
                          (deref (promise)))}}}

teodorlu12:05:16

would adding a version entrypoint to Neil make sense? neil --version or similar.

teodorlu12:05:45

Should have checked the issues!

teodorlu19:05:12

I figure we want to inline version.txt when producing the script. Not sure what behavior we want for src/babashka/neil.clj. Leaving version undefined here is easiest. Otherwise I guess we could have a default function that tries to read version.txt dynamically and then when we build the neil script we add an (alter-var-root version (constantly INLINED_STRING)).

borkdude19:05:20

Have you checked how it's done in deps.clj?

teodorlu19:05:50

yes - but frankly, I didn't really understand why you chose to do it that way. Was it to get the same semantics for local development and resulting script?

(def raw-script (io/file "src" "borkdude" "deps.clj"))
(def version (-> (io/file "resources" "DEPS_CLJ_VERSION")
                 (slurp)
                 (str/trim)))

(def version-code "(def deps-clj-version
  (-> (io/resource \"DEPS_CLJ_VERSION\")
      (slurp)
      (str/trim)))")

(def script
  (str ";; Generated with script/gen_script.clj. Do not edit directly.\n\n"
       (-> (slurp raw-script)
           (str/replace #"(?i)\s*\(:gen-class\)" "")
           (str/replace version-code (format "(def deps-clj-version %s)" (pr-str version))))
       "\n(apply -main *command-line-args*)\n"))

(def clj-script
  (str
   "#!/usr/bin/env bb\n\n"
   script))
https://github.com/borkdude/deps.clj/blob/bac835661adbcd06b07ce2c408bb3e4911a48c28/script/gen_script.clj#L8-L23

borkdude19:05:40

I don't remember either. We could just hard-code the version in the source maybe and when bump the version (via bb publish), then we search and replace it.

borkdude19:05:55

seems the most robust way

borkdude19:05:13

(def version "0.0.1")
(str/replace "(def version ...) "(def version ...)")

teodorlu19:05:40

Makes sense - I'll give it a shot.

🙏 1
teodorlu19:05:19

do regexes work differently in bb.edn targets from normal clj files? I'm able to use (re-pattern "version"), but #"version" gives me trouble.

borkdude19:05:53

yes, if you update to the newest bb then you will get a better error msg

borkdude19:05:00

regex literals are not supported in .edn

teodorlu20:05:59

Code generation (regex) seems to be working: https://github.com/babashka/neil/pull/39/files

teodorlu20:05:05

./neil --version
neil 0.0.29

borkdude20:05:03

woohoo nice! will check tomorrow

borkdude20:05:28

merged, look straightforward enough :)

🎉 1