Skip to content

Commit

Permalink
Merge pull request #25783 from mshima/compose-command
Browse files Browse the repository at this point in the history
add compose to command definition.
  • Loading branch information
DanielFran authored Apr 8, 2024
2 parents fc519fe + 79f962b commit d0f9c27
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
21 changes: 21 additions & 0 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
blueprintStorage?: Storage;
/** Allow to use a specific definition at current command operations */
generatorCommand?: JHipsterCommandDefinition;
/**
* @experimental
* Additional commands to be considered
*/
generatorsToCompose: string[] = [];

private _jhipsterGenerator?: string;
private _needleApi?: NeedleApi;
Expand Down Expand Up @@ -352,6 +357,22 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
});
}

/**
* @experimental
* Compose the current JHipster command compose.
* Blueprints commands compose without generators will be composed.
*/
async composeCurrentJHipsterCommand() {
const generatorCommand = await this.getCurrentJHipsterCommand();
for (const compose of generatorCommand.compose ?? []) {
await this.composeWithJHipster(compose);
}

for (const compose of this.generatorsToCompose) {
await this.composeWithJHipster(compose);
}
}

parseJHipsterCommand(commandDef: JHipsterCommandDefinition) {
if (commandDef.arguments) {
this.parseJHipsterArguments(commandDef.arguments);
Expand Down
6 changes: 6 additions & 0 deletions generators/base/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ export type JHipsterCommandDefinition = {
* @example ['server', 'jhipster-blueprint:server']
*/
import?: string[];
/**
* @experimental
* Compose with generator.
* @example ['server', 'jhipster-blueprint:server']
*/
compose?: string[];
/**
* Override options from the generator been blueprinted.
*/
Expand Down
22 changes: 18 additions & 4 deletions generators/base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ export default class JHipsterBaseBlueprintGenerator<
const composedBlueprints: any[] = [];
for (const blueprint of blueprints) {
const blueprintGenerator = await this._composeBlueprint(blueprint.name, subGen, options);
let blueprintCommand;
if (blueprintGenerator) {
composedBlueprints.push(blueprintGenerator);
if ((blueprintGenerator as any).sbsBlueprint) {
Expand All @@ -480,11 +481,24 @@ export default class JHipsterBaseBlueprintGenerator<
this.delegateToBlueprint = true;
this.checkBlueprintImplementsPriorities(blueprintGenerator);
}
const blueprintModule: any = await blueprintGenerator._meta?.importModule?.();
// Use the blueprint command if it is set to override.
if (blueprintModule?.command?.override) {
this.generatorCommand = blueprintModule.command;
const blueprintModule = (await blueprintGenerator._meta?.importModule?.()) as any;
blueprintCommand = blueprintModule?.command;
} else {
const generatorName = packageNameToNamespace(normalizeBlueprintName(blueprint.name));
const generatorNamespace = `${generatorName}:${subGen}`;
const blueprintMeta = await this.env.findMeta(generatorNamespace);
const blueprintModule = (await blueprintMeta?.importModule?.()) as any;
blueprintCommand = blueprintModule?.command;
if (blueprintCommand?.compose) {
this.generatorsToCompose.push(...blueprintCommand.compose);
}
}
if (blueprintCommand?.override) {
if (this.generatorCommand) {
this.log.warn('Command already set, multiple blueprints may be overriding the command. Unexpected behavior may occur.');
}
// Use the blueprint command if it is set to override.
this.generatorCommand = blueprintCommand;
}
}
return composedBlueprints;
Expand Down
3 changes: 3 additions & 0 deletions generators/server/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {

get composing() {
return this.asComposingTaskGroup({
async composeCommand() {
await this.composeCurrentJHipsterCommand();
},
async composeBackendType() {
if (!this.jhipsterConfig.backendType || ['spring-boot', 'java'].includes(this.jhipsterConfig.backendType.toLowerCase())) {
await this.composeWithJHipster(GENERATOR_SPRING_BOOT);
Expand Down

0 comments on commit d0f9c27

Please sign in to comment.