chore: add root startup scripts
This commit is contained in:
27
README.md
27
README.md
@@ -14,6 +14,33 @@ Monorepo for the Termi blog system.
|
|||||||
|
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
|
### Monorepo scripts
|
||||||
|
|
||||||
|
From the repository root:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\dev.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
Only frontend:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\dev.ps1 -FrontendOnly
|
||||||
|
```
|
||||||
|
|
||||||
|
Only backend:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\dev.ps1 -BackendOnly
|
||||||
|
```
|
||||||
|
|
||||||
|
Direct scripts:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\start-frontend.ps1
|
||||||
|
.\start-backend.ps1
|
||||||
|
```
|
||||||
|
|
||||||
### Frontend
|
### Frontend
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
|
|||||||
42
dev.ps1
Normal file
42
dev.ps1
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
param(
|
||||||
|
[switch]$FrontendOnly,
|
||||||
|
[switch]$BackendOnly,
|
||||||
|
[string]$DatabaseUrl = "postgres://postgres:postgres%402025%21@10.0.0.2:5432/termi-api_development"
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$frontendScript = Join-Path $repoRoot "start-frontend.ps1"
|
||||||
|
$backendScript = Join-Path $repoRoot "start-backend.ps1"
|
||||||
|
|
||||||
|
if ($FrontendOnly -and $BackendOnly) {
|
||||||
|
throw "Use either -FrontendOnly or -BackendOnly, not both."
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($FrontendOnly) {
|
||||||
|
& $frontendScript
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($BackendOnly) {
|
||||||
|
& $backendScript -DatabaseUrl $DatabaseUrl
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "[monorepo] Starting frontend and backend in separate PowerShell windows..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
Start-Process powershell -ArgumentList @(
|
||||||
|
"-NoExit",
|
||||||
|
"-ExecutionPolicy", "Bypass",
|
||||||
|
"-File", $frontendScript
|
||||||
|
)
|
||||||
|
|
||||||
|
Start-Process powershell -ArgumentList @(
|
||||||
|
"-NoExit",
|
||||||
|
"-ExecutionPolicy", "Bypass",
|
||||||
|
"-File", $backendScript,
|
||||||
|
"-DatabaseUrl", $DatabaseUrl
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "[monorepo] Frontend window and backend window started." -ForegroundColor Green
|
||||||
27
start-backend.ps1
Normal file
27
start-backend.ps1
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
param(
|
||||||
|
[string]$DatabaseUrl = "postgres://postgres:postgres%402025%21@10.0.0.2:5432/termi-api_development"
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$backendDir = Join-Path $repoRoot "backend"
|
||||||
|
|
||||||
|
if (-not (Test-Path $backendDir)) {
|
||||||
|
throw "Backend directory not found: $backendDir"
|
||||||
|
}
|
||||||
|
|
||||||
|
Push-Location $backendDir
|
||||||
|
|
||||||
|
try {
|
||||||
|
$env:DATABASE_URL = $DatabaseUrl
|
||||||
|
Write-Host "[backend] DATABASE_URL set to $DatabaseUrl" -ForegroundColor Cyan
|
||||||
|
Write-Host "[backend] Starting Loco.rs server..." -ForegroundColor Green
|
||||||
|
cargo loco start 2>&1
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "cargo loco start failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
33
start-frontend.ps1
Normal file
33
start-frontend.ps1
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
param(
|
||||||
|
[switch]$Install
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$frontendDir = Join-Path $repoRoot "frontend"
|
||||||
|
|
||||||
|
if (-not (Test-Path $frontendDir)) {
|
||||||
|
throw "Frontend directory not found: $frontendDir"
|
||||||
|
}
|
||||||
|
|
||||||
|
Push-Location $frontendDir
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($Install -or -not (Test-Path (Join-Path $frontendDir "node_modules"))) {
|
||||||
|
Write-Host "[frontend] Installing dependencies..." -ForegroundColor Cyan
|
||||||
|
npm install
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "npm install failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "[frontend] Starting Astro dev server..." -ForegroundColor Green
|
||||||
|
npm run dev
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "npm run dev failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user