Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions src/Cellm.Installers/Scripts/install_node.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
@echo off
setlocal EnableDelayedExpansion

REM --- Configuration ---
set NODEJS_VERSION=22.16.0
set NODEJS_ARCH=x64

REM === Validate and Get Parent Extraction Directory from Command Line Argument ===
if "%~1"=="" (
echo ERROR: Parent extraction directory not provided.
echo Usage: %~nx0 ^<ParentExtractionDirectory^>
echo Example: %~nx0 "C:\MyNodeJSInstallations"
exit /b 1
)
set "NODEJS_EXTRACT_PARENT_DIR=%~1"

REM Check if the provided parent directory exists
if not exist "!NODEJS_EXTRACT_PARENT_DIR!\" (
echo ERROR: The specified parent extraction directory does not exist:
echo "!NODEJS_EXTRACT_PARENT_DIR!"
echo Please create this directory first or provide an existing one.
exit /b 1
)
echo Parent extraction directory: "!NODEJS_EXTRACT_PARENT_DIR!"
echo.

set NODEJS_DIR_NAME=node-v%NODEJS_VERSION%-win-%NODEJS_ARCH%
set NODEJS_FILENAME=%NODEJS_DIR_NAME%.zip
set NODEJS_URL=https://nodejs.org/dist/v%NODEJS_VERSION%/%NODEJS_FILENAME%

REM Using %TEMP% for downloads is generally safer and cleaner
set DOWNLOAD_DIR=%TEMP%\nodejs_download_%RANDOM%_%RANDOM%
set DOWNLOAD_PATH=!DOWNLOAD_DIR!\%NODEJS_FILENAME%

REM This will be the full path to the extracted folder
set FINAL_NODE_EXTRACTED_PATH=!NODEJS_EXTRACT_PARENT_DIR!\%NODEJS_DIR_NAME%

echo ========================================================================
echo Node.js Standalone Download ^& Extract
echo ========================================================================
echo Version: %NODEJS_VERSION%
echo Architecture: %NODEJS_ARCH%
echo Download URL: %NODEJS_URL%
echo Download to: "!DOWNLOAD_PATH!"
echo Node.js will be extracted to: "!FINAL_NODE_EXTRACTED_PATH!"
echo ========================================================================
echo.

REM Create download directory (temporary)
if not exist "!DOWNLOAD_DIR!" mkdir "!DOWNLOAD_DIR!"
if !errorlevel! neq 0 (
echo ERROR: Could not create temporary download directory: "!DOWNLOAD_DIR!". Check permissions.
exit /b 1
)

REM PowerShell command to download and extract with improved error handling and retry logic
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$ErrorActionPreference = 'Stop'; ^
$downloadUrl = '%NODEJS_URL%'; ^
$downloadPath = '%DOWNLOAD_PATH%'; ^
$extractDestinationParent = '%NODEJS_EXTRACT_PARENT_DIR%'; ^
$finalExtractedPath = '%FINAL_NODE_EXTRACTED_PATH%'; ^
$maxRetries = 3; ^
$retryCount = 0; ^
$downloaded = $false; ^
^
Write-Host \"Download starting...\" -ForegroundColor Cyan; ^
^
while (-not $downloaded -and $retryCount -lt $maxRetries) { ^
try { ^
if ($retryCount -gt 0) { ^
Write-Host \"Retry attempt $retryCount of $maxRetries...\" -ForegroundColor Yellow; ^
Start-Sleep -Seconds ($retryCount * 2); ^
} ^
^
$wc = New-Object Net.WebClient; ^
$wc.Headers.Add('User-Agent', 'Node.js Installer Script'); ^
Write-Host \"Downloading Node.js from $downloadUrl to $downloadPath...\"; ^
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew(); ^
$wc.DownloadFile($downloadUrl, $downloadPath); ^
$stopwatch.Stop(); ^
Write-Host \"Download complete in $($stopwatch.Elapsed.TotalSeconds) seconds.\" -ForegroundColor Green; ^
$downloaded = $true; ^
} ^
catch { ^
$retryCount++; ^
if ($retryCount -ge $maxRetries) { ^
Write-Host \"ERROR: Download failed after $maxRetries attempts: $($_.Exception.Message)\" -ForegroundColor Red; ^
exit 1; ^
} ^
} ^
} ^
^
if (Test-Path $downloadPath) { ^
$fileSize = (Get-Item $downloadPath).Length / 1MB; ^
Write-Host \"Downloaded file size: $([Math]::Round($fileSize, 2)) MB\" -ForegroundColor Cyan; ^
^
try { ^
Write-Host \"Extracting $downloadPath to parent directory $extractDestinationParent...\" -ForegroundColor Cyan; ^
if (Test-Path $finalExtractedPath) { ^
Write-Host \"Warning: Destination directory already exists. Files will be overwritten.\" -ForegroundColor Yellow; ^
} ^
Expand-Archive -Path $downloadPath -DestinationPath $extractDestinationParent -Force; ^
Write-Host \"Extraction complete.\" -ForegroundColor Green; ^
^
if (Test-Path \"$finalExtractedPath\\node.exe\") { ^
$nodeVersion = & \"$finalExtractedPath\\node.exe\" -v; ^
Write-Host \"Verified Node.js version: $nodeVersion\" -ForegroundColor Green; ^
} else { ^
Write-Host \"Warning: node.exe not found in extracted directory.\" -ForegroundColor Yellow; ^
} ^
} ^
catch { ^
Write-Host \"ERROR: Extraction failed: $($_.Exception.Message)\" -ForegroundColor Red; ^
exit 1; ^
} ^
} else { ^
Write-Host \"ERROR: Download appears to have failed. File not found.\" -ForegroundColor Red; ^
exit 1; ^
}"

