-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bat
More file actions
47 lines (40 loc) · 1.05 KB
/
test.bat
File metadata and controls
47 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@echo off
setlocal
cd /d "%~dp0"
if /I "%~1"=="--help" goto help
if /I "%~1"=="-h" goto help
where npm.cmd >nul 2>nul
if errorlevel 1 (
echo npm.cmd was not found. Please install Node.js or add it to PATH.
exit /b 1
)
set "host=127.0.0.1"
set "port=%~1"
if not defined port set "port=4321"
echo.
echo [1/2] Building site...
set ASTRO_TELEMETRY_DISABLED=1
call npm.cmd run build
if errorlevel 1 (
echo.
echo Build failed. Preview was not started.
exit /b 1
)
echo.
echo [2/2] Starting local preview...
set "preview_url=http://%host%:%port%/CatBox/"
echo Open this URL:
echo %preview_url%
echo.
echo Press Ctrl+C to stop the preview server.
powershell -NoProfile -WindowStyle Hidden -Command "Start-Sleep -Seconds 2; Start-Process '%preview_url%'" >nul 2>nul
call npm.cmd run preview -- --host %host% --port %port%
exit /b %errorlevel%
:help
echo Usage:
echo test.bat
echo test.bat 4322
echo.
echo The script builds the static site and starts Astro preview locally.
echo It also opens http://127.0.0.1:4321/CatBox/ in your default browser.
exit /b 0