#!/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 templates/_base
echo "Updating template to ziex version: ${VERSION} of base template"
zig fetch --save "git+https://github.com/ziex-dev/ziex#${VERSION}"


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