Skip to content

Commit

Permalink
Merge pull request #25718 from mshima/compose-blueprints
Browse files Browse the repository at this point in the history
Normalize some method calls.
  • Loading branch information
DanielFran authored Apr 3, 2024
2 parents e5b1b29 + cab7171 commit 4eb3058
Show file tree
Hide file tree
Showing 57 changed files with 219 additions and 191 deletions.
8 changes: 3 additions & 5 deletions .blueprint/code-workspace/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { join } from 'path';
import { defaults, merge } from 'lodash-es';
import { merge } from 'lodash-es';
import BaseGenerator from '../../generators/base/index.js';
import { getPackageRoot } from '../../lib/index.js';
import command from './command.mjs';
import { defaultSamplesFolder, promptSamplesFolder, samplesFolderConfig } from '../support.mjs';

export default class extends BaseGenerator {
samplePath;

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
this.parseJHipsterOptions(command.options);
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}
Expand Down
6 changes: 2 additions & 4 deletions .blueprint/from-issue/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Octokit } from 'octokit';
import { setOutput } from '@actions/core';
import BaseGenerator from '../../generators/base/index.js';
import command from './command.mjs';
import { promptSamplesFolder } from '../support.mjs';
import { join } from 'path';
import { GENERATOR_APP, GENERATOR_JDL } from '../../generators/generator-list.js';
Expand Down Expand Up @@ -31,9 +30,8 @@ export default class extends BaseGenerator {

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
this.parseJHipsterOptions(command.options);
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}
Expand Down
6 changes: 2 additions & 4 deletions .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { extname } from 'path';
import { transform } from '@yeoman/transform';
import BaseGenerator from '../../generators/base/index.js';
import command from './command.mjs';
import { generateSample } from './support/generate-sample.js';
import { promptSamplesFolder } from '../support.mjs';
import { GENERATOR_APP, GENERATOR_JDL } from '../../generators/generator-list.js';
Expand All @@ -13,9 +12,8 @@ export default class extends BaseGenerator {

get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
this.parseJHipsterOptions(command.options);
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}
Expand Down
6 changes: 2 additions & 4 deletions .blueprint/update-vscode/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { join } from 'path';
import BaseGenerator from '../../generators/base/index.js';
import { getPackageRoot } from '../../lib/index.js';
import command from './command.mjs';
import { getWorkflowSamples } from '../generate-sample/support/get-workflow-samples.js';

