param( [switch]$StartServices ) $ErrorActionPreference = "Stop" function Write-Step($msg) { Write-Host "[AIDOP INIT] $msg" -ForegroundColor Cyan } function Write-Ok($msg) { Write-Host "[ OK ] $msg" -ForegroundColor Green } function Write-Warn($msg) { Write-Host "[ WARN ] $msg" -ForegroundColor Yellow } function Write-Fail($msg) { Write-Host "[ FAIL ] $msg" -ForegroundColor Red } function Test-Command($name) { return [bool](Get-Command $name -ErrorAction SilentlyContinue) } function Invoke-Checked($command, [string[]]$arguments) { & $command @arguments if ($LASTEXITCODE -ne 0) { throw "$command $($arguments -join ' ') failed with exit code $LASTEXITCODE" } } # ---------- paths ---------- $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $platformRoot = Split-Path -Parent $scriptDir $repoRoot = Split-Path -Parent $platformRoot $webDir = Join-Path $repoRoot "Web" $serverDir = Join-Path $repoRoot "server" $entryDir = Join-Path $serverDir "Admin.NET.Web.Entry" $slnFile = Join-Path $serverDir "Admin.NET.sln" Write-Step "Repo root: $repoRoot" Write-Host "" # ---------- 1. directory sanity ---------- Write-Step "1/6 Checking directory structure..." $dirChecks = @( @{ Path = $webDir; Label = "Web (frontend)" }, @{ Path = $serverDir; Label = "server (backend)" }, @{ Path = $entryDir; Label = "Admin.NET.Web.Entry (startup project)" }, @{ Path = $slnFile; Label = "Admin.NET.sln" } ) foreach ($chk in $dirChecks) { if (-not (Test-Path $chk.Path)) { throw "$($chk.Label) not found: $($chk.Path)" } Write-Ok $chk.Label } # ---------- 2. dotnet ---------- Write-Step "2/6 Checking .NET SDK..." if (-not (Test-Command "dotnet")) { Write-Fail "dotnet CLI not found." throw "Please install .NET 10 SDK from https://dotnet.microsoft.com/download" } $dotnetVersion = (dotnet --version).Trim() Write-Ok "dotnet $dotnetVersion" if (-not $dotnetVersion.StartsWith("10.")) { Write-Warn "global.json requires SDK 10.0.x but found $dotnetVersion — restore/build may fail." } # ---------- 3. node / pnpm ---------- Write-Step "3/6 Checking Node.js & pnpm..." if (-not (Test-Command "node")) { throw "node not found. Please install Node.js >= 18 from https://nodejs.org" } $nodeVersion = (node --version).Trim() Write-Ok "node $nodeVersion" $hasPnpm = Test-Command "pnpm" if ($hasPnpm) { $pnpmVersion = (pnpm --version).Trim() Write-Ok "pnpm $pnpmVersion" } else { Write-Warn "pnpm not found; will fall back to npm. Recommend: npm install -g pnpm" } # ---------- 4. frontend deps ---------- Write-Step "4/6 Installing frontend dependencies..." Push-Location $webDir try { if ($hasPnpm) { Invoke-Checked "pnpm" @("install") } else { Invoke-Checked "npm" @("install", "--legacy-peer-deps") } if ($hasPnpm) { Invoke-Checked "pnpm" @("run", "prepare") } else { Invoke-Checked "npm" @("run", "prepare") } Write-Ok "Frontend dependencies installed & git hooks prepared" } finally { Pop-Location } # ---------- 5. backend restore & build ---------- Write-Step "5/6 Restoring & building backend solution..." Invoke-Checked "dotnet" @("restore", $slnFile) Write-Ok "dotnet restore succeeded" Invoke-Checked "dotnet" @("build", $slnFile, "-c", "Debug", "--no-restore") Write-Ok "dotnet build succeeded" # ---------- 6. summary ---------- Write-Host "" Write-Step "6/6 Environment summary" Write-Host " -----------------------------------------------" Write-Host " .NET SDK : $dotnetVersion" Write-Host " Node.js : $nodeVersion" if ($hasPnpm) { Write-Host " pnpm : $pnpmVersion" } Write-Host " Backend entry : $entryDir" Write-Host " Backend URL : http://localhost:5005" Write-Host " Frontend dir : $webDir" Write-Host " Frontend URL : http://localhost:8888" Write-Host " -----------------------------------------------" Write-Host "" # ---------- optional: start services ---------- if ($StartServices) { Write-Step "Starting backend (dotnet run)..." Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$entryDir'; dotnet run" Write-Step "Starting frontend (pnpm dev)..." if ($hasPnpm) { Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$webDir'; pnpm dev" } else { Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$webDir'; npm run dev" } Write-Host "" Write-Ok "Services launched in separate windows." Write-Host " Backend -> http://localhost:5005" Write-Host " Frontend -> http://localhost:8888" Write-Host "" Write-Host " Tip: start backend first; frontend dev-server proxies API to :5005." } Write-Ok "Initialization complete."