Skip to content

Commit

Permalink
rework beforeQueue for non java blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 25, 2023
1 parent 9cf46b9 commit 6d41d02
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 75 deletions.
7 changes: 5 additions & 2 deletions generators/angular/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ export default class AngularGenerator extends BaseApplicationGenerator {
localEntities?: any[];

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

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
}
}

get loading() {
Expand Down
5 changes: 4 additions & 1 deletion generators/app/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
async beforeQueue() {
loadStoredAppOptions.call(this);

await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_BASE);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_APP);
}

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

get initializing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/ci-cd/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ export default class CiCdGenerator extends BaseApplicationGenerator {
}

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

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

// Public API method used by the getter and also by Blueprints
Expand Down
10 changes: 6 additions & 4 deletions generators/client/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator {
async beforeQueue() {
loadStoredAppOptions.call(this);

// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);

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

if (!this.delegateToBlueprint) {
// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);
}
}

get initializing() {
Expand Down
8 changes: 5 additions & 3 deletions generators/common/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export default class CommonGenerator extends BaseApplicationGenerator {
async beforeQueue() {
loadStoredAppOptions.call(this);

await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_GIT);

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

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

get initializing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/cucumber/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import cleanupTask from './cleanup.mjs';

export default class CucumberGenerator extends BaseApplicationGenerator {
async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_CUCUMBER);
}

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

get writing() {
Expand Down
7 changes: 5 additions & 2 deletions generators/cypress/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ const { ANGULAR } = clientFrameworkTypes;

export default class CypressGenerator extends BaseApplicationGenerator {
async beforeQueue() {
// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_CYPRESS);
}

if (!this.delegateToBlueprint) {
// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
}
}

get prompting() {
Expand Down
7 changes: 5 additions & 2 deletions generators/docker/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ export default class DockerGenerator extends BaseApplicationGenerator {
hasServicesFile = false;

async beforeQueue() {
// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_SERVER.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_SERVER);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_DOCKER);
}

if (!this.delegateToBlueprint) {
// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_SERVER.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_SERVER);
}
}

get preparing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/gatling/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import writeEntityTask, { cleanupEntitiesTask } from './entity-files.mjs';

export default class GatlingGenerator extends BaseApplicationGenerator {
async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_GATLING);
}

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

get writing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/generate-blueprint/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ const { GENERATOR_PROJECT_NAME, GENERATOR_INIT, GENERATOR_GENERATE_BLUEPRINT } =

export default class extends BaseGenerator {
async _beforeQueue() {
await this.dependsOnJHipster(GENERATOR_PROJECT_NAME);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_GENERATE_BLUEPRINT);
}

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

get initializing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/git/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ export default class InitGenerator extends BaseGenerator {
skipGit;

async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_PROJECT_NAME);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_GIT);
}

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

get initializing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/gradle/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ import {
export default class GradleGenerator extends BaseApplicationGenerator {
async beforeQueue() {
if (!this.fromBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_SERVER);
await this.composeWithBlueprints(GENERATOR_GRADLE);
}

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

get configuring() {
Expand Down
5 changes: 4 additions & 1 deletion generators/init/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ import { packageJson } from '../../lib/index.mjs';
*/
export default class InitGenerator extends BaseApplicationGenerator {
async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_PROJECT_NAME);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_INIT);
}

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

get initializing() {
Expand Down
5 changes: 4 additions & 1 deletion generators/java/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ export default class JavaGenerator extends BaseApplicationGenerator<GeneratorDef
packageInfoFile = true;

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

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

get initializing() {
Expand Down
6 changes: 4 additions & 2 deletions generators/languages/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ export default class LanguagesGenerator extends BaseApplicationGenerator {
}

async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);

if (!this.fromBlueprint) {
this.supportedLanguages = supportedLanguages;
this.composedBlueprints = await this.composeWithBlueprints('languages', {
generatorArgs: this.options.languages,
});
}

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

// Public API method used by the getter and also by Blueprints
Expand Down
5 changes: 4 additions & 1 deletion generators/liquibase/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
}

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

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

get initializing() {
Expand Down
19 changes: 16 additions & 3 deletions generators/maven/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ export default class MavenGenerator extends BaseApplicationGenerator<SpringBootG
pomStorage!: PomStorage;

async beforeQueue() {
this.pomStorage = createPomStorage(this);

if (!this.fromBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_SERVER);
await this.composeWithBlueprints(GENERATOR_MAVEN);
}

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

get initializing() {
return this.asInitializingTaskGroup({
pomStorage() {
this.pomStorage = createPomStorage(this);
},
});
}

get [BaseApplicationGenerator.INITIALIZING]() {
return this.delegateTasksToBlueprint(() => this.initializing);
}

get configuring() {
Expand Down
4 changes: 2 additions & 2 deletions generators/maven/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ describe(`generator - ${generator}`, () => {
.withGenerators([
[
class extends MavenGenerator {
get [MavenGenerator.PREPARING]() {
return super.preparing;
constructor(args, options, features) {
super(args, options, { ...features, sbsBlueprint: true });
}

get [MavenGenerator.POST_WRITING]() {
Expand Down
7 changes: 5 additions & 2 deletions generators/react/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ const { REACT } = clientFrameworkTypes;
*/
export default class ReactGenerator extends BaseApplicationGenerator {
async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_REACT);
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
}
}

get loading() {
Expand Down
53 changes: 28 additions & 25 deletions generators/server/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,36 +156,20 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
fakeKeytool;
command = command;

async beforeQueue() {
loadStoredAppOptions.call(this);

// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_SERVER.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);
await this.dependsOnJHipster(GENERATOR_JAVA);

async beforeQueue(useNpmWrapper = true) {
if (!this.fromBlueprint) {
loadStoredAppOptions.call(this);
await this.composeWithBlueprints(GENERATOR_SERVER);
}

// Not using normal blueprints or this is a normal blueprint.
if ((!this.fromBlueprint && !this.delegateToBlueprint) || (this.fromBlueprint && this.sbsBlueprint)) {
this.setFeatures({
customInstallTask: async function customInstallTask(preferredPm, defaultInstallTask) {
const buildTool = this.jhipsterConfig.buildTool;
if ((preferredPm && preferredPm !== 'npm') || this.jhipsterConfig.skipClient || (buildTool !== GRADLE && buildTool !== MAVEN)) {
return defaultInstallTask();
}
if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);
await this.dependsOnJHipster(GENERATOR_JAVA);

const npmCommand = process.platform === 'win32' ? 'npmw' : './npmw';
try {
await this.spawnCommand(npmCommand, ['install'], { preferLocal: true });
} catch (error) {
this.log.error(chalk.red(`Error executing '${npmCommand} install', please execute it yourself. (${error.shortMessage})`));
}
return true;
}.bind(this),
});
if (useNpmWrapper) {
this.useNpmWrapperInstallTask();
}
}
}

Expand Down Expand Up @@ -977,6 +961,25 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
}
}

useNpmWrapperInstallTask() {
this.setFeatures({
customInstallTask: async function customInstallTask(preferredPm, defaultInstallTask) {
const buildTool = this.jhipsterConfig.buildTool;
if ((preferredPm && preferredPm !== 'npm') || this.jhipsterConfig.skipClient || (buildTool !== GRADLE && buildTool !== MAVEN)) {
return defaultInstallTask();
}

const npmCommand = process.platform === 'win32' ? 'npmw' : './npmw';
try {
await this.spawnCommand(npmCommand, ['install'], { preferLocal: true });
} catch (error) {
this.log.error(chalk.red(`Error executing '${npmCommand} install', please execute it yourself. (${error.shortMessage})`));
}
return true;
}.bind(this),
});
}

_validateRelationship(entityName, relationship) {
if (relationship.otherEntityName === undefined) {
throw new Error(
Expand Down
Loading

0 comments on commit 6d41d02

Please sign in to comment.