export default class extends BaseGenerator {
get [BaseGenerator.INITIALIZING]() {
return this.asInitializingTaskGroup({
async initializeOptions() {
this.parseJHipsterArguments(command.arguments);
this.parseJHipsterOptions(command.options);
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}
Expand Down
26 changes: 26 additions & 0 deletions generators/angular/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { JHipsterCommandDefinition } from '../base/api.js';

const command: JHipsterCommandDefinition = {
options: {},
import: [],
};

export default command;
2 changes: 1 addition & 1 deletion generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_ANGULAR);
await this.composeWithBlueprints();
}

if (!this.delegateToBlueprint) {
Expand Down
1 change: 1 addition & 0 deletions generators/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
* limitations under the License.
*/
export { default } from './generator.js';
export { default as command } from './command.js';
47 changes: 34 additions & 13 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
jhipsterTemplatesFolders!: string[];

blueprintStorage?: Storage;
/** Allow to use a specific definition at current command operations */
generatorCommand?: JHipsterCommandDefinition;

private _jhipsterGenerator?: string;
private _needleApi?: NeedleApi;
Expand Down Expand Up @@ -292,36 +294,55 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
return priorities;
}

async parseCurrentJHipsterCommand() {
const module: any = await this._meta?.importModule?.();
if (!module?.command) {
throw new Error(`Command not found for generator ${this.options.namespace}`);
/**
* Get the current Command Definition for the generator.
* `generatorCommand` takes precedence.
*/
async getCurrentJHipsterCommand(): Promise<JHipsterCommandDefinition> {
if (!this.generatorCommand) {
const { command } = ((await this._meta?.importModule?.()) ?? {}) as any;
if (!command) {
throw new Error(`Command not found for generator ${this.options.namespace}`);
}
this.generatorCommand = command;
return command;
}
return this.generatorCommand;
}

this.parseJHipsterCommand(module?.command);
/**
* Parse command definition arguments, options and configs.
* Blueprints with command override takes precedence.
*/
async parseCurrentJHipsterCommand() {
const generatorCommand = await this.getCurrentJHipsterCommand();
this.parseJHipsterCommand(generatorCommand!);
}

/**
* Prompts for command definition configs.
* Blueprints with command override takes precedence.
*/
async promptCurrentJHipsterCommand() {
const module: any = await this._meta?.importModule?.();
if (!module?.command?.configs) {
const generatorCommand = await this.getCurrentJHipsterCommand();
if (!generatorCommand.configs) {
throw new Error(`Configs not found for generator ${this.options.namespace}`);
}

return this.prompt(this.prepareQuestions(module?.command?.configs));
return this.prompt(this.prepareQuestions(generatorCommand.configs));
}

/**
* Load the current JHipster command storage configuration into the context.
* Blueprints with command override takes precedence.
*/
async loadCurrentJHipsterCommandConfig(context: any) {
const module: any = await this._meta?.importModule?.();
const command: JHipsterCommandDefinition | undefined = module?.command;
if (!command?.configs) {
const generatorCommand = await this.getCurrentJHipsterCommand();
if (!generatorCommand.configs) {
throw new Error(`Configs not found for generator ${this.options.namespace}`);
}

const config = (this as any).jhipsterConfigWithDefaults;
Object.entries(command.configs).forEach(([name, def]) => {
Object.entries(generatorCommand.configs).forEach(([name, def]) => {
if (def.scope === 'storage') {
context[name] = context[name] ?? config?.[name] ?? this.config.get(name);
}
Expand Down
7 changes: 6 additions & 1 deletion generators/base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { packageNameToNamespace, removeFieldsWithNullishValues } from './support
import { mergeBlueprints, parseBluePrints, loadBlueprintsFromConfiguration, normalizeBlueprintName } from './internal/index.js';
import { PRIORITY_NAMES } from './priorities.js';
import { BaseGeneratorDefinition, GenericTaskGroup } from './tasks.js';
import { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from './api.js';
import type { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from './api.js';
import CoreGenerator from '../base-core/index.js';
import { LOCAL_BLUEPRINT_PACKAGE_NAMESPACE } from './support/constants.js';
import { getConfigWithDefaults } from '../../jdl/index.js';
Expand Down Expand Up @@ -480,6 +480,11 @@ 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;
}
}
}
return composedBlueprints;
Expand Down
4 changes: 2 additions & 2 deletions generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
} from '../base-application/support/index.js';
import { createAuthorityEntity, createUserEntity, createUserManagementEntity } from './utils.js';
import { JAVA_DOCKER_DIR } from '../generator-constants.js';
import { GENERATOR_BOOTSTRAP, GENERATOR_BOOTSTRAP_APPLICATION_BASE, GENERATOR_COMMON, GENERATOR_PROJECT_NAME } from '../generator-list.js';
import { GENERATOR_BOOTSTRAP, GENERATOR_COMMON, GENERATOR_PROJECT_NAME } from '../generator-list.js';
import { packageJson } from '../../lib/index.js';
import { loadLanguagesConfig } from '../languages/support/index.js';
import { loadAppConfig, loadDerivedAppConfig, loadStoredAppOptions } from '../app/support/index.js';
Expand All @@ -55,7 +55,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_BOOTSTRAP_APPLICATION_BASE);
await this.composeWithBlueprints();
}

if (this.delegateToBlueprint) {
Expand Down
5 changes: 2 additions & 3 deletions generators/bootstrap-application-client/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
import { loadClientConfig, loadDerivedClientConfig, preparePostEntityClientDerivedProperties } from '../client/support/index.js';
import BaseApplicationGenerator from '../base-application/index.js';
import { GENERATOR_BOOTSTRAP_APPLICATION_BASE, GENERATOR_BOOTSTRAP_APPLICATION_CLIENT } from '../generator-list.js';
import { loadStoredAppOptions } from '../app/support/index.js';
import clientCommand from '../client/command.js';
import { loadConfig, loadDerivedConfig } from '../../lib/internal/index.js';
Expand All @@ -34,14 +33,14 @@ export default class BootStrapApplicationClient extends BaseApplicationGenerator

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_BOOTSTRAP_APPLICATION_CLIENT);
await this.composeWithBlueprints();
}

if (this.delegateToBlueprint) {
throw new Error('Only sbs blueprint is supported');
}

await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_BASE);
await this.dependsOnBootstrapApplicationBase();
}

get loading() {
Expand Down
5 changes: 2 additions & 3 deletions generators/bootstrap-application-server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import BaseApplicationGenerator from '../base-application/index.js';
import { GENERATOR_BOOTSTRAP_APPLICATION_BASE, GENERATOR_BOOTSTRAP_APPLICATION_SERVER } from '../generator-list.js';
import {
JAVA_VERSION,
MAIN_DIR,
Expand Down Expand Up @@ -56,14 +55,14 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_BOOTSTRAP_APPLICATION_SERVER);
await this.composeWithBlueprints();
}

if (this.delegateToBlueprint) {
throw new Error('Only sbs blueprint is supported');
}

await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_BASE);
await this.dependsOnBootstrapApplicationBase();
}

get loading() {
Expand Down
11 changes: 3 additions & 8 deletions generators/bootstrap-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import {
preparePostEntitiesCommonDerivedProperties,
preparePostEntityCommonDerivedProperties,
} from '../base-application/support/index.js';
import {
GENERATOR_BOOTSTRAP_APPLICATION,
GENERATOR_BOOTSTRAP_APPLICATION_CLIENT,
GENERATOR_BOOTSTRAP_APPLICATION_SERVER,
} from '../generator-list.js';

import { preparePostEntityServerDerivedProperties } from '../server/support/index.js';
import { loadStoredAppOptions } from '../app/support/index.js';
Expand All @@ -52,15 +47,15 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_BOOTSTRAP_APPLICATION);
await this.composeWithBlueprints();
}

if (this.delegateToBlueprint) {
throw new Error('Only sbs blueprint is supported');
}

await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_CLIENT);
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_SERVER);
await this.dependsOnBootstrapApplicationClient();
await this.dependsOnBootstrapApplicationServer();
}

