From 4b68734e562b7d68561b8ca6a08f1dd710ed2b8f Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 1 Mar 2021 14:14:41 +0100 Subject: [PATCH] Generalize node search logic --- package.json | 1 + scripts/find-node.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 scripts/find-node.sh diff --git a/package.json b/package.json index 25f41b42b82ce5..b4e3edafdc5227 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "scripts/packager.sh", "scripts/react_native_pods.rb", "scripts/react-native-xcode.sh", + "scripts/find-node.sh", "template.config.js", "template", "third-party-podspecs" diff --git a/scripts/find-node.sh b/scripts/find-node.sh new file mode 100755 index 00000000000000..c111e70d927bb7 --- /dev/null +++ b/scripts/find-node.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +set -e + +# Define NVM_DIR and source the nvm.sh setup script +[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm" + +if [[ -s "$HOME/.nvm/nvm.sh" ]]; then + . "$HOME/.nvm/nvm.sh" +elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then + . "$(brew --prefix nvm)/nvm.sh" +fi + +# Set up the nodenv node version manager if present +if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then + eval "$("$HOME/.nodenv/bin/nodenv" init -)" +elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then + eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)" +fi + +# Set up the ndenv of anyenv if preset +if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then + export PATH=${HOME}/.anyenv/bin:${PATH} + if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then + eval "$(anyenv init -)" + fi +fi \ No newline at end of file