From 8f13b3d4068f0f017186fbc2dbd33a1427768ea4 Mon Sep 17 00:00:00 2001 From: Ofer Shaal Date: Wed, 16 Mar 2022 11:24:01 -0400 Subject: [PATCH] logic for opening example projects (#2811) --- .gitpod.yml | 2 +- .gitpod/gitpod-setup.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 .gitpod/gitpod-setup.sh diff --git a/.gitpod.yml b/.gitpod.yml index 6d12b9fff..97ce81997 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -7,7 +7,7 @@ tasks: pnpm install pnpm run build command: | - [[ ! -z "$ASTRO_NEW" ]] && gp await-port 23000 && cd "$GITPOD_REPO_ROOT"/examples/"$ASTRO_NEW" && code src/pages/index.astro && pnpm start + .gitpod/gitpod-setup.sh vscode: extensions: - astro-build.astro-vscode diff --git a/.gitpod/gitpod-setup.sh b/.gitpod/gitpod-setup.sh new file mode 100755 index 000000000..883b3b1c9 --- /dev/null +++ b/.gitpod/gitpod-setup.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Convert context URL to an array +mapfile -t CONTEXT_URL_ITEMS < <(echo "$GITPOD_WORKSPACE_CONTEXT_URL" | tr '/' '\n') + +# Check if Gitpod started from a specific example directory in the repository +if [ "${CONTEXT_URL_ITEMS[7]}" = "examples" ]; then + EXAMPLE_PROJECT=${CONTEXT_URL_ITEMS[8]} +# Check it Gitpod started with $ASTRO_NEW environment variable +elif [ -n "$ASTRO_NEW" ]; then + EXAMPLE_PROJECT="$ASTRO_NEW" +# Otherwise, set the default example project - 'starter' +else + EXAMPLE_PROJECT="starter" +fi + +# Wait for VSCode to be ready (port 23000) +gp await-port 23000 > /dev/null 2>&1 + +echo "Loading example project:" $EXAMPLE_PROJECT + +# Go to the requested example project +cd "$GITPOD_REPO_ROOT"/examples/"$EXAMPLE_PROJECT" || exit +# Open the main page in VSCode +code src/pages/index.astro +# Start Astro +pnpm start