gitpod-setup.sh 943 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. # Convert context URL to an array
  3. mapfile -t CONTEXT_URL_ITEMS < <(echo "$GITPOD_WORKSPACE_CONTEXT_URL" | tr '/' '\n')
  4. # Install latest pnpm
  5. curl -fsSL https://get.pnpm.io/install.sh | SHELL=`which bash` bash -
  6. # Check if Gitpod started from a specific example directory in the repository
  7. if [ "${CONTEXT_URL_ITEMS[7]}" = "examples" ]; then
  8. EXAMPLE_PROJECT=${CONTEXT_URL_ITEMS[8]}
  9. # Check it Gitpod started with $ASTRO_NEW environment variable
  10. elif [ -n "$ASTRO_NEW" ]; then
  11. EXAMPLE_PROJECT="$ASTRO_NEW"
  12. # Otherwise, set the default example project - 'starter'
  13. else
  14. EXAMPLE_PROJECT="starter"
  15. fi
  16. # Wait for VSCode to be ready (port 23000)
  17. gp ports await 23000 > /dev/null 2>&1
  18. echo "Loading example project: $EXAMPLE_PROJECT"
  19. # Go to the requested example project
  20. cd "$GITPOD_REPO_ROOT"/examples/"$EXAMPLE_PROJECT" || exit
  21. # Open the main page in VSCode
  22. code src/pages/index.astro
  23. # Start Astro
  24. pnpm start