| | |
| | | @echo off
|
| | | setlocal enabledelayedexpansion
|
| | |
|
| | | :: ================= Config =================
|
| | | set "COMPANY=TEST"
|
| | | set "USER=root"
|
| | | set "PASS=Xdrjkj@10086#"
|
| | | set "IP=36.213.180.217"
|
| | | set "PORT=65022"
|
| | | set "ZIP_FILE=dist.zip"
|
| | | set "REMOTE_DIR=/data/project/mom/vue/test/dist"
|
| | | set "SSH_OPTS=-o StrictHostKeyChecking=no -o ConnectTimeout=10"
|
| | | :: ===========================================
|
| | |
|
| | | echo ==========================================
|
| | | echo Vue Dist Auto Deploy Script
|
| | | echo ==========================================
|
| | | echo.
|
| | |
|
| | | :: Check if sshpass is available
|
| | | set "SSHPASS_DIR=%~dp0bin"
|
| | | if exist "!SSHPASS_DIR!\sshpass.exe" (
|
| | | set "PATH=!SSHPASS_DIR!;%PATH%"
|
| | | )
|
| | |
|
| | | where sshpass >nul 2>&1
|
| | | if %errorlevel% equ 0 goto :check_node
|
| | |
|
| | | 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_node
|
| | | )
|
| | | )
|
| | |
|
| | | if not exist "!SSHPASS_DIR!" mkdir "!SSHPASS_DIR!"
|
| | |
|
| | | if exist "!SSHPASS_DIR!\sshpass.exe" (
|
| | | set "PATH=!SSHPASS_DIR!;%PATH%"
|
| | | echo [OK] sshpass found at: !SSHPASS_DIR!
|
| | | goto :check_node
|
| | | )
|
| | |
|
| | | 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_node
|
| | | :: Check if pnpm is available
|
| | | where pnpm >nul 2>&1
|
| | | if %errorlevel% neq 0 (
|
| | | echo [ERROR] pnpm not found! Please install pnpm first.
|
| | | echo [HINT] npm install -g pnpm
|
| | | goto :error_exit
|
| | | )
|
| | |
|
| | | :: Check if node_modules exists
|
| | | if not exist "node_modules" (
|
| | | echo [INFO] node_modules not found, running pnpm install...
|
| | | echo.
|
| | | call pnpm install
|
| | | if !errorlevel! neq 0 (
|
| | | echo [ERROR] pnpm install failed!
|
| | | goto :error_exit
|
| | | )
|
| | | echo.
|
| | | )
|
| | |
|
| | | :: Check if dist.zip exists and ask user
|
| | | if exist "%ZIP_FILE%" (
|
| | | echo [WARN] %ZIP_FILE% already exists.
|
| | | set /p "REBUILD=Do you want to rebuild? (Y/N, default Y): "
|
| | | if /i "!REBUILD!"=="N" (
|
| | | echo [INFO] Skip build, using existing %ZIP_FILE%
|
| | | goto :upload
|
| | | )
|
| | | )
|
| | |
|
| | | :: Build the project
|
| | | echo [STEP 1/3] Building project for %COMPANY%...
|
| | | echo [INFO] Running: pnpm run build
|
| | | echo.
|
| | | :: Pass VITE_COMPANY so vite.config.ts picks the right company (vite reads VITE_ prefixed env vars)
|
| | | set "VITE_COMPANY=!COMPANY!" && call pnpm run build
|
| | | if !errorlevel! neq 0 (
|
| | | echo [ERROR] Build failed! Check your project configuration.
|
| | | goto :error_exit
|
| | | )
|
| | | echo [OK] Build completed!
|
| | | echo.
|
| | |
|
| | | :upload
|
| | | if not exist "%ZIP_FILE%" (
|
| | | echo [ERROR] %ZIP_FILE% not found.
|
| | | echo [HINT] Build may have failed or VITE_ARCHIVER is not enabled in .env.production.
|
| | | goto :error_exit
|
| | | )
|
| | |
|
| | | :: Calculate zip size
|
| | | for %%F in ("%ZIP_FILE%") do set "ZIP_BYTES=%%~zF"
|
| | | set /a "ZIP_SIZE_MB=ZIP_BYTES/1024/1024"
|
| | |
|
| | | echo [INFO] Zip file: %ZIP_FILE%
|
| | | echo [INFO] Size: %ZIP_SIZE_MB% MB
|
| | | echo [INFO] Target: %USER%@%IP%:%PORT%
|
| | | echo [INFO] Remote dir: %REMOTE_DIR%
|
| | | echo.
|
| | |
|
| | | :: Optional: Ask for confirmation before upload
|
| | | set /p "CONFIRM=Proceed with upload? (Y/N, default Y): "
|
| | | if /i "!CONFIRM!"=="N" (
|
| | | echo [INFO] Upload cancelled by user.
|
| | | goto :end
|
| | | )
|
| | |
|
| | | :: Upload dist.zip
|
| | | echo [STEP 2/3] Uploading %ZIP_FILE%...
|
| | | sshpass -p "%PASS%" scp -P %PORT% %SSH_OPTS% "%ZIP_FILE%" %USER%@%IP%:%REMOTE_DIR%/
|
| | | if %errorlevel% neq 0 (
|
| | | echo [ERROR] Upload failed! Check network or credentials.
|
| | | goto :error_exit
|
| | | )
|
| | | echo [OK] Upload completed!
|
| | | echo.
|
| | |
|
| | | :: Remote unzip: cd to %REMOTE_DIR% then unzip -o ./dist.zip
|
| | | echo [STEP 3/3] Running remote: cd %REMOTE_DIR% && unzip -o ./%ZIP_FILE%
|
| | | sshpass -p "%PASS%" ssh -P %PORT% %SSH_OPTS% %USER%@%IP% "cd %REMOTE_DIR% && unzip -o ./%ZIP_FILE% && rm -f ./%ZIP_FILE%"
|
| | | if %errorlevel% neq 0 (
|
| | | echo [ERROR] Remote unzip failed! Check if 'unzip' is installed on server.
|
| | | goto :error_exit
|
| | | )
|
| | | echo [OK] Unzip completed! %ZIP_FILE% removed from remote.
|
| | | echo.
|
| | |
|
| | | echo ==========================================
|
| | | echo [SUCCESS] Deploy completed!
|
| | | echo ==========================================
|
| | | echo.
|
| | | echo Summary:
|
| | | echo - Build: Completed
|
| | | echo - Upload: %ZIP_FILE% (%ZIP_SIZE_MB% MB)
|
| | | echo - Target: %USER%@%IP%:%PORT%%REMOTE_DIR%
|
| | | echo.
|
| | |
|
| | | goto :end
|
| | |
|
| | | :error_exit
|
| | | echo.
|
| | | echo ==========================================
|
| | | echo [FAILED] Deploy failed!
|
| | | echo ==========================================
|
| | |
|
| | | :end
|
| | | pause
|
| | | @echo off |
| | | setlocal enabledelayedexpansion |
| | | |
| | | :: ================= Config ================= |
| | | set "COMPANY=TEST" |
| | | set "USER=root" |
| | | set "PASS=Xdrjkj@10086#" |
| | | set "IP=36.213.90.123" |
| | | set "PORT=65022" |
| | | set "ZIP_FILE=dist.zip" |
| | | set "REMOTE_DIR=/data/project/mom/vue/test/dist" |
| | | set "SSH_OPTS=-o StrictHostKeyChecking=no -o ConnectTimeout=10" |
| | | :: =========================================== |
| | | |
| | | echo ========================================== |
| | | echo Vue Dist Auto Deploy Script |
| | | echo ========================================== |
| | | echo. |
| | | |
| | | :: Check if sshpass is available |
| | | set "SSHPASS_DIR=%~dp0bin" |
| | | if exist "!SSHPASS_DIR!\sshpass.exe" ( |
| | | set "PATH=!SSHPASS_DIR!;%PATH%" |
| | | ) |
| | | |
| | | where sshpass >nul 2>&1 |
| | | if %errorlevel% equ 0 goto :check_node |
| | | |
| | | 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_node |
| | | ) |
| | | ) |
| | | |
| | | if not exist "!SSHPASS_DIR!" mkdir "!SSHPASS_DIR!" |
| | | |
| | | if exist "!SSHPASS_DIR!\sshpass.exe" ( |
| | | set "PATH=!SSHPASS_DIR!;%PATH%" |
| | | echo [OK] sshpass found at: !SSHPASS_DIR! |
| | | goto :check_node |
| | | ) |
| | | |
| | | 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_node |
| | | :: Check if pnpm is available |
| | | where pnpm >nul 2>&1 |
| | | if %errorlevel% neq 0 ( |
| | | echo [ERROR] pnpm not found! Please install pnpm first. |
| | | echo [HINT] npm install -g pnpm |
| | | goto :error_exit |
| | | ) |
| | | |
| | | :: Check if node_modules exists |
| | | if not exist "node_modules" ( |
| | | echo [INFO] node_modules not found, running pnpm install... |
| | | echo. |
| | | call pnpm install |
| | | if !errorlevel! neq 0 ( |
| | | echo [ERROR] pnpm install failed! |
| | | goto :error_exit |
| | | ) |
| | | echo. |
| | | ) |
| | | |
| | | :: Check if dist.zip exists and ask user |
| | | if exist "%ZIP_FILE%" ( |
| | | echo [WARN] %ZIP_FILE% already exists. |
| | | set /p "REBUILD=Do you want to rebuild? (Y/N, default Y): " |
| | | if /i "!REBUILD!"=="N" ( |
| | | echo [INFO] Skip build, using existing %ZIP_FILE% |
| | | goto :upload |
| | | ) |
| | | ) |
| | | |
| | | :: Build the project |
| | | echo [STEP 1/3] Building project for %COMPANY%... |
| | | echo [INFO] Running: pnpm run build |
| | | echo. |
| | | :: Pass VITE_COMPANY so vite.config.ts picks the right company (vite reads VITE_ prefixed env vars) |
| | | set "VITE_COMPANY=!COMPANY!" && call pnpm run build |
| | | if !errorlevel! neq 0 ( |
| | | echo [ERROR] Build failed! Check your project configuration. |
| | | goto :error_exit |
| | | ) |
| | | echo [OK] Build completed! |
| | | echo. |
| | | |
| | | :upload |
| | | if not exist "%ZIP_FILE%" ( |
| | | echo [ERROR] %ZIP_FILE% not found. |
| | | echo [HINT] Build may have failed or VITE_ARCHIVER is not enabled in .env.production. |
| | | goto :error_exit |
| | | ) |
| | | |
| | | :: Calculate zip size |
| | | for %%F in ("%ZIP_FILE%") do set "ZIP_BYTES=%%~zF" |
| | | set /a "ZIP_SIZE_MB=ZIP_BYTES/1024/1024" |
| | | |
| | | echo [INFO] Zip file: %ZIP_FILE% |
| | | echo [INFO] Size: %ZIP_SIZE_MB% MB |
| | | echo [INFO] Target: %USER%@%IP%:%PORT% |
| | | echo [INFO] Remote dir: %REMOTE_DIR% |
| | | echo. |
| | | |
| | | :: Optional: Ask for confirmation before upload |
| | | set /p "CONFIRM=Proceed with upload? (Y/N, default Y): " |
| | | if /i "!CONFIRM!"=="N" ( |
| | | echo [INFO] Upload cancelled by user. |
| | | goto :end |
| | | ) |
| | | |
| | | :: Upload dist.zip |
| | | echo [STEP 2/3] Uploading %ZIP_FILE%... |
| | | sshpass -p "%PASS%" scp -P %PORT% %SSH_OPTS% "%ZIP_FILE%" %USER%@%IP%:%REMOTE_DIR%/ |
| | | if %errorlevel% neq 0 ( |
| | | echo [ERROR] Upload failed! Check network or credentials. |
| | | goto :error_exit |
| | | ) |
| | | echo [OK] Upload completed! |
| | | echo. |
| | | |
| | | :: Remote unzip: cd to %REMOTE_DIR% then unzip -o ./dist.zip |
| | | echo [STEP 3/3] Running remote: cd %REMOTE_DIR% && unzip -o ./%ZIP_FILE% |
| | | sshpass -p "%PASS%" ssh -P %PORT% %SSH_OPTS% %USER%@%IP% "cd %REMOTE_DIR% && unzip -o ./%ZIP_FILE% && rm -f ./%ZIP_FILE%" |
| | | if %errorlevel% neq 0 ( |
| | | echo [ERROR] Remote unzip failed! Check if 'unzip' is installed on server. |
| | | goto :error_exit |
| | | ) |
| | | echo [OK] Unzip completed! %ZIP_FILE% removed from remote. |
| | | echo. |
| | | |
| | | echo ========================================== |
| | | echo [SUCCESS] Deploy completed! |
| | | echo ========================================== |
| | | echo. |
| | | echo Summary: |
| | | echo - Build: Completed |
| | | echo - Upload: %ZIP_FILE% (%ZIP_SIZE_MB% MB) |
| | | echo - Target: %USER%@%IP%:%PORT%%REMOTE_DIR% |
| | | echo. |
| | | |
| | | goto :end |
| | | |
| | | :error_exit |
| | | echo. |
| | | echo ========================================== |
| | | echo [FAILED] Deploy failed! |
| | | echo ========================================== |
| | | |
| | | :end |
| | | pause |