|
1 | 1 | @ECHO OFF |
2 | 2 | SETLOCAL EnableDelayedExpansion |
3 | 3 |
|
4 | | -SET "SCRIPT_DIR=%~dp0" |
| 4 | +SET "NODE_VERSION=22.14.0" |
| 5 | +SET "GOOSE_NODE_DIR=%LOCALAPPDATA%\Goose\node" |
5 | 6 |
|
6 | | -REM Try to find Node.js in standard locations first |
7 | | -if exist "C:\Program Files\nodejs\npx.cmd" ( |
8 | | - "C:\Program Files\nodejs\npx.cmd" %* |
9 | | - exit /b %errorlevel% |
| 7 | +REM === Check for previously downloaded portable Node.js (matching version) === |
| 8 | +if exist "%GOOSE_NODE_DIR%\node-v%NODE_VERSION%.installed" ( |
| 9 | + SET "PATH=%GOOSE_NODE_DIR%;!PATH!" |
| 10 | + "%GOOSE_NODE_DIR%\npx.cmd" %* |
| 11 | + exit /b !errorlevel! |
10 | 12 | ) |
11 | 13 |
|
12 | | -if exist "C:\Program Files (x86)\nodejs\npx.cmd" ( |
13 | | - "C:\Program Files (x86)\nodejs\npx.cmd" %* |
14 | | - exit /b %errorlevel% |
15 | | -) |
| 14 | +REM === Download portable Node.js === |
| 15 | +echo [Goose] Node.js not found. Downloading portable Node.js v%NODE_VERSION%... 1>&2 |
| 16 | + |
| 17 | +SET "NODE_ZIP=%TEMP%\goose-node-%NODE_VERSION%.zip" |
| 18 | +SET "NODE_EXTRACT=%TEMP%\goose-node-extract" |
16 | 19 |
|
17 | | -REM If Node.js not found, run installer |
18 | | -call "%SCRIPT_DIR%install-node.cmd" "https://nodejs.org/dist/v23.10.0/node-v23.10.0-x64.msi" |
| 20 | +powershell -NoProfile -Command "$ProgressPreference='SilentlyContinue'; try { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-win-x64.zip' -OutFile '%NODE_ZIP%' -UseBasicParsing; Expand-Archive -Path '%NODE_ZIP%' -DestinationPath '%NODE_EXTRACT%' -Force; exit 0 } catch { Write-Error $_.Exception.Message; exit 1 }" |
19 | 21 | if errorlevel 1 ( |
20 | | - echo Failed to install Node.js |
| 22 | + echo [Goose] ERROR: Failed to download Node.js. Please install manually from https://nodejs.org/ 1>&2 |
| 23 | + del "%NODE_ZIP%" >nul 2>&1 |
21 | 24 | exit /b 1 |
22 | 25 | ) |
23 | 26 |
|
24 | | -REM Try using the newly installed Node.js |
25 | | -if exist "C:\Program Files\nodejs\npx.cmd" ( |
26 | | - "C:\Program Files\nodejs\npx.cmd" %* |
27 | | - exit /b %errorlevel% |
| 27 | +REM Clean previous version and install to Goose directory |
| 28 | +rmdir /s /q "%GOOSE_NODE_DIR%" >nul 2>&1 |
| 29 | +mkdir "%GOOSE_NODE_DIR%" >nul 2>&1 |
| 30 | +xcopy /s /e /q /y "%NODE_EXTRACT%\node-v%NODE_VERSION%-win-x64\*" "%GOOSE_NODE_DIR%\" >nul 2>&1 |
| 31 | + |
| 32 | +REM Clean up |
| 33 | +del "%NODE_ZIP%" >nul 2>&1 |
| 34 | +rmdir /s /q "%NODE_EXTRACT%" >nul 2>&1 |
| 35 | + |
| 36 | +if exist "%GOOSE_NODE_DIR%\npx.cmd" ( |
| 37 | + echo.>"%GOOSE_NODE_DIR%\node-v%NODE_VERSION%.installed" |
| 38 | + SET "PATH=%GOOSE_NODE_DIR%;!PATH!" |
| 39 | + echo [Goose] Node.js v%NODE_VERSION% ready. 1>&2 |
| 40 | + "%GOOSE_NODE_DIR%\npx.cmd" %* |
| 41 | + exit /b !errorlevel! |
28 | 42 | ) |
29 | 43 |
|
30 | | -echo Failed to find npx after Node.js installation |
| 44 | +echo [Goose] ERROR: Installation failed. Please install Node.js manually from https://nodejs.org/ 1>&2 |
31 | 45 | exit /b 1 |
0 commit comments