diff --git a/judo-ui-react/src/main/resources/actor/README.md.hbs b/judo-ui-react/src/main/resources/actor/README.md.hbs index 746b53a3..761e5c96 100644 --- a/judo-ui-react/src/main/resources/actor/README.md.hbs +++ b/judo-ui-react/src/main/resources/actor/README.md.hbs @@ -21,27 +21,12 @@ This application has been generated by the JUDO toolbox. ## Setup -### NodeJS -We recommend using [NVM](https://github.com/nvm-sh/nvm) to handle your NodeJS -installation. - -The recommended NodeJS version is `18.15.0` (LTS), or whatever version which has been set in the `.nvmrc` file. - -> If the `.nvmrc` file is empty, we can fix it by setting the `nodeVersion` property in our generator config. - -### PNPM - -For dependency management we are using [PNPM](https://pnpm.io/benchmarks). - -Installing PNPM if you don't have it already: +We recommend using our setup script, which takes care of everything: ``` -npm i -g pnpm +./setup-node-env.sh ``` -> If you are using NVM to manage your NodeJS installs, the global installation of PNPM will - place it under the folder where NVM installed your NodeJS! - ## Local development In order for our frontend application to be able to find our running backend, we need to export the following variables: diff --git a/judo-ui-react/src/main/resources/actor/setup-node-env.sh.hbs b/judo-ui-react/src/main/resources/actor/setup-node-env.sh.hbs new file mode 100755 index 00000000..f9256c25 --- /dev/null +++ b/judo-ui-react/src/main/resources/actor/setup-node-env.sh.hbs @@ -0,0 +1,66 @@ +#!/bin/bash + +# Define the versions to use +NVM_VERSION="0.40.1" # Specify the desired NVM version +DEFAULT_NODE_VERSION="{{ nodeVersion }}" # Specify the default Node.js version to use if .nvmrc is not found +PNPM_VERSION="{{ pnpmVersion }}" # Specify the desired PNPM version + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# Determine the Node.js version to use +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +if [ -f "$SCRIPT_DIR/.nvmrc" ]; then + NODE_VERSION=$(cat "$SCRIPT_DIR/.nvmrc") + echo -e "${GREEN}.nvmrc file detected. Using Node.js version: $NODE_VERSION${NC}" +else + NODE_VERSION=$DEFAULT_NODE_VERSION + echo -e "${YELLOW}.nvmrc file not found. Falling back to default Node.js version: $NODE_VERSION${NC}" +fi + +# Step 1: Install NVM +echo -e "${GREEN}Installing NVM (Node Version Manager) version $NVM_VERSION...${NC}" +curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh" | bash + +# Load NVM script into the current shell session +export NVM_DIR="$HOME/.nvm" +# shellcheck source=/dev/null +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +# Verify NVM installation +if command -v nvm > /dev/null 2>&1; then + echo -e "${GREEN}NVM version $NVM_VERSION installed successfully!${NC}" +else + echo -e "${RED}NVM installation failed! Exiting.${NC}" + exit 1 +fi + +# Step 2: Install the specified version of Node.js using NVM +echo -e "${GREEN}Installing Node.js version $NODE_VERSION...${NC}" +nvm install "$NODE_VERSION" +nvm use "$NODE_VERSION" +nvm alias default "$NODE_VERSION" + +# Verify Node.js installation +if command -v node > /dev/null 2>&1; then + echo -e "${GREEN}Node.js $(node -v) installed successfully!${NC}" +else + echo -e "${RED}Node.js installation failed! Exiting.${NC}" + exit 1 +fi + +# Step 3: Install PNPM globally +echo -e "${GREEN}Installing PNPM version $PNPM_VERSION...${NC}" +npm install -g pnpm@"$PNPM_VERSION" + +# Verify PNPM installation +if command -v pnpm > /dev/null 2>&1; then + echo -e "${GREEN}PNPM $(pnpm -v) installed successfully!${NC}" +else + echo -e "${RED}PNPM installation failed! Exiting.${NC}" + exit 1 +fi + +echo -e "${GREEN}Node.js and PNPM setup complete!${NC}" diff --git a/judo-ui-react/src/main/resources/ui-react.yaml b/judo-ui-react/src/main/resources/ui-react.yaml index 69176b2c..349f771c 100644 --- a/judo-ui-react/src/main/resources/ui-react.yaml +++ b/judo-ui-react/src/main/resources/ui-react.yaml @@ -1,4 +1,8 @@ templates: + - name: actor/setup-node-env.sh + pathExpression: "'setup-node-env.sh'" + templateName: actor/setup-node-env.sh.hbs + - name: actor/biome.json pathExpression: "'biome.json'" templateName: actor/biome.json.hbs