diff --git a/prepare_public_folder.sh b/prepare_public_folder.sh
index fa2b3addb..878e23263 100755
--- a/prepare_public_folder.sh
+++ b/prepare_public_folder.sh
@@ -3,35 +3,36 @@
set -e
# Create the public folder to be published on Pages
+rm -rf public
mkdir -p public
-# Set an entrypoint to avoid 404 on Pages
echo "
JS SDK Playground
" > public/index.html
# Fetch origin to list the branches below
-git fetch --no-tags
+git fetch --prune --no-tags
# Loop all the branches and - for each - build the SDK, build the playground-js
# and copy the `dist` folder in the global `public` folder.
-for branch_name in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/); do
- # Remove `remote/` from refname
- branch=${branch_name/origin\//}
- if [[ $branch == "canary" ]]; then
- # canary branch is too old!
- echo "Skip canary branch"
- continue
- fi
-
- folder="public/$branch"
- echo "\nCreate folder $folder"
- mkdir -p $folder
+for remote in $( \
+ git branch -r \
+ | awk '{print $1}' \
+ | grep '^origin/' \
+ | grep -vE '^origin/(HEAD|canary)$' \
+); do
+ branch="${remote#origin/}"
+
+ echo "Processing branch: $branch"
+
+ echo "Creating public/$branch"
+ mkdir -p "public/$branch"
+
echo "Checkout $branch"
git switch -f "$branch"
-
+
echo "NPM install and Build SDK for this branch"
# TODO: Build only JS/required sdks
npm ci && npm run build
-
- echo "Build playgrounds"
+
+ echo "Building playgrounds for $branch"
{
# VITE_BASE used in internal/playground-js/vite.config.ts
VITE_BASE="/signalwire-js/$branch/" npm run -w=@sw-internal/playground-js build