From 6dd20cb64f02e26f9899ef154855a159509eb8ef Mon Sep 17 00:00:00 2001 From: Mudassir Shabbir <53943791+amessbee@users.noreply.github.com> Date: Sat, 6 Jul 2024 08:55:27 +0000 Subject: [PATCH] feat: offer-up script changes to work on codespaces --- package.json | 2 +- set.hostname.sh | 28 ++++++++++++++++++++++++++++ ui/package.json | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100755 set.hostname.sh diff --git a/package.json b/package.json index ce4534c..f40ec59 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "docker:bash": "cd contract; docker compose exec agd bash", "docker:make": "cd contract; docker compose exec agd make -C /workspace/contract", "make:help": "make -C contract list", - "start:contract": "cd contract && yarn start", + "start:contract": "./set.hostname.sh && cd contract && yarn start", "start:ui": "cd ui && yarn dev", "lint": "yarn workspaces run lint", "test": "yarn workspaces run test", diff --git a/set.hostname.sh b/set.hostname.sh new file mode 100755 index 0000000..b92424e --- /dev/null +++ b/set.hostname.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Step 1: Read the environment variable CODESPACE_NAME +CODESPACE_NAME="${CODESPACE_NAME}" + +# Step 2: Define the file name +FILE="ui/src/App.tsx" + +# Check if the file exists +if [ ! -f "$FILE" ]; then + echo "File $FILE does not exist." + exit 1 +fi + +# Step 3: Check if the environment variable is set and replace accordingly +if [ -z "$CODESPACE_NAME" ]; then + echo "CODESPACE_NAME is not set. Setting host with http://localhost" + sed -i "s|https://.*-1317\.app\.github\.dev/|http://localhost:1317|g" "$FILE" + sed -i "s|https://.*-26657\.app\.github\.dev/|http://localhost:26657|g" "$FILE" +else + echo "CODESPACE_NAME is set to $CODESPACE_NAME. Setting host with https://${CODESPACE_NAME}-1317.app.github.dev/" + sed -i "s|https://.*-1317\.app\.github\.dev/|https://${CODESPACE_NAME}-1317.app.github.dev/|g" "$FILE" + echo "CODESPACE_NAME is set to $CODESPACE_NAME. Setting host with https://${CODESPACE_NAME}-26675.app.github.dev/" + sed -i "s|https://.*-26657\.app\.github\.dev/|https://${CODESPACE_NAME}-26657.app.github.dev/|g" "$FILE" +fi + +# Step 4: Notify the user of completion +echo "Replacement complete in $FILE" diff --git a/ui/package.json b/ui/package.json index 6f5356a..664db26 100644 --- a/ui/package.json +++ b/ui/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "./set.hostname.sh && vite", + "dev": "vite", "build": "tsc && vite build", "test": "vitest spec", "test:e2e": "SKIP_EXTENSION_SETUP=true EXTENSION=keplr synpress run --configFile=test/e2e/synpress.config.cjs",