-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ps1
More file actions
84 lines (75 loc) · 2.67 KB
/
run.ps1
File metadata and controls
84 lines (75 loc) · 2.67 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# run.ps1
# Starts both the backend and frontend for local development.
#
# What it does:
# 1. Starts the .NET backend (dotnet run) on http://localhost:5115
# 2. Starts the Next.js frontend (npm run dev) on http://localhost:3000
# 3. Stops both when you press Ctrl+C
#
# Usage:
# .\run.ps1
$ErrorActionPreference = "Stop"
$RepoRoot = $PSScriptRoot
$BackendDir = "$RepoRoot\backend\Tasklog.Api"
$FrontendDir = "$RepoRoot\frontend"
# Verify directories exist.
if (-not (Test-Path $BackendDir)) {
Write-Host "ERROR: Backend not found at $BackendDir" -ForegroundColor Red
exit 1
}
if (-not (Test-Path $FrontendDir)) {
Write-Host "ERROR: Frontend not found at $FrontendDir" -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "Starting Tasklog..." -ForegroundColor Cyan
Write-Host " Backend: http://localhost:5115" -ForegroundColor Gray
Write-Host " Frontend: http://localhost:3000" -ForegroundColor Gray
Write-Host " Press Ctrl+C to stop both." -ForegroundColor Gray
Write-Host ""
# Start the backend as a background job.
$backendJob = Start-Job -ScriptBlock {
param($dir)
Set-Location $dir
dotnet run 2>&1
} -ArgumentList $BackendDir
# Start the frontend as a background job.
$frontendJob = Start-Job -ScriptBlock {
param($dir)
Set-Location $dir
npm run dev 2>&1
} -ArgumentList $FrontendDir
# Stream output from both jobs until the user presses Ctrl+C.
try {
while ($true) {
# Print any new output from both jobs.
Receive-Job $backendJob -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "[backend] $_" -ForegroundColor Green
}
Receive-Job $frontendJob -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "[frontend] $_" -ForegroundColor Blue
}
# Check if either job has stopped unexpectedly.
if ($backendJob.State -eq "Failed") {
Write-Host "Backend stopped unexpectedly." -ForegroundColor Red
Receive-Job $backendJob -ErrorAction SilentlyContinue
break
}
if ($frontendJob.State -eq "Failed") {
Write-Host "Frontend stopped unexpectedly." -ForegroundColor Red
Receive-Job $frontendJob -ErrorAction SilentlyContinue
break
}
Start-Sleep -Milliseconds 500
}
}
finally {
# Clean up both jobs on exit.
Write-Host ""
Write-Host "Stopping..." -ForegroundColor Yellow
Stop-Job $backendJob -ErrorAction SilentlyContinue
Stop-Job $frontendJob -ErrorAction SilentlyContinue
Remove-Job $backendJob -Force -ErrorAction SilentlyContinue
Remove-Job $frontendJob -Force -ErrorAction SilentlyContinue
Write-Host "Stopped." -ForegroundColor Yellow
}