if !errorlevel! neq 0 (
echo.
echo ERROR: Node.js download/extraction failed. See PowerShell messages above.
goto :cleanup_with_error
)

echo.
echo ========================================================================
echo Node.js download and extraction successful!
echo ========================================================================
echo The Node.js ZIP file '%NODEJS_FILENAME%' has been extracted.
echo A folder named '%NODEJS_DIR_NAME%' has been created inside '!NODEJS_EXTRACT_PARENT_DIR!'.
echo.
echo Node.js binaries are located in:
echo "!FINAL_NODE_EXTRACTED_PATH!"
echo.
echo To run Node.js from this location, you can use:
echo "!FINAL_NODE_EXTRACTED_PATH!\node.exe" -v
echo "!FINAL_NODE_EXTRACTED_PATH!\npm.cmd" -v
echo ========================================================================

REM Clean up the downloaded ZIP file and temporary directory
:cleanup
if exist "!DOWNLOAD_PATH!" (
del "!DOWNLOAD_PATH!" >nul 2>&1
)
if exist "!DOWNLOAD_DIR!" (
rd "!DOWNLOAD_DIR!" /s /q >nul 2>&1
)
exit /b 0

:cleanup_with_error
if exist "!DOWNLOAD_PATH!" (
del "!DOWNLOAD_PATH!" >nul 2>&1
)
if exist "!DOWNLOAD_DIR!" (
rd "!DOWNLOAD_DIR!" /s /q >nul 2>&1
)
exit /b 1
89 changes: 89 additions & 0 deletions src/Cellm.Installers/Scripts/install_playwright.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@echo OFF
setlocal EnableDelayedExpansion

REM --- Configuration ---
set NODEJS_VERSION=22.16.0
set NODEJS_ARCH=x64
set PLAYWRIGHT_DIR_NAME=Playwright

REM === Validate Parent Directory from Command Line Argument ===
if "%~1"=="" (
echo ERROR: Parent directory not provided.
echo Usage: %~nx0 ^<ParentNodeDirectory^>
echo Example: %~nx0 "C:\MyNodeJSInstallations"
exit /b 1
)

set "PARENT_NODE_DIR=%~1"

REM Check if the provided parent directory exists
if not exist "!PARENT_NODE_DIR!\" (
echo ERROR: The specified parent directory does not exist:
echo "!PARENT_NODE_DIR!"
echo This directory should contain your Node.js installation folder.
exit /b 1
)

REM --- Construct Paths ---
set "NODEJS_FOLDER=node-v%NODEJS_VERSION%-win-%NODEJS_ARCH%"
set "NODE_BIN_PATH=%PARENT_NODE_DIR%\%NODEJS_FOLDER%"
set "PLAYWRIGHT_PATH=%PARENT_NODE_DIR%\%PLAYWRIGHT_DIR_NAME%"

REM Check if the Playwright directory exists
if not exist "!PLAYWRIGHT_PATH!\" (
echo ERROR: Playwright directory does not exist:
echo "!PLAYWRIGHT_PATH!"
echo Please run the Playwright setup script first.
exit /b 1
)

REM Check if npx.cmd exists
if not exist "!NODE_BIN_PATH!\npx.cmd" (
echo ERROR: Could not find npx.cmd at:
echo "!NODE_BIN_PATH!\npx.cmd"
echo Ensure Node.js version '%NODEJS_VERSION%-%NODEJS_ARCH%' is installed in "!PARENT_NODE_DIR!".
exit /b 1
)

echo ========================================================================
echo Installing Playwright
echo ========================================================================
echo Node.js Path: "!NODE_BIN_PATH!"
echo Playwright Path: "!PLAYWRIGHT_PATH!"
echo ========================================================================

REM --- Change to Project Directory and Run Commands ---
echo Changing directory to: "!PLAYWRIGHT_PATH!"
pushd "!PLAYWRIGHT_PATH!"
if !errorlevel! neq 0 (
echo ERROR: Could not change directory to "!PLAYWRIGHT_PATH!".
exit /b 1
)

echo.
echo Installing Playwright browsers and system dependencies...
echo This may take several minutes depending on your internet connection.
echo Administrative privileges may be required for system dependencies.
echo.

REM Set PATH temporarily to include the Node.js directory first
set "PATH=!NODE_BIN_PATH!;%PATH%"

REM Run npx playwright install
call "!NODE_BIN_PATH!\npx.cmd" playwright install --with-deps --no-shell
if !errorlevel! neq 0 (
echo ERROR: "npx playwright install --with-deps --no-shell" failed.
echo This may be due to insufficient permissions for installing system dependencies.
echo Try running this script as Administrator if system dependencies are required.
popd
exit /b 1
)

echo.
echo Installation complete!
echo ========================================================================
echo Playwright browsers and system dependencies have been successfully installed.
echo ========================================================================

popd
exit /b 0
Loading