diff --git a/mac b/mac index a18cfce10..0f5fae151 100755 --- a/mac +++ b/mac @@ -55,7 +55,7 @@ esac brew_uninstall() { if brew_is_installed "$1"; then fancy_echo "Uninstalling %s ..." "$1" - brew uninstall "$@" + brew uninstall -f "$@" fi } @@ -153,14 +153,34 @@ brew_tap 'caskroom/cask' ########################### # NODEJS ########################## + +# Install NVM +if ! command -v nvm >/dev/null; then + fancy_echo "Installing NVM ..." + curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | $SHELL + + # Load NVM + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +else + fancy_echo "NVM already installed. Skipping ..." +fi + nodeversions=`./node-versions.rb` mostrecentnode=$(echo "${nodeversions[@]:-1:1}" | tail -1) -# Install each versions +# Remove any brew installed versions for version in $nodeversions; do - brew_install_or_upgrade $version + brew_uninstall node@$version done +# Install LTS versions of Node +for version in $nodeversions; do + nvm install $version +done + +nvm alias default $mostrecentnode + # Link the last, most recent version brew unlink $mostrecentnode brew link --force $mostrecentnode diff --git a/node-versions.rb b/node-versions.rb index 2854ade55..d9c0e2684 100755 --- a/node-versions.rb +++ b/node-versions.rb @@ -7,4 +7,4 @@ url = URI('https://raw.githubusercontent.com/nodejs/Release/master/schedule.json') result = Net::HTTP.get(url) lts = JSON.parse(result).select {|key, value| value.key?("lts") and Date.parse(value["start"]) < Date.today } -lts.each {|key, value| puts "node@#{key.gsub(/v/, '')}" } +lts.each {|key, value| puts "#{key.gsub(/v/, '')}" }