Fork me on GitHub
#shadow-cljs
<
2020-08-09
>
kiranshila17:08:40

Hey everone. Is there a way to create a custom target configuration? I am trying to get shadow to work with building for Espruino, a JS runtime for microcontrollers. The esprit project accomplishes this by just using cljs.main, but I would like to use shadow for the better integration of external js. I can't quite figure out how to make shadow just accomplish clj -m cljs.main -c myproject.core

kiranshila17:08:24

As in, I don't want to wrap in any extra stuff like the repl or hot reloading

thheller18:08:08

@me1310 yes, :target is extensible and meant to enable things like this. Its just not documented very well so writing it may be not so straightforward. do you have an example project for this? would be curious to know what the runtime is capable of. I saw Mike tweeting about about it but haven't looked into it myself yet.

kiranshila18:08:26

Yeah, I'm working on a simple project here. I'm using make to orchestrate some of the flashing as well

kiranshila18:08:06

AFAIK no one has tried to like make a project like this yet, Mike's examples were all fooling around in the repl

kiranshila18:08:38

But I fixed some bugs for him to make it such that "projects" like this just work

kiranshila18:08:18

In fact, I have CIDER working, and can live code on the device, which is frankly incredible

thheller18:08:20

are there some docs for the runtime itself? is it node?

kiranshila18:08:50

And its not a perfect implementation of the runtime, I had to muck around with cider's wrap fn as it's implementation of try/catch isn't quite correct

kiranshila19:08:31

@thheller Do you have an example bare-minimum target I can follow?

kiranshila19:08:22

Ooh also Espruino provides an npm module that actually does a lot of the heavy lifting, including hot code reloading

thheller19:08:26

well the easiest and closest is probably the node-script

kiranshila19:08:15

Nice, I'll take a look

kiranshila19:08:01

And so, is this something I need a fork to do? Or is there a mechanism to point to a custom target clj file

thheller19:08:08

someone made a :target not too long ago. maybe that helps too https://github.com/titonbarua/shadow-cljs-gjs-target

thheller19:08:53

no you just create a namespace with a process fn, then :target that.namespace just works

kiranshila19:08:01

oh sweet, thats easy

thheller19:08:41

basically that fn is called repeatedly with :shadow.build/stage changing and you doing stuff depending on the stage

thheller19:08:37

some of the hooks docs apply too. its pretty similar in structure https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks

thheller19:08:00

just that hooks do work after the :target impl. otherwise its the same.

kiranshila19:08:16

Cool, makes sense

thheller19:08:42

you can try the UI and (tap> build-state) to explore what it looks like