rfcs/4-jhipster-rfc-entity-as-core.md
This RFC proposes to implement entities as JHipster core feature instead of generators.
With JHipster 8 modular proposal, entity related generators would multiply and become a development problem due to generator dependencies order. Probably not viable. A solution for this issue must be implemented.
Another reason is that JHipster has too many generators, this will allow a more concise workflow.
JHipster has a few generators related to entities:
entities generator is used to delegate selected entities to entity generator and database-changelog generator.entity generator is used for prompting, configuring, preparing.client generator is used
server generator is used for entity customizations and writing files related to server.We have priorities to be used on entity generators.
preparingFieldspreparingRelationshipsThose generators and priorities will be replaced by entity focused priorities and internal methods to support the workflow. Some entity related generators may be kept for more specific purpose like prompts.
Planned priorities include:
configuringEachEntity: priority to manipulate entities config.preparingEachEntity: priority to create derived properties for entities to be used by the templates.preparingEachEntityField: priority to create derived properties for fields to be used by the templates.preparingEachEntityRelationship: priority to create derived properties for relationships to be used by the templates.writingEntities: priority to write entity related files.New priorities will have as first argument relevant resources to the priority/task purpose.
get configuringEachEntity () {
return {
configuringEntityTask({ entityName, entityStorage, entityConfig }) {
entityConfig.dto = true;
}
}
}
get preparingEachEntity () {
return {
preparingEntityTask({ entityName, entity }) {
if (entity.dto) {
entityConfig.dtoName = `${entityName}DTO`;
}
}
}
}
get preparingEachEntityField () {
return {
preparingEntityFieldTask({ entityName, entity, field }) {
field.getter = `get${field.fieldName}`;
}
}
}
get preparingEachEntityRelationship () {
return {
preparingEntityRelationshipTask({ entityName, entity, relationship }) {
relationship.getter = `get${relationship.relationshipName}`;
}
}
}
get writingEntities () {
return {
async writeEntityTask({ entities }) {
await this.writeFileToDisk({
sections: entitiesFiles,
context: { entities },
);
await Promise.all(
entities.map(async entity => {
await this.writeFiles({
sections: entityFiles,
context: { entity },
});
})
);
}
}
}
?
The implementation will require changes to yeoman-generator in order to allow tasks arguments and extract tasks to execute them for more than once (each entity/language).
As advantages, we can list:
configuringEachEntityField, others?New priorities will be implemented at v7 as an incremental feature. Entity breaking change implementation will only be migrated to the new priorities at v8 pre-release cycle.