From cabc6cafc940435a782b01611a0160d6d2dbc6cf Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 8 Mar 2022 17:09:17 +0100 Subject: [PATCH] chore: remove code duplication in custom Node.js version logic --- run-build-functions.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 43603fdd..43f88073 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -212,6 +212,12 @@ check_python_version() { fi } +read_node_version_file() { + local nodeVersionFile="$1" + NODE_VERSION="$(cat "$nodeVersionFile")" + echo "Attempting node version '$NODE_VERSION' from $nodeVersionFile" +} + install_dependencies() { local defaultNodeVersion=$1 local defaultRubyVersion=$2 @@ -247,14 +253,12 @@ install_dependencies() { echo "Finished restoring cached node version" fi - if [ -f .nvmrc ] + if [ -f ".nvmrc" ] then - NODE_VERSION=$(cat .nvmrc) - echo "Attempting node version '$NODE_VERSION' from .nvmrc" - elif [ -f .node-version ] + read_node_version_file ".nvmrc" + elif [ -f ".node-version" ] then - NODE_VERSION=$(cat .node-version) - echo "Attempting node version '$NODE_VERSION' from .node-version" + read_node_version_file ".node-version" fi if nvm install --no-progress $NODE_VERSION