diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000000..f6cf8fb9aa25 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,22 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/java/.devcontainer/base.Dockerfile + +# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster +ARG VARIANT="17-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT} + +# [Choice] Node.js version: none, lts/*, defaults to generator-jhipster default node version. +ARG NODE_VERSION + +# Copy required generator-jhipster resource to detect node and npm versions +COPY /package.json /tmp/generator-jhipster/ +COPY /generators /tmp/generator-jhipster/generators +COPY /test-integration /tmp/generator-jhipster/test-integration + +RUN /tmp/generator-jhipster/test-integration/scripts/99-print-node-version.sh +RUN export NODE_VERSION=${NODE_VERSION:-$(/tmp/generator-jhipster/test-integration/scripts/99-print-node-version.sh)}; \ + su -p vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install $NODE_VERSION 2>&1"; +RUN npm install -g npm@$(/tmp/generator-jhipster/test-integration/scripts/99-print-npm-version.sh); \ + npm cache clean --force + +# Remove generator-jhipster for final image +RUN rm -rf /tmp/generator-jhipster diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000000..18cc63929448 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,50 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/java +{ + "name": "generator-jhipster", + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + // Update the VARIANT arg to pick a Java version: 11, 17 + // Append -bullseye or -buster to pin to an OS version. + // Use the -bullseye variants on local arm64/Apple Silicon. + "VARIANT": "17-bullseye" + + // Defaults to generator-jhipster's default node version. + //"NODE_VERSION": "" + } + }, + "mounts": [ + // If your system OS/Architecture doesn't matches the container one, you can uncomment the following line and create node_modules_container to keep local and containers node_module usable. + // "source=${localWorkspaceFolder}/node_modules_container,target=/workspaces/generator-jhipster/node_modules,type=bind,consistency=cached", + "source=${localWorkspaceFolder}/../jhipster-samples,target=/workspaces/jhipster-samples,type=bind,consistency=cached" + ], + + "customizations": { + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "java.jdt.ls.java.home": "/docker-java-home" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": ["eamodio.gitlens", "esbenp.prettier-vscode", "github.vscode-github-actions", "hbenl.vscode-mocha-test-adapter"] + } + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.eslintignore b/.eslintignore index a506035ff3b9..aabe916debee 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,6 +2,7 @@ coverage generators/**/templates node_modules +node_modules_container test-integration docs test/templates diff --git a/.gitignore b/.gitignore index 8780216f8c6c..87aee4cd01bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules +node_modules_container coverage .idea *.iml diff --git a/.prettierignore b/.prettierignore index 6c5c11d1b2a3..baa1ba926cf6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,5 @@ node_modules +node_modules_container docs .git jdl/**/.jhipster/** diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a14cdb27ff64..94eb9eb53a07 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -219,14 +219,31 @@ Go to the [generator-jhipster project](https://github.com/jhipster/generator-jhi [Please read the GitHub forking documentation for more information](https://help.github.com/articles/fork-a-repo) -### Set NPM to use the cloned project +### Set `jhipster` command to use the cloned project + +Since v8 `generator-jhipster` is written in typescript. +To run it you need to compile to javascript or use a just-in-time compilation. + +#### Runnning jit executable + +The executable is located at `bin/jhipster.cjs`. +You can alias it to `jhipster` command: + +```shell +alias jhipster="GLOBAL_PATH/generator-jhipster/bin/jhipster.cjs" +``` + +#### Globally linked compiled package In your cloned `generator-jhipster` project, run `npm ci` and then run `npm link`. -`npm ci` will do a clean installation of all the project dependencies. +`npm ci` will do a clean installation of all the project dependencies and compile sources. +`npm run build` can be used to compile sources after each change. `npm link` will make a symbolic link from the global `node_modules` version to point to this folder, so when we run `jhipster`, you will now use the development version of JHipster. +### Test generating applications + For testing, you will want to generate an application, and there is a specific issue here: for each application, JHipster installs a local version of itself. This is made to enable several applications to each use a specific JHipster version (application A uses JHipster 3.1.0, and application B uses JHipster 3.2.0). To overcome this you need to run `npm link generator-jhipster` on the generated project folder as well, so that the local version has a symbolic link to the development version of JHipster. @@ -234,14 +251,14 @@ Also add the option `--skip-jhipster-dependencies` to generate the application i To put it in a nutshell, you need to: -1. run `npm link` on the `generator-jhipster` project (link globally) +1. run `npm link` on the `generator-jhipster` project (link globally) or configure jit executable 2. run `jhipster --skip-jhipster-dependencies` on the generated application folder You can execute `jhipster --install-path` to check where jhipster is being executed from. You can test your setup by making a small change in your cloned generator, and running again on an existing JHipster project: -For projects with jhipster third party library (i.e. react-jhipster, ng-jhipster, etc.) you need to run `npm link` on the library project as well, then npm link the original framework (i.e. react) from the generated project to the library project `cd react-jhipster && npm link /node_modules/react`. +For projects with jhipster third party library (i.e. react-jhipster, etc.) you need to run `npm link` on the library project as well, then npm link the original framework (i.e. react) from the generated project to the library project `cd react-jhipster && npm link /node_modules/react`. ```shell jhipster @@ -289,23 +306,48 @@ Run every test with lint/prettier `npm test` Run every test without lint/prettier -`npx mocha` +`npx esmocha` Update every test snapshot `npm run update-snapshots` Run specific tests -`npx mocha ` +`npx esmocha ` Run specific tests in series (improved error reporting) -`npx mocha --no-parallel` +`npx esmocha --no-parallel` Update specific test snapshot -`npm run update-snapshot -- ` or `npx mocha --no-parallel --updateSnapshot` +`npm run update-snapshot -- ` or `npx esmocha --no-parallel --update-snapshot` Fixing lint and prettier errors `npm run lint-fix` +## DX using vscode + +`generator-jhipster` add a series of vscode configurations for a better developer experience. + +### Development Containers + +Container is built using java, node and npm recommended by `generator-jhipster`. +Once up, you should have the stack maintainers recommends. + +### Execution shortcuts + +Shortcuts are provided to easily generate integration tests samples. + +- go to `Execute and Debug`. +- select the sample's github workflow. +- run the shortcut. +- select the sample. +- sample is generated at `../jhipster-samples/` folder relative the `generator-jhipster` folder. + +Some daily builds samples are available too. + +### Generators tests + +At test tab you can run and debug individual test. + ## Running integration tests locally You can run the builds locally by following below commands diff --git a/generators/server/templates/.devcontainer/devcontainer.json.ejs b/generators/server/templates/.devcontainer/devcontainer.json.ejs index e7310c15c359..8b363fa19a27 100644 --- a/generators/server/templates/.devcontainer/devcontainer.json.ejs +++ b/generators/server/templates/.devcontainer/devcontainer.json.ejs @@ -8,34 +8,39 @@ // Update the VARIANT arg to pick a Java version: 17, 19 // Append -bullseye or -buster to pin to an OS version. // Use the -bullseye variants on local arm64/Apple Silicon. - "VARIANT": "17", + "VARIANT": "<%= JAVA_VERSION %>-bullseye", // Options - "INSTALL_MAVEN": "<%= buildToolMaven %>", - "INSTALL_GRADLE": "<%= buildToolGradle %>", - "NODE_VERSION": "lts/*" + // maven and gradle wrappers are used by default, we don't need them installed globally + // "INSTALL_MAVEN": "<%= buildToolMaven %>", + // "INSTALL_GRADLE": "<%= buildToolGradle %>", + "NODE_VERSION": "<%= nodeVersion %>" } }, - // Set *default* container specific settings.json values on container create. - "settings": { - "java.home": "/docker-java-home" - }, + "customizations": { + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "java.jdt.ls.java.home": "/docker-java-home" + }, - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ <%_ if(clientFrameworkAngular) { _%> - "angular.ng-template", + "angular.ng-template", <%_ } _%> <%_ if(!skipClient) { _%> - "christian-kohler.npm-intellisense", - "firsttris.vscode-jest-runner", - "ms-vscode.vscode-typescript-tslint-plugin", - "dbaeumer.vscode-eslint", + "christian-kohler.npm-intellisense", + "firsttris.vscode-jest-runner", + "ms-vscode.vscode-typescript-tslint-plugin", + "dbaeumer.vscode-eslint", <%_ } _%> - "vscjava.vscode-java-pack", - "pivotal.vscode-boot-dev-pack", - "esbenp.prettier-vscode" - ], + "vscjava.vscode-java-pack", + "pivotal.vscode-boot-dev-pack", + "esbenp.prettier-vscode" + ], + }, + }, // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [ diff --git a/test-integration/scripts/99-print-npm-version.sh b/test-integration/scripts/99-print-npm-version.sh new file mode 100755 index 000000000000..08c36ce23c15 --- /dev/null +++ b/test-integration/scripts/99-print-npm-version.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e +source $(dirname $0)/00-init-env.sh + +echo $JHI_NPM_VERSION