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

Rework entity generator #23804

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions generators/base-application/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { mutateApplication } from '../base/support/config.mjs';
const {
LOADING,
PREPARING,
POST_PREPARING,
CONFIGURING_EACH_ENTITY,
LOADING_ENTITIES,
PREPARING_EACH_ENTITY,
Expand Down Expand Up @@ -341,6 +342,7 @@ export default class BaseApplicationGenerator<
![
LOADING,
PREPARING,
POST_PREPARING,

CONFIGURING_EACH_ENTITY,
LOADING_ENTITIES,
Expand Down
6 changes: 6 additions & 0 deletions generators/base-application/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe(`generator - ${generator}`, () => {
// application arg
const loading = esmocha.fn();
const preparing = esmocha.fn();
const postPreparing = esmocha.fn();
const writing = esmocha.fn();
const postWriting = esmocha.fn();
const install = esmocha.fn();
Expand Down Expand Up @@ -106,6 +107,10 @@ describe(`generator - ${generator}`, () => {
return { preparing };
}

get [Generator.POST_PREPARING]() {
return { postPreparing };
}

get [Generator.CONFIGURING_EACH_ENTITY]() {
return { configuringEachEntity };
}
Expand Down Expand Up @@ -236,6 +241,7 @@ describe(`generator - ${generator}`, () => {
expect(configuring).toBeCalledWith(controlArg);
expect(composing).toBeCalledWith(controlArg);
expect(loading).toBeCalledWith(applicationDefaultsArg);
expect(postPreparing).toBeCalledWith(applicationSourceArg);

expect(configuringEachEntity).toBeCalledTimes(3);
expect(configuringEachEntity).toHaveBeenNthCalledWith(1, { ...entityConfiguringArg, entityName: 'One' });
Expand Down
8 changes: 7 additions & 1 deletion generators/base-application/tasks.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ export type BaseApplicationGeneratorDefinition<
// Add application to existing priorities
Record<'loadingTaskParam' | 'preparingTaskParam', ApplicationTaskParam<Definition> & ApplicationDefaultsTaskParam> &
Record<
'defaultTaskParam' | 'postWritingTaskParam' | 'preConflictsTaskParam' | 'installTaskParam' | 'postInstallTaskParam' | 'endTaskParam',
| 'postPreparingTaskParam'
| 'defaultTaskParam'
| 'postWritingTaskParam'
| 'preConflictsTaskParam'
| 'installTaskParam'
| 'postInstallTaskParam'
| 'endTaskParam',
ApplicationTaskParam<Definition>
> &
Record<'writingTaskParam', ApplicationTaskParam<Definition> & { configChanges?: Record<string, { newValue: any; oldValue: any }> }> &
Expand Down
21 changes: 18 additions & 3 deletions generators/base-core/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,21 @@ import { GENERATOR_JHIPSTER, YO_RC_FILE } from '../generator-constants.mjs';
import { convertConfigToOption } from '../../lib/internal/index.mjs';

const { merge, get, set } = _;
const { INITIALIZING, PROMPTING, CONFIGURING, COMPOSING, LOADING, PREPARING, DEFAULT, WRITING, POST_WRITING, INSTALL, POST_INSTALL, END } =
PRIORITY_NAMES;
const {
INITIALIZING,
PROMPTING,
CONFIGURING,
COMPOSING,
LOADING,
PREPARING,
POST_PREPARING,
DEFAULT,
WRITING,
POST_WRITING,
INSTALL,
POST_INSTALL,
END,
} = PRIORITY_NAMES;

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -89,6 +102,8 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti

static PREPARING = asPriority(PREPARING);

static POST_PREPARING = asPriority(POST_PREPARING);

static DEFAULT = asPriority(DEFAULT);

static WRITING = asPriority(WRITING);
Expand Down Expand Up @@ -218,7 +233,7 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
*/
getArgsForPriority(priorityName: string) {
const control = this.sharedData.getControl();
if (priorityName === POST_WRITING || priorityName === PREPARING) {
if (priorityName === POST_WRITING || priorityName === PREPARING || priorityName === POST_PREPARING) {
const source = this.sharedData.getSource();
return [{ control, source }];
}
Expand Down
18 changes: 18 additions & 0 deletions generators/base/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ export default class JHipsterBaseBlueprintGenerator<
return taskGroup;
}

/**
* Priority API stub for blueprints.
*
* Preparing should be used to generate derived properties.
*/
get postPreparing(): GenericTaskGroup<this, Definition['preparingTaskParam']> {
return this.asPreparingTaskGroup({});
}

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

/**
* Priority API stub for blueprints.
*
Expand Down
14 changes: 13 additions & 1 deletion generators/base/priorities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const LOADING_QUEUE = `${QUEUE_PREFIX}${LOADING}`;
const PREPARING = 'preparing';
const PREPARING_QUEUE = `${QUEUE_PREFIX}${PREPARING}`;

const POST_PREPARING = 'postPreparing';
const POST_PREPARING_QUEUE = `${QUEUE_PREFIX}${POST_PREPARING}`;

const MULTISTEP_TRANSFORM = 'multistepTransform';
const MULTISTEP_TRANSFORM_QUEUE = `${QUEUE_PREFIX}${MULTISTEP_TRANSFORM}`;

Expand Down Expand Up @@ -98,9 +101,15 @@ export const CUSTOM_PRIORITIES = [
{
priorityName: PREPARING,
queueName: PREPARING_QUEUE,
before: DEFAULT,
before: POST_PREPARING,
args: generator => generator.getArgsForPriority(PREPARING),
},
{
priorityName: POST_PREPARING,
queueName: POST_PREPARING_QUEUE,
before: DEFAULT,
args: generator => generator.getArgsForPriority(POST_PREPARING),
},
{
priorityName: DEFAULT,
args: generator => generator.getArgsForPriority(DEFAULT),
Expand Down Expand Up @@ -153,6 +162,7 @@ export const PRIORITY_NAMES = {
COMPOSING,
LOADING,
PREPARING,
POST_PREPARING,

DEFAULT,
WRITING,
Expand All @@ -172,6 +182,7 @@ export const PRIORITY_NAMES_LIST = [
COMPOSING,
LOADING,
PREPARING,
POST_PREPARING,

DEFAULT,
WRITING,
Expand All @@ -190,6 +201,7 @@ export const QUEUES = {
COMPOSING_QUEUE,
LOADING_QUEUE,
PREPARING_QUEUE,
POST_PREPARING_QUEUE,

DEFAULT_QUEUE: DEFAULT,
WRITING_QUEUE: WRITING,
Expand Down
3 changes: 1 addition & 2 deletions generators/base/tasks.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ export type BaseGeneratorDefinition<Definition extends GenericSourceTypeDefiniti
| 'endTaskParam',
ControlTaskParam
> &
Record<'postWritingTaskParam', SourceTaskParam<Definition>> &
Record<'preparingTaskParam', SourceTaskParam<Definition>>;
Record<'preparingTaskParam' | 'postPreparingTaskParam' | 'postWritingTaskParam', SourceTaskParam<Definition>>;
Loading