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 composing component priority. #26080

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions generators/app/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() {
Expand Down
106 changes: 106 additions & 0 deletions generators/app/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally running npm test, the askedQuestion returns undefined. Any clue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm ci?
Requires an updated version of yeoman-test.

[
"baseName",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project-name generator

"applicationType",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server generator

"packageName",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java/bootstrap generator

"buildTool",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java/build-tool generator

"reactive",
"authenticationType",
"serverTestFrameworks",
"databaseType",
"prodDatabaseType",
"devDatabaseType",
"cacheProvider",
"enableHibernateCache",
"serverSideOptions",
Comment on lines +181 to +189
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring-boot generator

"enableTranslation",
"nativeLanguage",
"languages",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

languages generator

"clientFramework",
"clientTestFrameworks",
"withAdminUi",
"clientTheme",
Comment on lines +190 to +193
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client generator

]
`);
});
});

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",
"enableTranslation",
"nativeLanguage",
"languages",
"clientFramework",
"microfrontend",
"clientTestFrameworks",
"withAdminUi",
"clientTheme",
]
`);
});
});

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",
"enableTranslation",
"nativeLanguage",
"languages",
"clientFramework",
]
`);
});
});
});
});
10 changes: 8 additions & 2 deletions generators/base-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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}`);
Expand All @@ -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 }) => {
Expand All @@ -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}`);
Expand All @@ -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}`);
Expand All @@ -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}`);
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions generators/base-application/priorities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const {
PROMPTING,
CONFIGURING,
COMPOSING,
COMPOSING_COMPONENT,
LOADING,
PREPARING,
POST_PREPARING,
Expand Down Expand Up @@ -101,6 +102,8 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti

static COMPOSING = asPriority(COMPOSING);

static COMPOSING_COMPONENT = asPriority(COMPOSING_COMPONENT);

static LOADING = asPriority(LOADING);

static PREPARING = asPriority(PREPARING);
Expand Down
18 changes: 18 additions & 0 deletions generators/base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ export default class JHipsterBaseBlueprintGenerator<
return taskGroup;
}

/**
* Priority API stub for blueprints.
*
* ComposingComponent priority should be used to handle component configuration order.
*/
get composingComponent(): GenericTaskGroup<this, Definition['composingTaskParam']> {
return {};
}

/**
* Utility method to get typed objects for autocomplete.
*/
asComposingComponentTaskGroup(
taskGroup: GenericTaskGroup<this, Definition['composingTaskParam']>,
): GenericTaskGroup<this, Definition['composingTaskParam']> {
return taskGroup;
}

/**
* Priority API stub for blueprints.
*
Expand Down
14 changes: 13 additions & 1 deletion generators/base/priorities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -160,6 +169,7 @@ export const PRIORITY_NAMES = {
PROMPTING,
CONFIGURING,
COMPOSING,
COMPOSING_COMPONENT,
LOADING,
PREPARING,
POST_PREPARING,
Expand All @@ -180,6 +190,7 @@ export const PRIORITY_NAMES_LIST = [
PROMPTING,
CONFIGURING,
COMPOSING,
COMPOSING_COMPONENT,
LOADING,
PREPARING,
POST_PREPARING,
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions generators/common/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down