#!/bin/sh

if command -v nodenv >/dev/null 2>&1; then
    # installing correct node version using nodenv
    nodenv install -s "$(cat .node-version)"
else
    # alternative using nvm
    # shellcheck source=/dev/null
    . ~/.nvm/nvm.sh
    nvm install "$(cat .node-version)"
fi

if [ ! -f ".envrc.local" ]; then
  cp .envrc.local.template .envrc.local
  echo ".envrc.local was created from template, please add your configuration if necessary"
fi

# loads personal (secret) data from separate env file (not checked in)
# NOT using source_if_exists because it's not available in the context of mprocs (sh)
if [ -f ".envrc.local" ]; then
  source .envrc.local
fi