From ac0f3afa2cdd1842d9be86784432037dfeb2511b Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sun, 22 Sep 2024 18:20:03 -0300 Subject: [PATCH] generate-blueprint: add recreatePackageLock option --- generators/generate-blueprint/command.ts | 7 +++++++ generators/generate-blueprint/generator.ts | 8 ++++++++ 2 files changed, 15 insertions(+) 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 59dd31e633d0..96c25c402e29 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) { @@ -349,6 +351,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');