diff --git a/cli/program.mjs b/cli/program.mjs index d824a452e47..fc793098025 100644 --- a/cli/program.mjs +++ b/cli/program.mjs @@ -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); diff --git a/generators/upgrade/command.ts b/generators/upgrade/command.ts index fbb46139235..75c5870dd6e 100644 --- a/generators/upgrade/command.ts +++ b/generators/upgrade/command.ts @@ -33,6 +33,11 @@ const command: JHipsterCommandDefinition = { default: false, scope: 'generator', }, + executable: { + description: 'Executable command', + type: String, + scope: 'generator', + }, }, import: [GENERATOR_APP], }; diff --git a/generators/upgrade/generator.js b/generators/upgrade/generator.js index 6c9db0ecda5..e3fc39a1ad4 100644 --- a/generators/upgrade/generator.js +++ b/generators/upgrade/generator.js @@ -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) { @@ -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() { @@ -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); + } + } } }, @@ -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, }); }