#!/bin/bash

### Windows
# to run with Bash: "C:\Program Files\Git\bin\bash.exe" ./build/build.sh
###

export CI_BUILD="no"
export SHOULD_BUILD="yes"
export SKIP_PACKAGES="yes"
export VSCODE_LATEST="no"
export VSCODE_QUALITY="stable"

while getopts ":ilp" opt; do
  case "$opt" in
    i)
      export VSCODE_QUALITY="insider"
      ;;
    l)
      export VSCODE_LATEST="yes"
      ;;
    p)
      export SKIP_PACKAGES="no"
      ;;
  esac
done

case "${OSTYPE}" in
  darwin*)
    export OS_NAME="osx"
    ;;
  msys* | cygwin*)
    export OS_NAME="windows"
    ;;
  *)
    export OS_NAME="linux"
    ;;
esac

UNAME_ARCH=$( uname -m )

if [[ "${UNAME_ARCH}" == "arm64" ]]; then
  export VSCODE_ARCH="arm64"
else
  export VSCODE_ARCH="x64"
fi

echo "OS_NAME: ${OS_NAME}"
echo "SKIP_PACKAGES: ${SKIP_PACKAGES}"
echo "VSCODE_ARCH: ${VSCODE_ARCH}"
echo "VSCODE_LATEST: ${VSCODE_LATEST}"
echo "VSCODE_QUALITY: ${VSCODE_QUALITY}"

rm -rf vscode* VSCode*

. get_repo.sh
. build.sh

if [[ "${SKIP_PACKAGES}" == "no" ]]; then
  if [[ "${OS_NAME}" == "windows" ]]; then
    rm -rf build/windows/msi/releasedir
  fi

  . prepare_artifacts.sh
fi
