ETest-Vue-FastAPI/install-node16.bat

122 lines
2.7 KiB
Batchfile
Raw Normal View History

2026-03-30 10:38:36 +08:00
@echo off
chcp 65001 >nul
title Install Node.js 16 for ETest
color 0A
echo ========================================
echo Install Node.js 16 for ETest Project
echo ========================================
echo.
echo [*] This script will download and install Node.js 16.20.2
echo [*] Current version: 22.x (TOO NEW for Vue 2)
echo [*] Required version: 14.x or 16.x
echo.
set "NODE_VERSION=16.20.2"
set "NODE_URL=https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-win-x64.zip"
set "INSTALL_DIR=C:\nodejs16"
set "ZIP_FILE=%TEMP%\node-v%NODE_VERSION%-win-x64.zip"
echo [*] Downloading Node.js %NODE_VERSION%...
echo [*] URL: %NODE_URL%
echo.
:: Download using PowerShell
powershell -Command "Invoke-WebRequest -Uri '%NODE_URL%' -OutFile '%ZIP_FILE%'"
if not exist "%ZIP_FILE%" (
echo [!] Download failed
echo [*] Please download manually from:
echo %NODE_URL%
pause
exit /b 1
)
echo [OK] Download complete
echo.
:: Create install directory
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
:: Extract using PowerShell
echo [*] Extracting to %INSTALL_DIR%...
powershell -Command "Expand-Archive -Path '%ZIP_FILE%' -DestinationPath '%INSTALL_DIR%' -Force"
:: Move files from subdirectory
for /d %%D in ("%INSTALL_DIR%\node-v*") do (
xcopy "%%D\*" "%INSTALL_DIR%\" /E /I /Y
rmdir /s /q "%%D"
)
echo [OK] Extraction complete
echo.
:: Verify installation
echo [*] Verifying installation...
"%INSTALL_DIR%\node.exe" -v
if %errorlevel% neq 0 (
echo [!] Installation failed
pause
exit /b 1
)
echo [OK] Node.js installed successfully
echo.
:: Create npm.cmd
echo [*] Creating npm command...
echo @echo off > "%INSTALL_DIR%\npm.cmd"
echo "%~dp0\node.exe" "%~dp0\node_modules\npm\bin\npm-cli.js" %%* >> "%INSTALL_DIR%\npm.cmd"
echo.
echo ========================================
echo Installation Complete!
echo ========================================
echo.
echo Node.js 16 location: %INSTALL_DIR%
echo.
echo USAGE:
echo %INSTALL_DIR%\node.exe -v
echo %INSTALL_DIR%\npm.cmd install
echo %INSTALL_DIR%\npm.cmd run dev
echo.
echo Or add to PATH:
echo set PATH=%INSTALL_DIR%;%%PATH%%
echo.
:: Clean up
del "%ZIP_FILE%" 2>nul
:: Test npm
echo [*] Testing npm...
"%INSTALL_DIR%\npm.cmd" -v
echo.
echo [*] Now fixing ETest project...
echo.
cd /d C:\PPRO\ETest-Vue-FastAPI\ruoyi-fastapi-frontend
echo [*] Removing old node_modules...
rmdir /s /q node_modules 2>nul
del package-lock.json 2>nul
echo [*] Installing dependencies with Node.js 16...
"%INSTALL_DIR%\npm.cmd" install
echo.
if %errorlevel% equ 0 (
echo [OK] Dependencies installed!
echo [*] Starting dev server...
echo.
"%INSTALL_DIR%\npm.cmd" run dev
) else (
echo [!] Install failed
echo [*] Try: %INSTALL_DIR%\npm.cmd install --legacy-peer-deps
)
echo.
pause