启动脚本
This commit is contained in:
1 parent
202a81d0a9
commit
5e024f77a2
3 files changed
+86
No files matched your search
@@ -0,0 +1,22 @@
|
||||
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
$listener = Get-NetTCPConnection -LocalPort 3000 -State Listen -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1
|
||||
|
||||
if (-not $listener) {
|
||||
Write-Host 'PicHost development server is not running.'
|
||||
exit 2
|
||||
}
|
||||
|
||||
$process = Get-CimInstance Win32_Process -Filter ('ProcessId=' + $listener.OwningProcess)
|
||||
if (-not $process -or $process.CommandLine -notlike ('*' + $root + '*')) {
|
||||
Write-Host 'Port 3000 belongs to another program. Stop cancelled.'
|
||||
exit 3
|
||||
}
|
||||
|
||||
taskkill /PID $listener.OwningProcess /T /F | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host 'PicHost development server stopped.'
|
||||
exit 0
|
||||
@@ -0,0 +1,42 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0"
|
||||
title PicHost Development
|
||||
|
||||
where node >nul 2>&1
|
||||
if errorlevel 1 goto missing_node
|
||||
|
||||
where npm >nul 2>&1
|
||||
if errorlevel 1 goto missing_npm
|
||||
|
||||
if exist "node_modules" goto dependencies_ready
|
||||
echo Installing project dependencies...
|
||||
call npm ci
|
||||
if errorlevel 1 goto failed
|
||||
|
||||
:dependencies_ready
|
||||
if exist ".env" goto env_ready
|
||||
if not exist ".env.example" goto env_ready
|
||||
copy /Y ".env.example" ".env" >nul
|
||||
|
||||
:env_ready
|
||||
echo Starting PicHost development server...
|
||||
start "" powershell -NoProfile -WindowStyle Hidden -Command "Start-Sleep -Seconds 5; Start-Process 'http://127.0.0.1:3000/'"
|
||||
call npm run dev
|
||||
if errorlevel 1 goto failed
|
||||
exit /b 0
|
||||
|
||||
:missing_node
|
||||
echo Node.js 22 or newer was not found.
|
||||
pause
|
||||
exit /b 1
|
||||
|
||||
:missing_npm
|
||||
echo npm was not found. Check the Node.js installation.
|
||||
pause
|
||||
exit /b 1
|
||||
|
||||
:failed
|
||||
echo PicHost failed to start. Check the error output above.
|
||||
pause
|
||||
exit /b 1
|
||||
@@ -0,0 +1,22 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0"
|
||||
title PicHost Development - Stop
|
||||
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\stop-dev.ps1"
|
||||
if errorlevel 3 goto foreign_process
|
||||
if errorlevel 2 goto not_running
|
||||
if errorlevel 1 goto failed
|
||||
exit /b 0
|
||||
|
||||
:not_running
|
||||
exit /b 0
|
||||
|
||||
:foreign_process
|
||||
pause
|
||||
exit /b 1
|
||||
|
||||
:failed
|
||||
echo Failed to stop the PicHost development server.
|
||||
pause
|
||||
exit /b 1
|
||||
Reference in new issue
Block a user