#!/bin/bash

GRADLE_VERSION=6.7.1

export PATH="~/.gradle/${GRADLE_VERSION}:$PATH"
export PATH="~/.gradle/${GRADLE_VERSION}/bin:$PATH"
export GURU_BIN="~/dev/flutter/guru_app/tools/bin"
export PATH="$GURU_BIN:$PATH"

source .deps_env

echo "--- BuildName: ${BUILD_NAME}"
echo "--- AppName: ${APP_NAME}"
echo "--- APP_ID: ${APP_ID}"
echo "--- Platform: ${PLATFORM}"
echo "--- DIR: ${DIR}"


if [ "${PLATFORM}" = "android" ]; then
    gradle w
fi

echo "----- collect deps start-----"

depaudit --platform "${PLATFORM}" --dir "${DIR}" --build_version "${BUILD_NAME}" --app_name "${APP_NAME}" --app_id "${APP_ID}" --engine unity

echo "----- collect deps over -----"

if [ "${PLATFORM}" = "android" ]; then
  
  if [ -f ${DIR}/gradlew ]; then
      ${DIR}/gradlew --stop
      echo "***************** deps collect success! *****************"
  else
      echo "***************** gradlew not found, deps collect failed! *****************"
  fi
  
else
  echo "***************** deps collect success! *****************"
fi