diff --git a/generators/app/generator.js b/generators/app/generator.js index ab8c45a3d8c2..769516dd2bab 100644 --- a/generators/app/generator.js +++ b/generators/app/generator.js @@ -130,8 +130,8 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.configuring); } - get composing() { - return this.asComposingTaskGroup({ + get composingComponent() { + return this.asComposingComponentTaskGroup({ /** * Composing with others generators, must be executed after `configuring` priority to let others * generators `configuring` priority to run. @@ -154,20 +154,11 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { await this.composeWithJHipster(GENERATOR_CLIENT); } }, - /** - * At this point every other generator should already be configured, so, enforce defaults fallback. - */ - saveConfigWithDefaults() { - const config = this.jhipsterConfigWithDefaults; - if (config.entitySuffix === config.dtoSuffix) { - throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals !'); - } - }, }); } - get [BaseApplicationGenerator.COMPOSING]() { - return this.delegateTasksToBlueprint(() => this.composing); + get [BaseApplicationGenerator.COMPOSING_COMPONENT]() { + return this.delegateTasksToBlueprint(() => this.composingComponent); } get writing() { diff --git a/generators/app/generator.spec.ts b/generators/app/generator.spec.ts index 4081b631ca8a..01f254405c0f 100644 --- a/generators/app/generator.spec.ts +++ b/generators/app/generator.spec.ts @@ -165,4 +165,110 @@ describe(`generator - ${generator}`, () => { }); }); }); + describe('questions', () => { + describe('without answers', () => { + before(async () => { + await helpers.run(generatorPath).withSkipWritingPriorities(); + }); + + it('should match order', () => { + expect(runResult.askedQuestions.map(({ name }) => name)).toMatchInlineSnapshot(` +[ + "baseName", + "applicationType", + "packageName", + "buildTool", + "reactive", + "authenticationType", + "serverTestFrameworks", + "databaseType", + "prodDatabaseType", + "devDatabaseType", + "cacheProvider", + "enableHibernateCache", + "serverSideOptions", + "clientFramework", + "clientTestFrameworks", + "withAdminUi", + "clientTheme", + "enableTranslation", + "nativeLanguage", + "languages", +] +`); + }); + }); + + describe('with gateway, gradle and no cacheProvider', () => { + before(async () => { + await helpers + .run(generatorPath) + .withAnswers({ applicationType: 'gateway', buildTool: 'gradle', cacheProvider: 'no' }) + .withSkipWritingPriorities(); + }); + + it('should match order', () => { + expect(runResult.askedQuestions.map(({ name }) => name)).toMatchInlineSnapshot(` +[ + "baseName", + "applicationType", + "packageName", + "buildTool", + "serverPort", + "serviceDiscoveryType", + "authenticationType", + "serverTestFrameworks", + "databaseType", + "prodDatabaseType", + "devDatabaseType", + "cacheProvider", + "enableHibernateCache", + "serverSideOptions", + "enableGradleEnterprise", + "clientFramework", + "microfrontend", + "clientTestFrameworks", + "withAdminUi", + "clientTheme", + "enableTranslation", + "nativeLanguage", + "languages", +] +`); + }); + }); + + describe('with microservice', () => { + before(async () => { + await helpers + .run(generatorPath) + .withAnswers({ applicationType: 'microservice', databaseType: 'mongodb' }) + .withSkipWritingPriorities(); + }); + + it('should match order', () => { + expect(runResult.askedQuestions.map(({ name }) => name)).toMatchInlineSnapshot(` +[ + "baseName", + "applicationType", + "packageName", + "buildTool", + "reactive", + "serverPort", + "serviceDiscoveryType", + "authenticationType", + "feignClient", + "serverTestFrameworks", + "databaseType", + "cacheProvider", + "serverSideOptions", + "clientFramework", + "enableTranslation", + "nativeLanguage", + "languages", +] +`); + }); + }); + }); }); diff --git a/generators/base-application/generator.ts b/generators/base-application/generator.ts index e71908b9c2ed..c914734190be 100644 --- a/generators/base-application/generator.ts +++ b/generators/base-application/generator.ts @@ -577,6 +577,7 @@ export default class BaseApplicationGenerator< taskName: 'queueConfiguringEachEntity', cancellable: true, method: () => { + if (this.options.skipPriorities?.includes(CONFIGURING_EACH_ENTITY)) return; this.log.debug(`Queueing entity tasks ${CONFIGURING_EACH_ENTITY}`); const tasks = this.extractTasksFromPriority(CONFIGURING_EACH_ENTITY, { skip: false }); this.getEntitiesDataToConfigure().forEach(({ entityName, entityStorage, entityConfig }) => { @@ -597,6 +598,7 @@ export default class BaseApplicationGenerator< taskName: 'queueLoadingEntities', cancellable: true, method: () => { + if (this.options.skipPriorities?.includes(LOADING_ENTITIES)) return; this.log.debug(`Queueing entity tasks ${LOADING_ENTITIES}`); const tasks = this.extractTasksFromPriority(LOADING_ENTITIES, { skip: false }); this.log.debug(`Queueing entity tasks ${LOADING_ENTITIES}`); @@ -615,6 +617,7 @@ export default class BaseApplicationGenerator< taskName: 'queuePreparingEachEntity', cancellable: true, method: () => { + if (this.options.skipPriorities?.includes(PREPARING_EACH_ENTITY)) return; this.log.debug(`Queueing entity tasks ${PREPARING_EACH_ENTITY}`); const tasks = this.extractTasksFromPriority(PREPARING_EACH_ENTITY, { skip: false }); this.getEntitiesDataToPrepare().forEach(({ description, ...data }) => { @@ -635,6 +638,7 @@ export default class BaseApplicationGenerator< taskName: 'queuePreparingEachEntityField', cancellable: true, method: () => { + if (this.options.skipPriorities?.includes(PREPARING_EACH_ENTITY_FIELD)) return; const tasks = this.extractTasksFromPriority(PREPARING_EACH_ENTITY_FIELD, { skip: false }); this.getEntitiesFieldsDataToPrepare().forEach(({ description, ...data }) => { this.log.debug(`Queueing entity tasks ${PREPARING_EACH_ENTITY_FIELD} for ${description}`); @@ -654,6 +658,7 @@ export default class BaseApplicationGenerator< taskName: 'queuePreparingEachEntityRelationship', cancellable: true, method: () => { + if (this.options.skipPriorities?.includes(PREPARING_EACH_ENTITY_RELATIONSHIP)) return; const tasks = this.extractTasksFromPriority(PREPARING_EACH_ENTITY_RELATIONSHIP, { skip: false }); this.getEntitiesRelationshipsDataToPrepare().forEach(({ description, ...data }) => { this.log.debug(`Queueing entity tasks ${PREPARING_EACH_ENTITY_RELATIONSHIP} for ${description}`); @@ -673,6 +678,7 @@ export default class BaseApplicationGenerator< taskName: 'queuePostPreparingEachEntity', cancellable: true, method: () => { + if (this.options.skipPriorities?.includes(POST_PREPARING_EACH_ENTITY)) return; const tasks = this.extractTasksFromPriority(POST_PREPARING_EACH_ENTITY, { skip: false }); this.getEntitiesDataToPostPrepare().forEach(({ description, ...data }) => { this.log.debug(`Queueing entity tasks ${POST_PREPARING_EACH_ENTITY} for ${description}`); @@ -692,7 +698,7 @@ export default class BaseApplicationGenerator< taskName: 'queueWritingEachEntity', cancellable: true, method: () => { - if (this.options.skipWriting) return; + if (this.options.skipWriting || this.options.skipPriorities?.includes(WRITING_ENTITIES)) return; const tasks = this.extractTasksFromPriority(WRITING_ENTITIES, { skip: false }); const args = this.getArgsForPriority(WRITING_ENTITIES); tasks.forEach(task => { @@ -709,7 +715,7 @@ export default class BaseApplicationGenerator< taskName: 'queuePostWritingEachEntity', cancellable: true, method: () => { - if (this.options.skipWriting) return; + if (this.options.skipWriting || this.options.skipPriorities?.includes(POST_WRITING_ENTITIES)) return; const tasks = this.extractTasksFromPriority(POST_WRITING_ENTITIES, { skip: false }); const args = this.getArgsForPriority(POST_WRITING_ENTITIES); tasks.forEach(task => { diff --git a/generators/base-application/priorities.js b/generators/base-application/priorities.js index 888e29c4c6f1..fdee8c346827 100644 --- a/generators/base-application/priorities.js +++ b/generators/base-application/priorities.js @@ -143,6 +143,7 @@ export const PRIORITY_NAMES_LIST = [ PRIORITY_NAMES.PROMPTING, PRIORITY_NAMES.CONFIGURING, PRIORITY_NAMES.COMPOSING, + PRIORITY_NAMES.COMPOSING_COMPONENT, PRIORITY_NAMES.LOADING, PRIORITY_NAMES.PREPARING, CONFIGURING_EACH_ENTITY, diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index d009ac4a252c..a00e239f7b5a 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -66,6 +66,7 @@ const { PROMPTING, CONFIGURING, COMPOSING, + COMPOSING_COMPONENT, LOADING, PREPARING, POST_PREPARING, @@ -101,6 +102,8 @@ export default class CoreGenerator extends YeomanGenerator { + return {}; + } + + /** + * Utility method to get typed objects for autocomplete. + */ + asComposingComponentTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { + return taskGroup; + } + /** * Priority API stub for blueprints. * diff --git a/generators/base/priorities.js b/generators/base/priorities.js index 3945bfd7975e..197f6d7c2e9f 100644 --- a/generators/base/priorities.js +++ b/generators/base/priorities.js @@ -44,6 +44,9 @@ const END = 'end'; const COMPOSING = 'composing'; const COMPOSING_QUEUE = `${QUEUE_PREFIX}${COMPOSING}`; +const COMPOSING_COMPONENT = 'composingComponent'; +const COMPOSING_COMPONENT_QUEUE = `${QUEUE_PREFIX}${COMPOSING_COMPONENT}`; + const LOADING = 'loading'; const LOADING_QUEUE = `${QUEUE_PREFIX}${LOADING}`; @@ -89,9 +92,15 @@ export const CUSTOM_PRIORITIES = [ { priorityName: COMPOSING, queueName: COMPOSING_QUEUE, - before: LOADING, + before: COMPOSING_COMPONENT, args: generator => generator.getArgsForPriority(COMPOSING), }, + { + priorityName: COMPOSING_COMPONENT, + queueName: COMPOSING_COMPONENT_QUEUE, + before: LOADING, + args: generator => generator.getArgsForPriority(COMPOSING_COMPONENT), + }, { priorityName: LOADING, queueName: LOADING_QUEUE, @@ -160,6 +169,7 @@ export const PRIORITY_NAMES = { PROMPTING, CONFIGURING, COMPOSING, + COMPOSING_COMPONENT, LOADING, PREPARING, POST_PREPARING, @@ -180,6 +190,7 @@ export const PRIORITY_NAMES_LIST = [ PROMPTING, CONFIGURING, COMPOSING, + COMPOSING_COMPONENT, LOADING, PREPARING, POST_PREPARING, @@ -199,6 +210,7 @@ export const QUEUES = { PROMPTING_QUEUE: PROMPTING, CONFIGURING_QUEUE: CONFIGURING, COMPOSING_QUEUE, + COMPOSING_COMPONENT_QUEUE, LOADING_QUEUE, PREPARING_QUEUE, POST_PREPARING_QUEUE, diff --git a/generators/common/generator.js b/generators/common/generator.js index 931a20f6f53a..890c983bc42c 100644 --- a/generators/common/generator.js +++ b/generators/common/generator.js @@ -161,6 +161,11 @@ export default class CommonGenerator extends BaseApplicationGenerator { // Public API method used by the getter and also by Blueprints get preparing() { return this.asPreparingTaskGroup({ + checkSuffix({ application }) { + if (application.entitySuffix === application.dtoSuffix) { + throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals!'); + } + }, setupConstants({ application }) { // Make constants available in templates application.MAIN_DIR = MAIN_DIR; diff --git a/generators/spring-boot/generator.ts b/generators/spring-boot/generator.ts index 3b7b00af3457..ae7df37436e1 100644 --- a/generators/spring-boot/generator.ts +++ b/generators/spring-boot/generator.ts @@ -164,7 +164,6 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { cacheProvider, skipClient, clientFramework, - enableTranslation, testFrameworks, feignClient, } = this.jhipsterConfigWithDefaults; @@ -181,9 +180,6 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { await this.composeWithJHipster('jhipster:spring-cloud:gateway'); } - if (enableTranslation) { - await this.composeWithJHipster(GENERATOR_LANGUAGES); - } if (testFrameworks?.includes(CUCUMBER)) { await this.composeWithJHipster(GENERATOR_CUCUMBER); } @@ -225,6 +221,20 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.composing); } + get composingComponent() { + return this.asComposingComponentTaskGroup({ + async composeLanguages() { + if (this.jhipsterConfigWithDefaults.enableTranslation) { + await this.composeWithJHipster(GENERATOR_LANGUAGES); + } + }, + }); + } + + get [BaseApplicationGenerator.COMPOSING_COMPONENT]() { + return this.delegateTasksToBlueprint(() => this.composingComponent); + } + get preparing() { return this.asPreparingTaskGroup({ async loadCommand({ application }) {