diff --git a/generators/generate-blueprint/command.ts b/generators/generate-blueprint/command.ts index a7eebf6748c4..4d6ae7721a0e 100644 --- a/generators/generate-blueprint/command.ts +++ b/generators/generate-blueprint/command.ts @@ -33,6 +33,13 @@ import { const command: JHipsterCommandDefinition = { configs: { + recreatePackageLock: { + description: 'Recreate package lock', + cli: { + type: Boolean, + }, + scope: 'generator', + }, githubRepository: { cli: { description: 'Github Repository', diff --git a/generators/generate-blueprint/generator.ts b/generators/generate-blueprint/generator.ts index f183f3ff6b45..389123b2195c 100644 --- a/generators/generate-blueprint/generator.ts +++ b/generators/generate-blueprint/generator.ts @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { rm } from 'node:fs/promises'; import chalk from 'chalk'; import { camelCase, snakeCase, upperFirst } from 'lodash-es'; @@ -53,6 +54,7 @@ const defaultPublishedFiles = ['generators', '!**/__*', '!**/*.snap', '!**/*.spe export default class extends BaseGenerator { application!: any; + recreatePackageLock!: boolean; async _beforeQueue() { if (!this.fromBlueprint) { @@ -352,6 +354,12 @@ export default class extends BaseGenerator { } = this.options; if (!generateSnapshots) return; + if (this.recreatePackageLock) { + await rm(this.destinationPath('package-lock.json'), { force: true }); + await rm(this.destinationPath('node_modules'), { force: true, recursive: true }); + await this.spawnCommand('npm', ['install'], { stdio: 'inherit' }); + } + try { if (this.options[LINK_JHIPSTER_DEPENDENCY]) { this.log.verboseInfo('Linking generator-jhipster');