@echo off
setlocal

echo Nodarama Verbatim system update shortcut
echo Shortcut owner: %~dp0
echo.

cd /d "%~dp0\.."
if errorlevel 1 (
  echo Could not switch to Verbatim project root.
  pause
  exit /b 1
)

echo Project root: %CD%
echo Arguments: %*
echo.

if not exist ".temp" mkdir ".temp"

if not exist "node_modules" (
  echo Installing Nodarama dependencies...
  call npm install
  if errorlevel 1 (
    echo Dependency install failed. Install Node.js LTS, then run UPDATE again from the sysutil folder.
    pause
    exit /b 1
  )
)

echo Running release preflight and system export...
echo.
call npx tsx sysutil/update.ts %*
set UPDATE_EXIT=%ERRORLEVEL%
echo.

if not "%UPDATE_EXIT%"=="0" (
  echo System update export reported an error. Exit code: %UPDATE_EXIT%
  pause
  exit /b %UPDATE_EXIT%
)

echo System update export complete.
pause
exit /b 0
