There two main approches of handling upgrades when using a code generator:
- The generated code is never touched (only extended...), and regeneration only updates these files
- Generated code is stored in a separate branch where generation is done no changes are done manually, the generated branch is merged with master at each upgrade
I find the first approach hard to work with for two reasons:
- some files can't be extended like package.json ...
- Extending all the files makes for bigger code base and adding simple changes can add a lot of work
the second approch can also be combursume, when you need to merge a big project but I find it to be the best tradeoff
For Jhipster (up to now), all the code is generated in the beggining from a JDL file (jhipster.jh)
In our case we use two blueprints:
npx jhipster import-jdl --blueprints primeng-blueprint jhipster.jh
This automatically creates our initial commit and we create a new branch import-jdl
form this same commit.
Next time we want to regenarate the project:
- we switch back to the branch
import-jdl
git checkout import-jdl
- we update the jhipster version and blueprints in its
package.json
and install them:
npm install
- delete all the files except the ones we need to avoid keeping file not generated anymore:
rm -rf !(".git"|".jhipster"|"jhipster.jh"|"node_modules"|".yo-rc.json")
- modify .yo-rc to remove deleted entities and remove them from the .jhipster folder and restore liquibase files
- regenarte the project:
jhipster import-jdl --blueprints primeng-blueprint,composite-key-server jhipster.jh
When we want to only add a field, or make a small change and there is no risk of forgetting an old file..., we can just regenerate on top of the old files without mentionning the blueprints... by running:
jhipster import-jdl jhipster.jh --force
Once the project is inproducation the command above breaks liquibase, this was known issue as was fixed by creating the diff of the liquibase file manually, now this possible with the new flag: --incremental-changelog
jhipster import-jdl --incremental-changelog jhipster.jh
There is a bug when using incremental changelogs and generating fake-data (relationship fake-data is not present). To fix this you can add --skip-fake-data
carefull, not update application-dev.yml and remove faker profile
And change back "skipFakeData": false
in .yo-rc.json
Often, you don't want to merge directly into master, (you don't have the permissions, their is a CI you want to go through...) in this case:
- you create a branch
merge-import-jdl
from master - merge into it
- fix your tests...
- amend the extra commit if one was added for merging or add a new one for merging
- use
git log
to make sure that you did NOT amend the commit just created in import-jdl in this branch history,with AT MOST ONE for your tests fixes... (the one you ammend) - create a pull request WITHOUT the option squash commits, to endup with the commit from import-jdl inside master, so that, hopefully, next merges don't require you to resolve the same conflicts