jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

Generate side-by-side code and templates #19155

Closed buurd closed 2 years ago

buurd commented 2 years ago
Overview of the feature request

One of the general problems of a code-generator is how to handle the fact that one would like to change the generated code... but then if you would like to regenerate the code your changes is overwritten. This is documented at https://www.jhipster.tech/tips/035_tip_combine_generation_and_custom_code.html. The preferred solution in my mind it the side-by-side-option. This feature-request is about generate side-by-side-code as default.

Motivation for or Use Case

I am going to develop a system that is going to live a long time, eg not a prototype. But it is still CRUD and a code-generator feels like the perfect option since all changes are in the domain/database-layer. The CRUD operations is the constant. But there still are a few things we must change, texts, some view-options (show custom info instead of the id) etc etc.

So our case is that I really would like to regenerate the application with the code-generator, but don't want to re-apply our changes for each iteration. We could of course invent our own schemes for i18n (to take one example) to not be regenerated but I would feel much more secure if the generator draws a clear line between private code for the generator and extension points and provides those structures where the custom-code should be placed, for instance sub-classes of the code that is generated from the jdl.

Related issues or PR

https://github.com/jhipster/generator-jhipster/issues/12497

amatosg commented 2 years ago

I've been doing this for a long time. The best practice is to extend the classes. Never touch the generated ones :) @agoncal made an inspiring video a while ago: https://www.youtube.com/watch?v=9WVpwIUEty0

buurd commented 2 years ago

@amatosg Yes, I'd like JHipster to generate the side-by-side classes. Eg provide empty classes that are supposed to be modified by the developer. Both for front and backend. Instead of leaving it as an exercise for the developer.

amatosg commented 2 years ago

Creating empty classes doesn't seem logical, plus you will have to view the generator to skip those classes. You only need to extend the interface and then the same with the implementation.

buurd commented 2 years ago

So, a small modification to the suggestion could be to add a generator that will create the classes if not already exists but not overwrite. Empty classes is a small cost if it provides a clear separation of what code to change and what code to stay away from, in my mind at least. You should rarely need to answer anything but "change all" after a modification of the JDL, even in the first Helloworld-projects. Now you need to understand a great deal about Jhipster before you can regenerate in a save way.

Tcharl commented 2 years ago

Closing as there's already an open issue on the topic: https://github.com/jhipster/generator-jhipster/issues/12497