@echo off
title Build Release
cd /d "%~dp0"

if not exist "bin\version.txt" (
    echo Error: bin\version.txt not found!
    pause
    exit /b
)

:: Read the version into a variable (for /f is more reliable than set /p)
for /f "usebackq delims=" %%V in ("bin\version.txt") do set "NODE_VERSION=%%V"

set ZIP_NAME=node-win64.%NODE_VERSION%.zip

echo ==============================================
echo   Packaging Release: %ZIP_NAME%
echo ==============================================
echo.

echo Cleaning old log and config files from bin...
if exist "bin\*.log" del /q "bin\*.log" 2>nul
if exist "bin\*.json" del /q "bin\*.json" 2>nul
if exist "bin\*.toml" del /q "bin\*.toml" 2>nul

if exist "%ZIP_NAME%" (
    echo Removing old %ZIP_NAME%...
    del /q "%ZIP_NAME%"
)

echo Compressing files...
:: Compress the bin folder and all top-level .bat files
powershell -Command "Compress-Archive -Path 'bin', '*.bat' -DestinationPath '%ZIP_NAME%' -Force"

echo.
echo Done! Successfully generated %ZIP_NAME%
pause

