#!/usr/bin/env sh
dir=$(pwd)

# shellcheck disable=SC2129
printf "\n" >> "$dir/.gitignore"
printf "\n###Yarn 2" >> "$dir/.gitignore"
printf "\n.yarn/*" >> "$dir/.gitignore"
printf "\n!.yarn/releases" >> "$dir/.gitignore"
printf "\n!.yarn/plugins" >> "$dir/.gitignore"
printf "\n.pnp.*" >> "$dir/.gitignore"

# removes node_modules
rm -rf node_modules

# Upgrade Yarn to Berry (latest Yarn 2 version known to Yarn 1)
yarn set version berry

# (optional) Adds `yarn upgrade-interactive` command back
yarn plugin import interactive-tools

# Re-installs project using Yarn 2. This will also update your yarn.lock file, but will NOT sneakily upgrade the dependencies
yarn install