timlrx / contentlayer2

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://contentlayer.dev
MIT License
153 stars 11 forks source link

CLI tool #34

Closed Goldziher closed 2 days ago

Goldziher commented 1 month ago

Hi there,

I just discovered this tool (my partner started using a template that uses it). It's pretty nifty, and I'm glad you guys are continuing to support it.

One issue that I have is the code generation strategy. I understand it's piggybacking on top of the build command to emit JS and type definitions. This works, but the setup process could be better. furthermore, my experience with collagen from other languages is that it's usually better to have generated code committed to VCS.

I understand what I am about to propose is a massive effort, but its also a way to make this library more generic.

I suggest having a CLI command that generates typescript rather than JS at a specified directory.

This will also reduce the need of tweaking the tsconfig file etc.

timlrx commented 1 month ago

Hi, thanks for the comments. I think there's a slight misunderstanding of Contentlayer over here. Contentlayer is not really a code generation tool but rather a way to convert content into data (as opposed to code) that can be easily imported into applications.

This will be json data for performance reasons but for development, we also ship js objects with types to improve the user experience. Modifying tsconfig.json or jsconfig.json is needed just to specify to the application where to look for the generated files. Controlling where the files are generated is probably the cleanest approach rather than letting the user decide and having to customize this part of things.