This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-22
Channels
- # announcements (1)
- # aws (2)
- # babashka (52)
- # beginners (35)
- # calva (20)
- # clj-kondo (13)
- # cljdoc (8)
- # clojure (14)
- # clojure-uk (6)
- # clojurescript (5)
- # conjure (13)
- # crypto (1)
- # data-oriented-programming (1)
- # datalevin (7)
- # emacs (2)
- # fulcro (21)
- # graalvm (14)
- # introduce-yourself (1)
- # lsp (6)
- # malli (17)
- # off-topic (15)
- # re-frame (10)
- # releases (1)
- # sci (2)
- # shadow-cljs (17)
- # tools-build (9)
- # tools-deps (6)
Hey. I figured out how to call shadow-cljs on the command line but I haven't figured out how to call it from my bb.edn file with shell
.
npx shadow-cljs compile web --config-merge {:output-dir,\\\"target/fun\\\"}
This works. How do I put this into a string so that I can call (shell "npx shadow-cljs compile web --config-merge ...output-dir...target/fun...
Everything I've tried gives me some kind of runtime exception for not being able to parse the argument. I'm on windows. I think cider uses base64 encoding somehow to avoid this issue...
Here:
(shell "npx shadow-cljs compile web --config-merge \"{:output-dir,\\\\\\\"target/fun\\\\\\\"}\"")
This works. That wasn't fun.
Shadow has a client api you can call directly from clojure. Not sure that means it would work from bb.
That would avoid using shell
I've also called shadow from bb in several projects like this. I'll paste later today
I think removing the slashes should improve the situation, no idea why you out them there but making the map a separate arg after the first string should also work
Here's a snippet from one of my other projects:
build:cljs:snapshot {:doc "Builds production JS"
:task (shell {:extra-env {"DUCTILE_STATIC_CLERK" "true"}}
"yarn shadow-cljs release ui" "--config-merge"
"{:closure-defines {ductile.ui.routes/root-view \"devdocs/index\"}}")
:depends [yarn-install]}
(shell "npx shadow-cljs release web" "--config-merge" (format "{:output-dir \"%s\"}" output-dir))
result
shadow-cljs - config: C:\Users\richie\project\shadow-cljs.edn
Error while parsing option "--config-merge {:output-dir": java.lang.RuntimeException: EOF while reading
and this just in case
(shell "npx shadow-cljs release web" "--config-merge" "{:output-dir \"target/fun\"}")
result
Error while parsing option "--config-merge {:output-dir": java.lang.RuntimeException: EOF while reading
This is on windows.
I just tested on mac and I do not have this issue on mac.
Thanks!(shell {:escape (fn [x] (println x) x)} "npx shadow-cljs release web --config-merge {:output-dir \"target/fun\"}")
gives
npx
shadow-cljs
release
web
--config-merge
{:output-dir
target/fun
}
(shell {:escape (fn [x] (println x) x)} "npx shadow-cljs release web --config-merge '{:output-dir \"target/fun\"}'")
(shell {:escape (fn [x] (println x) x)} "npx shadow-cljs release web --config-merge '{:output-dir \"target/fun\"}'")
gives
npx
shadow-cljs
release
web
--config-merge
{:output-dir "target/fun"}
shadow-cljs - config: C:\Users\richie\project\shadow-cljs.edn
Error while parsing option "--config-merge {:output-dir": java.lang.RuntimeException: EOF while reading
what you can do is put that map in an .edn file and then just refer to the edn file instead
(shell {:escape (fn [x] (println x) x)} "npx shadow-cljs release web --config-merge '{:output-dir,\"target/fun\"}'")
gives
npx
shadow-cljs
release
web
--config-merge
{:output-dir,"target/fun"}
shadow-cljs - config: C:\Users\richie\project\shadow-cljs.edn
[:web] Compiling ...
Invalid configuration
-- Spec failed --------------------
{:output-dir target/fun,
^^^^^^^^^^
:compiler-options ...,
:build-hooks ...,
:modules ...,
:devtools ...,
:build-id ...,
:asset-path ...,
:target ...}
should satisfy
non-empty-string?
just use the file approach. windows can behave weird with spaces and quotes in args. it could also be something in shadow
{:enter (do
(def opts (parse-opts *command-line-args* [[nil "--output-dir OUTPUT-DIR"]]))
(def conf (edn/read-string (slurp "shadow-cljs.edn"))))
:task (let [output-dir (or (:output-dir (:options opts))
(get-in conf [:builds :web :output-dir]))]
(shell {:escape (fn [x] (println x) x)} "npx shadow-cljs" "release" "web" (format "--config-merge \\\"{:output-dir \\\\\\\"%s\\\\\\\"}\\\"" output-dir)))}
This works. +1 for not needing a comma.
I'm currently reading the output-dir from a cli parameter. I don't need this but it's helpful atm so I'll keep using it in the near-term.ok, you could also first spit out the map to a temporary file on disk and then use that file name
Instead of :enter
you probably want to put that in :init
. enter is executed before every individual task
(defn escape
[s]
(str/join ""
(flatten
(replace {\\ [\\ \\]
\" [\\ \"]}
s))))
(escape (format "--config-merge %s" (pr-str (pr-str {:output-dir "target/fun"}))))
;; "--config-merge \\\"{:output-dir \\\\\\\"target/fun\\\\\\\"}\\\""
forgive a noob question (can you tell i don't write much cli stuff :D) how would rewrite this so i can put it into my bb.edn
? specifically, the output to carve.txt
: clj -Tcarve carve! > carve.txt
bril, thanks!
I tested this and it worked:
{:tasks {foo (clojure {:out "/tmp/sum.txt"} "-M -e '(+ 1 2 3)'")}}
works great
Survey time! Please leave your feedback on how you are using #babashka! I will publish the results as an article later. https://forms.gle/ko3NjDg2SwXeEoNQ9
I'm trying to determine if my bb.edn is running on windows or not.
{:tasks
{:requires [[babashka.main :refer [windows?]]]
test (println windows?)}}
gives
Message: Could not find namespace: babashka.main.
but it's here in babashka.main
https://github.com/babashka/babashka/blob/master/src/babashka/main.clj#L59
Thanks again!@rgkirch you can use babashka.core :refer [windows?]
- it's a function. the code in the babashka repo does not reflect what's available in babashka itself.
I answered the survey, but I forgot that I would love to have datascript inside babashka as default feature 🙂
I just finished too -- and embedded datascript would be great. Though I don't know how hard that is to achieve.
I can you can have it as a feature flag though