nestjs / docs.nestjs.com

The official documentation https://docs.nestjs.com 📕
MIT License
1.2k stars 1.72k forks source link

Provide documentation on how to extend schematics #2470

Open hcharley opened 2 years ago

hcharley commented 2 years ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

I'm currently unsure how to extend schematics to include my own spin on how I create resources, so it would be great to help people like me out with an example of how to do so.

Describe the solution you'd like

Documentation on how to extend schematics, like @nestjs/schematics:resource.

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

I like to add MikroORM decorators to resources, use both resolvers and controllers at the same time, and other organization-specific code styles that would be nice to automate adding without having to rewrite and maintain everything.

micalevisk commented 2 years ago

I guess you could search on how to extends Angular schematics

Then use the -c option of NestJS CLI or define the collection field on your nest-cli.json file

hcharley commented 2 years ago

Thanks for the advice. I have searched on how to extend schematics, but I did it through a search of Nx schematics.

Honestly, it's all a bit confusing because Nx schematics are maybe called Nx generators, and Angular schematics are called Angular schematics. And the documentation seems a bit spread out.

But you're right, I could do more research to figure it out. I just thought that with a popular project like this, it might be helpful to folks. Partly I wanted to create this ticket to document that this is a possibility to those that come behind.

Here's an idea now that my gears are turning: what if this project had a schematic for creating a schematic that extended one of the available schematics? Kind of meta, but it would be cool imho.

micalevisk commented 2 years ago

I agree that having that covered at the docs would be pretty good to the NestJS ecosystem.

If I recall correctly, I manage to extend the @nestjs/schematics collection with no much worries but I didn't have that project anymore to share with you :/ I'll try again in the future.


what if this project had a schematic for creating a schematic that extended one of the available schematics?

sounds good to me.

EDIT: actually, that schematics will be another nodejs project, so having some generator for it in @nestjs/cli (as nest g <foo>) doesn't make much sense. We could have a boilerplate repository tho

jmcdo29 commented 2 years ago

For a nice reference, I extend the schematics in nest-commander a bit to create @Command() classes

soydev019 commented 6 months ago

Do we have any updates ? I would like to have my own templates/schematics using @nestjs/cli but couldn't reach my goal with the current informations I found. I will need a clear documentation on the exact process if possible please