From a5adf44f39daad24904b5066648ba91b6cc938a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johanna=20R=C3=BChrig?=
 <TheRealVira@users.noreply.github.com>
Date: Sat, 4 Jan 2025 10:59:35 +0100
Subject: [PATCH] Pf2eTools & 5eTools: Fixing npm build (#1213)

* Fixing #1195

* Fixing also for 5etools.

* Update 5etools.sh

* Update pf2etools.sh

* Update 5etools-install.sh

* Update pf2etools-install.sh

* Update 5etools-install.sh

* Update pf2etools-install.sh

* remove pnpm

* remove pnpm

---------

Co-authored-by: CanbiZ <47820557+MickLesk@users.noreply.github.com>
---
 ct/5etools.sh                |  4 ++++
 ct/pf2etools.sh              |  4 ++++
 install/5etools-install.sh   | 15 +++++++++++++++
 install/pf2etools-install.sh | 15 +++++++++++++++
 4 files changed, 38 insertions(+)

diff --git a/ct/5etools.sh b/ct/5etools.sh
index b0a40cf82..135119f93 100644
--- a/ct/5etools.sh
+++ b/ct/5etools.sh
@@ -51,6 +51,10 @@ function update_script() {
         rm -rf "/opt/${APP}"
         mv "${APP}-src-${RELEASE:1}" "/opt/${APP}"
         mv "/opt/img-backup" "/opt/${APP}/img"
+        cd /opt/5etools
+        $STD npm install
+        $STD npm run build
+        cd ~
         echo "${RELEASE}" >"/opt/${APP}_version.txt"
         msg_ok "Updated base 5etools"
 
diff --git a/ct/pf2etools.sh b/ct/pf2etools.sh
index 43d693c87..ef617afd2 100644
--- a/ct/pf2etools.sh
+++ b/ct/pf2etools.sh
@@ -50,6 +50,10 @@ function update_script() {
         unzip -q "${RELEASE}.zip"
         rm -rf "/opt/${APP}"
         mv "${APP}-${RELEASE:1}" "/opt/${APP}"
+        cd /opt/Pf2eTools
+        $STD npm install
+        $STD npm run build
+        cd ~
         echo "${RELEASE}" >"/opt/${APP}_version.txt"
         msg_ok "Updated ${APP}"
 
diff --git a/install/5etools-install.sh b/install/5etools-install.sh
index 5f9da35d2..48a2efa82 100644
--- a/install/5etools-install.sh
+++ b/install/5etools-install.sh
@@ -23,12 +23,27 @@ $STD apt-get install -y \
   apache2
 msg_ok "Installed Dependencies"
 
+msg_info "Setting up Node.js Repository"
+mkdir -p /etc/apt/keyrings
+curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
+echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
+msg_ok "Set up Node.js Repository"
+
+msg_info "Installing Node.js"
+$STD apt-get update
+$STD apt-get install -y nodejs
+msg_ok "Installed Node.js"
+
 # Setup App
 msg_info "Set up 5etools Base"
 RELEASE=$(curl -s https://api.github.com/repos/5etools-mirror-3/5etools-src/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
 wget -q "https://github.com/5etools-mirror-3/5etools-src/archive/refs/tags/${RELEASE}.zip"
 unzip -q "${RELEASE}.zip"
 mv "5etools-src-${RELEASE:1}" /opt/5etools
+cd /opt/5etools
+$STD npm install
+$STD npm run build
+cd ~
 echo "${RELEASE}" >"/opt/5etools_version.txt"
 rm "${RELEASE}.zip"
 msg_ok "Set up 5etools Base"
diff --git a/install/pf2etools-install.sh b/install/pf2etools-install.sh
index c7b8cfaec..1413ea87d 100644
--- a/install/pf2etools-install.sh
+++ b/install/pf2etools-install.sh
@@ -23,12 +23,27 @@ $STD apt-get install -y \
   git
 msg_ok "Installed Dependencies"
 
+msg_info "Setting up Node.js Repository"
+mkdir -p /etc/apt/keyrings
+curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
+echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
+msg_ok "Set up Node.js Repository"
+
+msg_info "Installing Node.js"
+$STD apt-get update
+$STD apt-get install -y nodejs
+msg_ok "Installed Node.js"
+
 # Setup App
 msg_info "Setup Pf2eTools"
 RELEASE=$(curl -s https://api.github.com/repos/Pf2eToolsOrg/Pf2eTools/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
 wget -q "https://github.com/Pf2eToolsOrg/Pf2eTools/archive/refs/tags/${RELEASE}.zip"
 unzip -q "${RELEASE}.zip"
 mv "Pf2eTools-${RELEASE:1}" /opt/Pf2eTools
+cd /opt/Pf2eTools
+$STD npm install
+$STD npm run build
+cd ~
 echo "${RELEASE}" >/opt/Pf2eTools_version.txt
 msg_ok "Set up Pf2eTools"