-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
111 lines (93 loc) · 3.64 KB
/
start.ps1
File metadata and controls
111 lines (93 loc) · 3.64 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Start DevOps Chatbot services for Windows PowerShell
# Resolve the repository root directory from the current script path
$scriptPath = $MyInvocation.MyCommand.Path
$rootDir = Split-Path -Parent $scriptPath
$backendDir = Join-Path $rootDir 'backend'
$frontendDir = Join-Path $rootDir 'frontend'
$venvDir = Join-Path $backendDir '.venv'
$venvScripts = Join-Path $venvDir 'Scripts'
function Write-Info {
param([string]$Message)
Write-Host "`n$Message" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host $Message -ForegroundColor Green
}
function Get-PythonExecutable {
$candidates = @('python.exe', 'python3.exe')
foreach ($candidate in $candidates) {
$command = Get-Command $candidate -ErrorAction SilentlyContinue
if ($command) { return $command.Source }
}
throw 'Python 3 is required to set up the backend environment.'
}
function Setup-Backend {
Write-Info 'Checking backend environment...'
$pythonExe = Get-PythonExecutable
if (-not (Test-Path $venvDir)) {
Write-Info 'Creating Python virtual environment for backend...'
& $pythonExe -m venv $venvDir
}
$venvPython = Join-Path $venvScripts 'python.exe'
try {
& $venvPython -m pip --version *> $null
} catch {
Write-Info 'pip not found in virtual environment; bootstrapping pip...'
try {
& $venvPython -m ensurepip --upgrade *> $null
} catch {
throw 'Failed to bootstrap pip. Install a Python distribution with ensurepip or install pip manually.'
}
}
Write-Info 'Bootstrapping uv in the backend virtual environment...'
& $venvPython -m pip install --upgrade pip
& $venvPython -m pip install uv
Write-Info 'Syncing backend dependencies with uv...'
Push-Location $backendDir
& $venvPython -m uv sync
Pop-Location
}
function Setup-Frontend {
Write-Info 'Checking frontend environment...'
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
throw 'npm is required to install frontend dependencies.'
}
$nodeModules = Join-Path $frontendDir 'node_modules'
if (-not (Test-Path $nodeModules)) {
Write-Info 'Installing frontend dependencies...'
Push-Location $frontendDir
npm install
Pop-Location
}
}
function Stop-Services {
Write-Host '`nStopping services...' -ForegroundColor Cyan
if ($backendProcess -and -not $backendProcess.HasExited) {
Stop-Process -Id $backendProcess.Id -ErrorAction SilentlyContinue
}
if ($frontendProcess -and -not $frontendProcess.HasExited) {
Stop-Process -Id $frontendProcess.Id -ErrorAction SilentlyContinue
}
Write-Success '✅ All services stopped.'
}
try {
Write-Info '🚀 Starting DevOps Chatbot Stack...'
Setup-Backend
Setup-Frontend
Write-Info 'Starting Backend...'
$venvPython = Join-Path $venvScripts 'python.exe'
$backendProcess = Start-Process -FilePath $venvPython -ArgumentList 'main.py' -WorkingDirectory $backendDir -NoNewWindow -PassThru
Write-Host "Backend running on PID: $($backendProcess.Id)"
Write-Info 'Starting Frontend...'
$frontendProcess = Start-Process -FilePath npm -ArgumentList 'run', 'dev' -WorkingDirectory $frontendDir -NoNewWindow -PassThru
Write-Host "Frontend running on PID: $($frontendProcess.Id)"
Write-Success '✨ Both services are running!'
Write-Host 'Backend: http://localhost:8000'
Write-Host 'Frontend: http://localhost:5173 (usually)'
Write-Host 'Press Ctrl+C to stop both services.' -ForegroundColor Cyan
Wait-Process -Id $backendProcess.Id, $frontendProcess.Id
}
finally {
Stop-Services
}