@echo off chcp 65001 >nul setlocal enabledelayedexpansion :: ================= Config ================= set "USER=dell" set "PASS=xd123456@.." set "IP=1.15.17.182" set "PORT=10000" set "DIST_DIR=dist" set "REMOTE_DIR=/home/vue/newpro-product" set "SSH_OPTS=-o StrictHostKeyChecking=no -o ConnectTimeout=10" :: =========================================== echo ========================================== echo Vue Dist Auto Deploy Script echo ========================================== echo. :: Check if sshpass is available where sshpass >nul 2>&1 if %errorlevel% neq 0 ( echo [WARN] sshpass not found, trying to install... echo. where bash >nul 2>&1 if %errorlevel% equ 0 ( echo [INFO] Git Bash detected, trying pacman install... bash -c "pacman -S --noconfirm sshpass" 2>nul if !errorlevel! equ 0 ( echo [OK] sshpass installed via pacman! goto :check_dist ) ) set "SSHPASS_DIR=%~dp0bin" if not exist "!SSHPASS_DIR!" mkdir "!SSHPASS_DIR!" echo [INFO] Downloading sshpass... powershell -NoProfile -Command "$url='https://github.com/xhcoding/sshpass-win32/releases/download/v1.0.3/sshpass.exe'; $out='!SSHPASS_DIR!\sshpass.exe'; Write-Host \"Downloading to: $out\"; try { Invoke-WebRequest -Uri $url -OutFile $out -UseBasicParsing; exit 0 } catch { Write-Host $_.Exception.Message; exit 1 }" if !errorlevel! neq 0 ( echo [ERROR] Failed to download sshpass! echo [HINT] Please install sshpass manually or use Git Bash: pacman -S sshpass goto :error_exit ) set "PATH=!SSHPASS_DIR!;%PATH%" echo [OK] sshpass downloaded to: !SSHPASS_DIR! echo. ) :check_dist if not exist "%DIST_DIR%" ( echo [ERROR] Dist directory not found: %DIST_DIR% echo [HINT] Please run 'npm run build' first! goto :error_exit ) :: Count files and calculate size set "FILE_COUNT=0" set "TOTAL_SIZE=0" for /r "%DIST_DIR%" %%F in (*) do ( set /a "FILE_COUNT+=1" set /a "TOTAL_SIZE+=%%~zF" ) set /a "TOTAL_SIZE_MB=TOTAL_SIZE/1024/1024" echo [INFO] Dist directory: %DIST_DIR% echo [INFO] Files count: %FILE_COUNT% echo [INFO] Total size: %TOTAL_SIZE_MB% MB echo [INFO] Target: %USER%@%IP%:%PORT% echo [INFO] Remote dir: %REMOTE_DIR% echo. :: Upload dist directory echo [STEP 2/2] Uploading dist directory... sshpass -p "%PASS%" scp -P %PORT% %SSH_OPTS% -r "%DIST_DIR%" %USER%@%IP%:%REMOTE_DIR%/ if %errorlevel% neq 0 ( echo [ERROR] Upload failed! Check network or credentials. goto :error_exit ) echo [OK] Upload completed! echo. echo ========================================== echo [SUCCESS] Deploy completed! echo ========================================== goto :end :error_exit echo. echo ========================================== echo [FAILED] Deploy failed! echo ========================================== :end pause