From 23c9dab36437979e9f52d18c5a4e20f265c41dc7 Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Wed, 19 Jun 2019 09:20:08 +0200
Subject: [PATCH] task-3074 add nvm init script for build process in nodejs
 projects

---
 .../deployment/classes/project.class.php      |  1 +
 shellscripts/nvm_init.sh                      | 59 +++++++++++++++++++
 2 files changed, 60 insertions(+)
 create mode 100644 shellscripts/nvm_init.sh

diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index 471b207c..64ff53c6 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -1647,6 +1647,7 @@ class project extends base {
                 . 'export GIT_SSH="'.$this->_aConfig['appRootDir'].'/shellscripts/gitsshwrapper.sh";'
                 . 'export DIR_SSH_KEYS="'.$this->_aConfig['dataDir'].'/sshkeys";'
                 . 'export DIR_APPROOT="'.$sTempBuildDir.'";'
+                . 'export NVMINIT="'.$this->_aConfig['appRootDir'].'/shellscripts/nvm_init.sh";'
                 . (isset($this->_aConfig['build']['env']) ? $this->_aConfig['build']['env'] : '')
                 ;
         
diff --git a/shellscripts/nvm_init.sh b/shellscripts/nvm_init.sh
new file mode 100644
index 00000000..ea013258
--- /dev/null
+++ b/shellscripts/nvm_init.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+# ======================================================================
+#
+# NVM INIT
+#
+# This is a helper tool for build processes with nodejs.
+# It installs nvm and offers a method to remove nvm again.
+#
+# ----------------------------------------------------------------------
+# 2019-06-18  first lines  <axel.hahn@iml.unibe.ch>
+# ======================================================================
+
+# ----------------------------------------------------------------------
+# CONFIG
+# ----------------------------------------------------------------------
+NVM_REPO=https://github.com/nvm-sh/nvm.git
+
+
+# ----------------------------------------------------------------------
+# FUNCTIONS
+# ----------------------------------------------------------------------
+function nvmremove(){
+    echo "REMOVE NVM ..."
+
+    if [ -z $NVM_DIR ]; then
+        echo ERROR: sorry, NVM_DIR is empty.
+        exit 1
+    fi
+
+    echo -n "Removing NVM from build directory: [$NVM_DIR] ..."
+    rm -rf "$NVM_DIR" || exit 3
+    echo OK
+
+    echo -n "unload ... "
+    nvm unload || exit 2
+    echo OK
+}
+
+# ----------------------------------------------------------------------
+# MAIN
+# ----------------------------------------------------------------------
+
+echo
+echo ===== NVM INIT =====
+echo 
+
+if [ -z $DIR_APPROOT ]; then
+    echo ERROR: this script runs in a onbuilt process only.
+    echo Currently here is no DIR_APPROOT to define a temporary working dir.
+    exit 1
+fi
+
+# INSTALL NVM ... see
+# https://github.com/nvm-sh/nvm#manual-install
+export NVM_DIR="$DIR_APPROOT/.nvm" && (
+  git clone $NVM_REPO "$NVM_DIR"
+  cd "$NVM_DIR"
+  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
+) && . "$NVM_DIR/nvm.sh" || exit 1
-- 
GitLab