#!/usr/bin/env bash

#
# install-npm-dependencies
#
# Copyright (C) 2009-20 by RStudio, Inc.
#
# Unless you have received this program directly from RStudio pursuant
# to the terms of a commercial license agreement with RStudio, then
# this program is licensed to you under the terms of version 3 of the
# GNU Affero General Public License. This program is distributed WITHOUT
# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
#
#

set -e
source "$(dirname "${BASH_SOURCE[0]}")/../tools/rstudio-tools.sh"

# ensure RSTUDIO_NODE_VERSION is set
if [ -z "${RSTUDIO_NODE_VERSION}" ]; then
	echo "internal error: RSTUDIO_NODE_VERSION is not set"
	exit 1
fi

# set up node variables common to scripts
export NODE_VERSION="${RSTUDIO_NODE_VERSION}"
export NODE_ROOT="node"
export NODE_SUBDIR="${NODE_ROOT}/${NODE_VERSION}"
export NODE_BASE_URL="https://nodejs.org/dist/v${NODE_VERSION}/"

# install node
./install-node

# install yarn
case "$(uname -sm)" in
"Linux aarch64") ./install-yarn-linux-aarch64 ;;
*)               ./install-yarn               ;;
esac

