diff --git a/generators/bootstrap/index.js b/generators/bootstrap/index.js index 4dd081079ca5..97596c43fba2 100644 --- a/generators/bootstrap/index.js +++ b/generators/bootstrap/index.js @@ -36,7 +36,7 @@ const { STRING: TYPE_STRING, LONG: TYPE_LONG } = CommonDBTypes; module.exports = class extends BaseGenerator { constructor(args, options) { - super(args, options, { unique: 'namespace' }); + super(args, options, { unique: 'namespace', customCommitTask: true }); /* * When testing a generator with yeoman-test using 'withLocalConfig(localConfig)', it instantiates the diff --git a/generators/server/files.js b/generators/server/files.js index b6531681a857..5b83d347d48e 100644 --- a/generators/server/files.js +++ b/generators/server/files.js @@ -198,6 +198,13 @@ const serverFiles = { { file: 'pom.xml', options: { interpolate: INTERPOLATE_REGEX } }, ], }, + { + condition: generator => generator.buildTool === 'maven', + templates: [ + { file: 'npmw', method: 'copy', noEjs: true }, + { file: 'npmw.cmd', method: 'copy', noEjs: true }, + ], + }, ], serverResource: [ { diff --git a/generators/server/index.js b/generators/server/index.js index 284300e9d28f..93ac17983cbb 100644 --- a/generators/server/index.js +++ b/generators/server/index.js @@ -52,6 +52,30 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator { this.jhipsterOldVersion = this.jhipsterConfig.jhipsterVersion; useBlueprints = !this.fromBlueprint && this.instantiateBlueprints('server'); + + // Not using normal blueprints or this is a normal blueprint. + if (!useBlueprints || (this.fromBlueprint && this.sbsBlueprint)) { + this.setFeatures({ + customInstallTask: function customInstallTask(preferredPm, defaultInstallTask) { + if ((preferredPm && preferredPm !== 'npm') || this.skipClient || this.jhipsterConfig.skipClient) { + return defaultInstallTask(); + } + const gradle = this.jhipsterConfig.buildTool === 'gradle'; + const command = gradle ? './gradlew' : './npmw'; + const args = gradle ? ['npmInstall'] : ['install']; + + const failureCallback = error => { + this.log(chalk.red(`Error executing '${command} ${args.join(' ')}', execute it yourself. (${error.shortMessage})`)); + return true; + }; + + return this.spawnCommand(command, args, { preferLocal: true }).then( + () => true, + error => failureCallback(error) + ); + }.bind(this), + }); + } } // Public API method used by the getter and also by Blueprints diff --git a/generators/server/templates/gradle.properties.ejs b/generators/server/templates/gradle.properties.ejs index 78171d9bf292..5fdb4de45405 100644 --- a/generators/server/templates/gradle.properties.ejs +++ b/generators/server/templates/gradle.properties.ejs @@ -102,3 +102,6 @@ checkstyleVersion=8.40 ## uncomment the below line to enable the selective mode #org.gradle.configureondemand=true + +## Install and use a local version of node and npm. +nodeInstall diff --git a/generators/server/templates/npmw b/generators/server/templates/npmw new file mode 100755 index 000000000000..3d0045e34d8e --- /dev/null +++ b/generators/server/templates/npmw @@ -0,0 +1,23 @@ +#!/bin/sh + +basedir=`dirname "$0"` + +if [ -f "$basedir/mvnw" ]; then + builddir="target/node" + installCommand="$basedir/mvnw frontend:install-node-and-npm@install-node-and-npm" +else + builddir=".gradle/npm" + installCommand="$basedir/gradlew npmSetup" +fi + +NPM_EXE="$basedir/$builddir/npm" + +if ! [ -x "$NPM_EXE" ]; then + $installCommand || true +fi + +if ! [ -x "$NPM_EXE" ]; then + npm "$@" +else + $NPM_EXE "$@" +fi diff --git a/generators/server/templates/npmw.cmd b/generators/server/templates/npmw.cmd new file mode 100644 index 000000000000..f0c285c406b3 --- /dev/null +++ b/generators/server/templates/npmw.cmd @@ -0,0 +1,24 @@ +@echo off + +@setlocal + +set NPMW_DIR=%~dp0 + +if exist "%NPMW_DIR%\mvnw.cmd" ( + set NPM_EXE=%NPMW_DIR%\target\node\npm.cmd + set INSTALL_NPM_COMMAND=%NPMW_DIR%\mvnw.cmd frontend:install-node-and-npm@install-node-and-npm +) else ( + set NPM_EXE=%NPMW_DIR%\.gradle\npm\npm.cmd + set INSTALL_NPM_COMMAND=%NPMW_DIR%\gradlew.bat npmSetup +) + +if not exist %NPM_EXE% ( + call %INSTALL_NPM_COMMAND% +) + +if not exist %NPM_EXE% goto globalNpm + +%NPM_EXE% %* + +:globalNpm +npm %* diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs index ed891f759f1f..c40a6e0bff59 100644 --- a/generators/server/templates/pom.xml.ejs +++ b/generators/server/templates/pom.xml.ejs @@ -1542,7 +1542,7 @@ frontend-maven-plugin - install node and npm + install-node-and-npm install-node-and-npm diff --git a/test-integration/scripts/10-install-jhipster.sh b/test-integration/scripts/10-install-jhipster.sh index 9145459bfdaa..6cedebecb4a0 100755 --- a/test-integration/scripts/10-install-jhipster.sh +++ b/test-integration/scripts/10-install-jhipster.sh @@ -47,7 +47,6 @@ if [[ "$JHI_REPO" == *"/generator-jhipster" ]]; then cd "$JHI_HOME" git --no-pager log -n 10 --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit - npm install -g npm@$(node -e "console.log(require('./generators/generator-constants').NPM_VERSION);") || true npm ci npm install -g "$JHI_HOME" elif [[ "$JHI_GEN_BRANCH" == "release" ]]; then