From b7a3f7263bb56f409887ddea275ce8fa726000a8 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 17 Feb 2023 10:17:48 +1100 Subject: [PATCH 1/3] Add script to install current node version The API is conveniently exactly the same as rbenv. --- script/nodenv-install.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 script/nodenv-install.sh diff --git a/script/nodenv-install.sh b/script/nodenv-install.sh new file mode 100755 index 0000000000..f8bcf33f58 --- /dev/null +++ b/script/nodenv-install.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# +# Install our selected Node version defined in the .node-version file. +# +# If our node-build version is outdated and it can't build the version we want +# then we try upgrading node-build and installing again. + +if nodenv install --skip-existing; then + echo "Correct Node version is installed." +else + echo "Upgrading node-build:" + git -C "$(nodenv root)"/plugins/node-build pull + + nodenv install +fi From d377300f32d4d70cf1ac9119911dcdcb407d1980 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 17 Feb 2023 10:24:58 +1100 Subject: [PATCH 2/3] Support installations with homebrew (macOS) The officially recommended installation for Mac is via Homebrew. --- script/nodenv-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/nodenv-install.sh b/script/nodenv-install.sh index f8bcf33f58..f5d5f8cd28 100755 --- a/script/nodenv-install.sh +++ b/script/nodenv-install.sh @@ -9,7 +9,8 @@ if nodenv install --skip-existing; then echo "Correct Node version is installed." else echo "Upgrading node-build:" - git -C "$(nodenv root)"/plugins/node-build pull + # If homebrew (macOS) installed, try that first. Otherwise look in plugins directory. + brew upgrade node-build || git -C "$(nodenv root)"/plugins/node-build pull nodenv install fi From 8f67e9839db57e5039258b8ef7ec5f90465eb4da Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 10 Mar 2023 13:38:59 +1100 Subject: [PATCH 3/3] Apply code suggestion Avoids an error: ./script/nodenv-install.sh: line 13: brew: command not found Co-authored-by: Maikel --- script/nodenv-install.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/script/nodenv-install.sh b/script/nodenv-install.sh index f5d5f8cd28..37081b6d7d 100755 --- a/script/nodenv-install.sh +++ b/script/nodenv-install.sh @@ -9,8 +9,13 @@ if nodenv install --skip-existing; then echo "Correct Node version is installed." else echo "Upgrading node-build:" - # If homebrew (macOS) installed, try that first. Otherwise look in plugins directory. - brew upgrade node-build || git -C "$(nodenv root)"/plugins/node-build pull + + if command -v brew &> /dev/null; then + # Installation via Homebrew is recommended on macOS. + brew upgrade node-build + else + git -C "$(nodenv root)"/plugins/node-build pull + fi nodenv install fi