#!/bin/sh
set -e

if [ "$1" = "monaco" ]; then
  rm -rf "dist/vendor/vs"
  path=$(dirname "$(node -p "require.resolve('monaco-editor/package.json')")")/min/vs
  cp -r "$path" "dist/vendor/vs"
  exit 0
fi

if [ -z "$1" ]; then
  export NODE_ENV=production
  make all
  echo "✨ Downloading locales..."
  # crowdin download
  echo "✨ Building gql..."
  ./scripts/build-gql.ts
  echo "✨ Building apps..."
  ./scripts/build-apps.ts -s
  echo "✨ Building license..."
  ./scripts/build-license.ts
else
  path=$(find ./scripts -type f -name "build-$1.*")
  if [ -z "$path" ]; then
    echo "Unknown task '$1'."
    exit 1
  fi
  $path "$@"
fi
