#!/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/nurulhudaapon/zx/releases/latest | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')
# zig fetch --save "git+https://github.com/nurulhudaapon/zx#${LATEST_RELEASE_VERSION}"


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

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