# Script de démarrage automatique pour Family Planner avec Pronote Write-Host "========================================" -ForegroundColor Cyan Write-Host " Demarrage de Family Planner " -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # Définir le chemin racine $rootPath = Split-Path -Parent $MyInvocation.MyCommand.Path $parentPath = Split-Path -Parent $rootPath # Vérifier Node.js Write-Host "[Verification] Verification de Node.js..." -ForegroundColor Yellow try { $nodeVersion = node --version Write-Host " Node.js $nodeVersion detecte" -ForegroundColor Green } catch { Write-Host " ERREUR: Node.js n'est pas installe!" -ForegroundColor Red Write-Host " Veuillez installer Node.js depuis https://nodejs.org" -ForegroundColor Red pause exit 1 } # Fonction pour tuer les processus sur un port function Stop-ProcessOnPort { param([int]$Port) $connections = netstat -ano | findstr ":$Port" if ($connections) { foreach ($line in $connections) { $pid = ($line -split '\s+')[-1] if ($pid -match '^\d+$') { try { Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue Write-Host " Processus $pid arrete sur le port $Port" -ForegroundColor Yellow } catch { # Ignorer les erreurs } } } } } # Nettoyer les ports Write-Host "[Nettoyage] Arret des anciens processus..." -ForegroundColor Yellow Stop-ProcessOnPort 3000 Stop-ProcessOnPort 3001 Stop-ProcessOnPort 5173 Start-Sleep -Seconds 2 # Démarrer le serveur Pronote API Write-Host "" Write-Host "[1/3] Demarrage du serveur Pronote API..." -ForegroundColor Cyan Set-Location $parentPath if (Test-Path "server.js") { $pronoteJob = Start-Job -ScriptBlock { param($path) Set-Location $path node server.js } -ArgumentList $parentPath Write-Host " Serveur Pronote API demarre (Job ID: $($pronoteJob.Id))" -ForegroundColor Green Write-Host " URL: http://localhost:3000" -ForegroundColor Gray Start-Sleep -Seconds 3 } else { Write-Host " AVERTISSEMENT: server.js non trouve" -ForegroundColor Yellow } # Démarrer le backend Write-Host "" Write-Host "[2/3] Demarrage du backend..." -ForegroundColor Cyan $backendPath = Join-Path $rootPath "backend" Set-Location $backendPath if (Test-Path "package.json") { $backendJob = Start-Job -ScriptBlock { param($path) Set-Location $path npm run dev } -ArgumentList $backendPath Write-Host " Backend demarre (Job ID: $($backendJob.Id))" -ForegroundColor Green Write-Host " URL: http://localhost:3001" -ForegroundColor Gray Start-Sleep -Seconds 3 } else { Write-Host " AVERTISSEMENT: Backend package.json non trouve" -ForegroundColor Yellow } # Démarrer le frontend Write-Host "" Write-Host "[3/3] Demarrage du frontend..." -ForegroundColor Cyan $frontendPath = Join-Path $rootPath "frontend" Set-Location $frontendPath if (Test-Path "package.json") { $frontendJob = Start-Job -ScriptBlock { param($path) Set-Location $path npm run dev } -ArgumentList $frontendPath Write-Host " Frontend demarre (Job ID: $($frontendJob.Id))" -ForegroundColor Green Write-Host " URL: http://localhost:5173" -ForegroundColor Gray Start-Sleep -Seconds 5 } else { Write-Host " ERREUR: Frontend package.json non trouve!" -ForegroundColor Red } # Afficher le résumé Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host " Tous les services sont demarres! " -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" Write-Host "Services actifs:" -ForegroundColor Cyan Write-Host " - Frontend: http://localhost:5173/profiles" -ForegroundColor White Write-Host " - Backend: http://localhost:3001" -ForegroundColor White Write-Host " - API Pronote: http://localhost:3000" -ForegroundColor White Write-Host "" Write-Host "Jobs PowerShell:" -ForegroundColor Cyan if ($pronoteJob) { Write-Host " - Pronote API: Job $($pronoteJob.Id)" -ForegroundColor Gray } if ($backendJob) { Write-Host " - Backend: Job $($backendJob.Id)" -ForegroundColor Gray } if ($frontendJob) { Write-Host " - Frontend: Job $($frontendJob.Id)" -ForegroundColor Gray } Write-Host "" # Ouvrir le navigateur Write-Host "Ouverture de l'application dans le navigateur..." -ForegroundColor Yellow Start-Sleep -Seconds 2 Start-Process "http://localhost:5173/profiles" Write-Host "" Write-Host "Application ouverte!" -ForegroundColor Green Write-Host "" Write-Host "Instructions:" -ForegroundColor Cyan Write-Host " - L'application est maintenant accessible" -ForegroundColor White Write-Host " - Pour arreter les serveurs, fermez cette fenetre" -ForegroundColor White Write-Host " - Ou appuyez sur Ctrl+C puis tapez 'Stop-Job *'" -ForegroundColor White Write-Host "" Write-Host "Appuyez sur une touche pour voir les logs..." -ForegroundColor Yellow $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") # Afficher les logs en continu Write-Host "" Write-Host "=== Logs des services ===" -ForegroundColor Cyan Write-Host "Appuyez sur Ctrl+C pour quitter" -ForegroundColor Yellow Write-Host "" try { while ($true) { if ($pronoteJob) { $output = Receive-Job -Job $pronoteJob -ErrorAction SilentlyContinue if ($output) { Write-Host "[Pronote] $output" -ForegroundColor Magenta } } if ($backendJob) { $output = Receive-Job -Job $backendJob -ErrorAction SilentlyContinue if ($output) { Write-Host "[Backend] $output" -ForegroundColor Blue } } if ($frontendJob) { $output = Receive-Job -Job $frontendJob -ErrorAction SilentlyContinue if ($output) { Write-Host "[Frontend] $output" -ForegroundColor Green } } Start-Sleep -Milliseconds 500 } } finally { Write-Host "" Write-Host "Arret des services..." -ForegroundColor Yellow if ($pronoteJob) { Stop-Job -Job $pronoteJob -ErrorAction SilentlyContinue; Remove-Job -Job $pronoteJob -ErrorAction SilentlyContinue } if ($backendJob) { Stop-Job -Job $backendJob -ErrorAction SilentlyContinue; Remove-Job -Job $backendJob -ErrorAction SilentlyContinue } if ($frontendJob) { Stop-Job -Job $frontendJob -ErrorAction SilentlyContinue; Remove-Job -Job $frontendJob -ErrorAction SilentlyContinue } Stop-ProcessOnPort 3000 Stop-ProcessOnPort 3001 Stop-ProcessOnPort 5173 Write-Host "Services arretes!" -ForegroundColor Green }