Skip to content

Commit

Permalink
Merge pull request #25232 from mshima/upgrade-blueprints
Browse files Browse the repository at this point in the history
improve upgrade for blueprints
  • Loading branch information
DanielFran committed Feb 17, 2024
2 parents 6918461 + dbcf336 commit 93bfdca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cli/program.mjs
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
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
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

0 comments on commit 93bfdca

Please sign in to comment.