get preparing() {
Expand Down
3 changes: 1 addition & 2 deletions generators/bootstrap-workspaces/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
import BaseWorkspacesGenerator from '../base-workspaces/index.js';

import { GENERATOR_BOOTSTRAP_WORKSPACES } from '../generator-list.js';
import command from './command.js';

export default class DockerComposeGenerator extends BaseWorkspacesGenerator {
Expand All @@ -31,7 +30,7 @@ export default class DockerComposeGenerator extends BaseWorkspacesGenerator {
this.parseJHipsterOptions(command.options);

if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_BOOTSTRAP_WORKSPACES);
await this.composeWithBlueprints();
}
}

Expand Down
9 changes: 4 additions & 5 deletions generators/bootstrap/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ import {
createRemoveUnusedImportsTransform,
} from './support/index.js';
import { PRETTIER_EXTENSIONS } from '../generator-constants.js';
import { GENERATOR_BOOTSTRAP, GENERATOR_UPGRADE } from '../generator-list.js';
import { GENERATOR_UPGRADE } from '../generator-list.js';
import { PRIORITY_NAMES, QUEUES } from '../base-application/priorities.js';
import type { BaseGeneratorDefinition, GenericTaskGroup } from '../base/tasks.js';
import command from './command.js';
import { loadStoredAppOptions } from '../app/support/index.js';

const { MULTISTEP_TRANSFORM, PRE_CONFLICTS } = PRIORITY_NAMES;
Expand Down Expand Up @@ -71,7 +70,7 @@ export default class BootstrapGenerator extends BaseGenerator {
this.upgradeCommand = this.options.commandName === GENERATOR_UPGRADE;

if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_BOOTSTRAP);
await this.composeWithBlueprints();
}

if (this.delegateToBlueprint) {
Expand All @@ -81,8 +80,8 @@ export default class BootstrapGenerator extends BaseGenerator {

get initializing() {
return this.asInitializingTaskGroup({
loadOptions() {
this.parseJHipsterOptions(command.options, command.configs);
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
validateBlueprint() {
if (this.jhipsterConfig.blueprints && !this.skipChecks) {
Expand Down
6 changes: 3 additions & 3 deletions generators/ci-cd/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import chalk from 'chalk';

import BaseApplicationGenerator from '../base-application/index.js';
import statistics from '../statistics.js';
import { GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_CI_CD } from '../generator-list.js';
import { GENERATOR_CI_CD } from '../generator-list.js';
import { clientFrameworkTypes } from '../../jdl/jhipster/index.js';
import { createPomStorage } from '../maven/support/pom-store.js';
import command from './command.js';
Expand All @@ -34,11 +34,11 @@ export default class CiCdGenerator extends BaseApplicationGenerator {

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_CI_CD);
await this.composeWithBlueprints();
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnBootstrapApplication();
}
}

Expand Down
Loading

0 comments on commit 4eb3058

Please sign in to comment.