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

improve upgrade for blueprints #25232

Merged
merged 1 commit into from
Feb 17, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/program.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ export const buildCommands = async ({
errors => done(errors.find(error => error)),
);
}
if (cmdName === 'upgrade') {
options.programName = program.name();
options.createEnvBuilder = createEnvBuilder;
}
const namespace = blueprint ? `${packageNameToNamespace(blueprint)}:${cmdName}` : `${JHIPSTER_NS}:${cmdName}`;
const generatorCommand = getCommand(namespace, args, opts);
return env.run(generatorCommand, options).then(done, done);
Expand Down
5 changes: 5 additions & 0 deletions generators/upgrade/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const command: JHipsterCommandDefinition = {
default: false,
scope: 'generator',
},
executable: {
description: 'Executable command',
type: String,
scope: 'generator',
},
},
import: [GENERATOR_APP],
};
Expand Down
26 changes: 21 additions & 5 deletions generators/upgrade/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const DEFAULT_MERGE_OPTIONS = ['--strategy', 'ours'];

export default class UpgradeGenerator extends BaseGenerator {
requiredPackage = GENERATOR_JHIPSTER;
createEnvBuilder = EnvironmentBuilder.createDefaultBuilder;
createEnvBuilder;
actualApplicationBranch;
silent;
applyConfig;
spawnStdio = 'inherit';
generationCommand = 'jhipster';
executable;

async beforeQueue() {
if (!this.fromBlueprint) {
Expand All @@ -78,6 +78,8 @@ export default class UpgradeGenerator extends BaseGenerator {
if (this.silent) {
this.spawnStdio = 'ignore';
}
this.executable = this.executable ?? this.options.programName ?? 'jhipster';
this.createEnvBuilder = this.options.createEnvBuilder ?? EnvironmentBuilder.createDefaultBuilder;
},

assertJHipsterProject() {
Expand All @@ -93,12 +95,25 @@ export default class UpgradeGenerator extends BaseGenerator {
},

async checkoutDependency() {
if (this.applyConfig) return;

const jhipsterVersion = this.getPackageJsonVersion();
if (!jhipsterVersion) {
throw new Error('No generator-jhipster dependency found in your package.json');
}
if (this.isV7(jhipsterVersion) && jhipsterVersion !== '7.9.4') {
throw new Error('Upgrade the project to JHipster 7.9.4 before upgrading to the latest version.');
if (this.isV7(jhipsterVersion)) {
if (jhipsterVersion !== '7.9.4') {
throw new Error('Upgrade the project to JHipster 7.9.4 before upgrading to the latest version.');
}
if ((this.jhipsterConfig.blueprints ?? []).length > 0) {
const errorMessage =
'Upgrade does not support upgrading a v7 project with blueprints. Please use the jhipster-migrate blueprint.';
if (!this.skipChecks) {
throw new Error(errorMessage);
} else {
this.log.warn(errorMessage);
}
}
}
},

Expand Down Expand Up @@ -174,7 +189,8 @@ export default class UpgradeGenerator extends BaseGenerator {
customCliOptions.push('--with-entities');
}
// Regenerate sources
await this.spawn('npx', ['--no', this.generationCommand, ...customCliOptions, ...DEFAULT_CLI_OPTIONS.split(' ')], {
this.log.info(`Regenerating sources using ${this.programName} executable`);
await this.spawn('npx', ['--no', this.programName, ...customCliOptions, ...DEFAULT_CLI_OPTIONS.split(' ')], {
stdio: this.spawnStdio,
});
}
Expand Down