Hi!
We're using this for typescript as well and its working great! It acted exactly as expected but I found myself scratching my head when my new slice didn't appear in storybook. This is because the hardcoded slice name "name": "MySlice" in my model and mock did not update when copied over when the slice was created.
I looked for docs hoping to see if there is some secret token I can use to mark the name for replacing, e.g "name": "{{slicename}}", or whatever. You get the idea.
Not asking for a feature per se, but if it's not currently possible, the ability would be tight. If I end up finding a way I'll post here. If anyone else knows whats up, please share
This isn't something that's possible with the current version of the Prismic CLI, but we have been working on an improved version of the CLI which will include this functionality in the templates.
Once this new version is released we'll let you know here.
I just started working with SM and would really like to get custom templates working, but if the model.json file can't be templated, it seems kinda useless. Is there any progress with a handlebars type token replacement in model.json?
(If I make my model.json have empty fields, it crashes Slice Machine)
Yes, but without adding the tokens, the custom templates are very limited, as I have to go in and find/replace all of the hardcoded values (which have to be present or Slice Machine bombs out when trying to generate stories).
I would love to use these to autogenerate my TypeScript types, but given the fact that the values are hardcoded, it would be impossible to do that currently.
I'm kinda shocked you guys don't have a solution for custom templating with string variables (ala handlebars, etc.)
So I ran into the same problem as you guys - I wanted to use custom typescript templates for both the index.tsx and model.json files but could not figure out how to make the slice naming work for me automatically.
At first I left those files empty but that just made slice machine crash every time I tried to make a new slice. Then I copied one of the earlier generated slices as is, but then I would have to manually change the hardcoded naming for every new slice.
After digging around the code of slice machine, I finally figured out what's happening. Essentially, the application is using the copy-template-dirs package to fill the component name and id via the moustache syntax {{ }}.
So the key idea here is that you can have these values filled in the template files when a new slice is generated:
componentName
componentId
variationId
To do so, just add them to the template file inside moustaches, e.g. {{componentName}} and {{componentId}}.
I've attached screenshots of my own template index.tsx and model.json files.
@Phil I really think the documentation needs to be updated with this information. Slice templates are really useful but without this information most devs would just end up wasting time and stop using slice machine altogether. I personally had to spend 3-4 hours just to get to the point where I understood what to do. If you want, I can provide a write-up which can be added to the documentation page (the What is Slice Machine article).