Files
cryptowallet/start.bat
ZOMBIIIIIII a81e29807c add project
2026-04-08 14:11:27 +03:00

125 lines
4.0 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0"
echo.
echo ==========================================
echo CryptoWallet - Local Dev Starter
echo ==========================================
echo.
:: ── 1. Check pnpm ────────────────────────────────────────────────────────────
where pnpm >nul 2>&1
if errorlevel 1 (
echo [ERROR] pnpm not found. Install with: npm install -g pnpm
pause
exit /b 1
)
:: ── 2. Locate PostgreSQL binaries ─────────────────────────────────────────────
set "PGBIN="
if exist "C:\Program Files\PostgreSQL\16\bin\pg_isready.exe" set "PGBIN=C:\Program Files\PostgreSQL\16\bin"
if not defined PGBIN (
where pg_isready >nul 2>&1
if errorlevel 1 (
echo [ERROR] PostgreSQL 16 not found. Expected at C:\Program Files\PostgreSQL\16\bin
pause
exit /b 1
)
)
set "PGPASSWORD=postgres"
:: ── 3. Start local PostgreSQL service ────────────────────────────────────────
echo [1/4] Starting PostgreSQL...
net start postgresql-x64-16 2>nul
timeout /t 2 /nobreak >nul
set /a pg_attempts=0
:waitpg
set /a pg_attempts+=1
if !pg_attempts! gtr 15 (
echo [ERROR] PostgreSQL not responding after 30 seconds.
pause
exit /b 1
)
if defined PGBIN (
"%PGBIN%\pg_isready.exe" -U postgres -q 2>nul
) else (
pg_isready -U postgres -q 2>nul
)
if errorlevel 1 (
timeout /t 2 /nobreak >nul
goto waitpg
)
echo PostgreSQL is ready.
:: ── 4. Ensure DB exists (create only if missing) ────────────────────────────
echo [2/4] Ensuring database...
if defined PGBIN (
"%PGBIN%\psql.exe" -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='cryptowallet_v2'" 2>nul | findstr "1" >nul 2>nul
) else (
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='cryptowallet_v2'" 2>nul | findstr "1" >nul 2>nul
)
if errorlevel 1 (
echo Creating database cryptowallet_v2...
if defined PGBIN (
"%PGBIN%\psql.exe" -U postgres -c "CREATE DATABASE cryptowallet_v2" 2>nul
) else (
psql -U postgres -c "CREATE DATABASE cryptowallet_v2" 2>nul
)
) else (
echo Database exists.
)
:: ── 5. Install deps + migrate ────────────────────────────────────────────────
echo [3/4] Installing dependencies...
if not exist .env (
copy .env.example .env >nul
echo Created .env from .env.example
)
call pnpm install
if errorlevel 1 (
echo [ERROR] pnpm install failed.
pause
exit /b 1
)
echo Dependencies installed.
echo Running migrations...
cd apps\api
call pnpm migrate
if errorlevel 1 (
echo [ERROR] Migrations failed.
pause
exit /b 1
)
cd ..\..
echo Migrations done.
:: ── 6. Stop old processes and start servers ──────────────────────────────────
echo [4/4] Starting servers...
powershell -NoProfile -Command "Get-NetTCPConnection -LocalPort 3000,3001 -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }"
if exist apps\web\.next\dev\lock del apps\web\.next\dev\lock 2>nul
timeout /t 1 /nobreak >nul
start "CryptoWallet API [port 3001]" cmd /k "cd /d %~dp0apps\api && pnpm dev"
timeout /t 2 /nobreak >nul
start "CryptoWallet Web [port 3000]" cmd /k "cd /d %~dp0apps\web && pnpm dev"
echo.
echo ==========================================
echo All services started!
echo.
echo Web: http://localhost:3000
echo API: http://localhost:3001
echo DB: localhost:5432 / cryptowallet_v2
echo ==========================================
echo.
timeout /t 3 /nobreak >nul
start http://localhost:3000
pause >nul
endlocal