ignite icon indicating copy to clipboard operation
ignite copied to clipboard

Add front matter support to templates

Open kateinkim opened this issue 4 years ago • 10 comments
trafficstars

Per #1611 templates currently only support copying their contents to app directories with a pluralized name of the template directory. Since ignite puts navigators in the app/navigation directory we need a way to customize this.

By using front matter we can specify a destinationDir at the top of the template, customizing per template file. This also opens up the possibility for more powerful generator customization in the future.

kateinkim avatar Mar 15 '21 04:03 kateinkim

Thanks for this PR, @kateinkim! It's super well done.

So, #1629 addresses the current problem, which is the navigation / navigators naming issue brought up in #1611.

I like the idea of frontmatter in general. However, I'm putting this PR "on hold" for now until we see another situation where it will be directly useful. I'll keep it open.

One note: I don't want to use gray-matter. If we can use a different frontmatter library that would be good. I don't want Ignite associated with the author of that library.

jamonholmgren avatar Mar 16 '21 00:03 jamonholmgren

Thanks @jamonholmgren! I'll get the library updated.

kateinkim avatar Mar 16 '21 00:03 kateinkim

@kateinkim We already have the yaml library in our dependencies. I'm sorta considering us rolling our own frontmatter ... basically, see if the file contains two lines that are just ---, and if so, parse what's between as yaml, and remove that chunk for rendering purposes. Just thinking out loud, though -- if you find a good (small) frontmatter library that might be all we need.

jamonholmgren avatar Mar 16 '21 00:03 jamonholmgren

@jamonholmgren I updated to remove the gray-matter dependency and added support for patching from templates. I added patches to the model template to automatically import and add stores to the root store.

kateinkim avatar Mar 16 '21 04:03 kateinkim

Hey @jamonholmgren! I updated to support append, prepend, and replace as well and refactored the existing barrel export handling with it (still supports the skipping option). I also moved the patching handling out into it's own function. Let me know what you think.

kateinkim avatar Mar 24 '21 17:03 kateinkim

Would this PR also allow us to create a custom generator for api? The folder structure would be to place the generated 'api' files within the services/api sub-directory of app?

gavinharris-dev avatar Jun 14 '21 03:06 gavinharris-dev

@gavinharris-dev Yes! You’d be able to target any path in the project. 🙂

kateinkim avatar Jun 14 '21 03:06 kateinkim

@kateinkim When you get a chance, can you resolve conflicts on this? No rush.

jamonholmgren avatar Apr 25 '22 18:04 jamonholmgren

@kateinkim When you get a chance, can you resolve conflicts on this? No rush.

Yep! I will take a look at this later today!

kateinkim avatar Apr 25 '22 19:04 kateinkim

Whoa, it took long time to remember what and how I did this thing after coming back a year later. It's all tested and working now! 😄

Screen Shot 2022-04-25 at 7 57 23 PM

kateinkim avatar Apr 26 '22 02:04 kateinkim

Since this is working, let's target v8: Maverick for this @kateinkim. Can you resolve conflicts and re-target this at the maverick branch?

jamonholmgren avatar Aug 10 '22 17:08 jamonholmgren

Well, It wasn't easy to fix the conflicts but it's working as it is supposed to be still. @jamonholmgren

Screen Shot 2022-08-10 at 8 33 21 PM

kateinkim avatar Aug 11 '22 02:08 kateinkim