Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNG-5997 node env setup script #480

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions judo-ui-react/src/main/resources/actor/README.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
noherczeg marked this conversation as resolved.
Show resolved Hide resolved
```

> 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:
Expand Down
66 changes: 66 additions & 0 deletions judo-ui-react/src/main/resources/actor/setup-node-env.sh.hbs
Original file line number Diff line number Diff line change
@@ -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
noherczeg marked this conversation as resolved.
Show resolved Hide resolved

# 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
noherczeg marked this conversation as resolved.
Show resolved Hide resolved

# 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
noherczeg marked this conversation as resolved.
Show resolved Hide resolved

# 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
noherczeg marked this conversation as resolved.
Show resolved Hide resolved

# 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}"
noherczeg marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions judo-ui-react/src/main/resources/ui-react.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading