Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal support for generators to implement jdl incremental generation for config and entities. #19989

Closed
1 task
mshima opened this issue Oct 11, 2022 · 2 comments · Fixed by #23357
Closed
1 task
Labels
area: feature request 💡 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: jhipster-internals $300 https://www.jhipster.tech/bug-bounties/
Milestone

Comments

@mshima
Copy link
Member

mshima commented Oct 11, 2022

Overview of the feature request

Back in JHipster 6, jdl command advertised that it only generates changed entities.
That was somewhat true, but it generated inconsistent source code.
The feature was jdl specific and had not support at generators. This was implemented by passing only changed entities to the generator, but it ignored application dependent configurations and relationships. Since the generator had no knowledge about others entities, relationships primaryKey and label types, that fall back to the default type that are application database dependent, were generated wrongly.
Due to this inconsistent behavior, this option was disabled.

For a consistent result, a jhipster application should be fully prepared.
At jhipster v8 the prepared application and entities are shared between the generators and fully consistent.
Now it's possible to add internal support to configuration and entities changes.

Configuration changes proposal:

  get [BaseApplicationGenerator.WRITING]() {
    return {
      async writeIncrementalConfig({ application, configChanges, sharedOptions }) {
        if (sharedOptions.regenerate || configChanges.cacheProvider?.newValue === 'ehcache') {
          await this.writeFiles({ files: ehcacheFiles, context: application });
        } else if (configChanges.cacheProvider?.oldValue === 'ehcache') {
          await this.deleteFiles({ files: ehcacheFiles, context: application });
        }
      }
    }
  }

Entity and entity changelogs proposal:

  get [BaseApplicationGenerator.WRITING_ENTITIES]() {
    return {
      async writeIncrementalEntities({ application, sharedOptions, entities, changedEntities }) {
        for (const { entity, deleted, added, changes } of changedEntities) {
          if (sharedOptions.regenerate || added) {
            await this.writeFiles({ files: entityFiles, context: entity });
          } else if (deleted) {
            await this.deleteFiles({ files: entityFiles, context: entity });
          }

          for (const entityChange of changes) {
            await this.writeFiles({ files: changelogFiles, context: { ...entity, ...entityChange } });
          }
        }
      }
    }
  }
Motivation for or Use Case

Allow to generate new configuration and entities without overriding custom code.

Related issues or PR

#19978 (comment)
#19761
#8933
#19328
#17006
#14678
#13365
#13833

  • Checking this box is mandatory (this is just to show you read everything)
@mshima
Copy link
Member Author

mshima commented Oct 10, 2023

@DanielFran
Copy link
Member

@mshima approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: feature request 💡 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: jhipster-internals $300 https://www.jhipster.tech/bug-bounties/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants