#!/bin/bash
# Use provided version argument, or fall back to current version from build.zig.zon
if [ -n "$1" ]; then
    VERSION="$1"
else
    CURRENT_VERSION=v$(grep -E '^\s*\.version\s*=' build.zig.zon | sed -E 's/.*"([^"]+)".*/\1/')
    VERSION="${CURRENT_VERSION}"
fi

cd src/cli/init/template

# Since we are releasing as pre-release it takes the last latest releases
# LATEST_RELEASE_VERSION=$(curl -s https://api.github.com/repos/ziex-dev/ziex/releases/latest | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')
# zig fetch --save "git+https://github.com/ziex-dev/ziex#${LATEST_RELEASE_VERSION}"


echo "Updating template to ziex version: ${VERSION}"
zig fetch --save "git+https://github.com/ziex-dev/ziex#${VERSION}"

npx --yes npm-check-updates -u
# git commit -m"feat: update template to latest ziex"