From 5e024f77a2c26115d4ced0c0fe7932845be75f7d Mon Sep 17 00:00:00 2001 From: YeomaiPC Date: Sun, 18 Oct 2026 17:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/stop-dev.ps1 | 22 ++++++++++++++++++++++ start-dev.bat | 42 ++++++++++++++++++++++++++++++++++++++++++ stop-dev.bat | 22 ++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 scripts/stop-dev.ps1 create mode 100644 start-dev.bat create mode 100644 stop-dev.bat diff --git a/scripts/stop-dev.ps1 b/scripts/stop-dev.ps1 new file mode 100644 index 0000000..1a57671 --- /dev/null +++ b/scripts/stop-dev.ps1 @@ -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 diff --git a/start-dev.bat b/start-dev.bat new file mode 100644 index 0000000..e80aedd --- /dev/null +++ b/start-dev.bat @@ -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 diff --git a/stop-dev.bat b/stop-dev.bat new file mode 100644 index 0000000..12a43bb --- /dev/null +++ b/stop-dev.bat @@ -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