aidop_init.ps1 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. param(
  2. [switch]$StartServices
  3. )
  4. $ErrorActionPreference = "Stop"
  5. function Write-Step($msg) {
  6. Write-Host "[AIDOP INIT] $msg"
  7. }
  8. function Test-Command($name) {
  9. return [bool](Get-Command $name -ErrorAction SilentlyContinue)
  10. }
  11. function Invoke-Checked($command, [string[]]$arguments) {
  12. & $command @arguments
  13. if ($LASTEXITCODE -ne 0) {
  14. throw "$command failed with exit code $LASTEXITCODE"
  15. }
  16. }
  17. Write-Step "Workspace: $(Get-Location)"
  18. if (-not (Test-Command "dotnet")) {
  19. throw "dotnet not found. Please install .NET SDK 8.x first."
  20. }
  21. $dotnetVersion = (dotnet --version)
  22. Write-Step "dotnet version: $dotnetVersion"
  23. if (-not (Test-Command "node")) {
  24. throw "node not found. Please install Node.js >=18 first."
  25. }
  26. $nodeVersion = (node --version)
  27. Write-Step "node version: $nodeVersion"
  28. $webDir = "d:/Projects/Ai-DOP/SourceCode/references/Admin.NET/Web"
  29. $entryDir = "d:/Projects/Ai-DOP/SourceCode/references/Admin.NET/server/Admin.NET.Web.Entry"
  30. if (-not (Test-Path $webDir)) { throw "Web directory not found: $webDir" }
  31. if (-not (Test-Path $entryDir)) { throw "Web.Entry directory not found: $entryDir" }
  32. Write-Step "Install frontend dependencies + hooks"
  33. Push-Location $webDir
  34. try {
  35. if (Test-Command "pnpm") {
  36. Invoke-Checked "pnpm" @("install")
  37. } else {
  38. Write-Step "pnpm not found, fallback to npm install --legacy-peer-deps"
  39. Invoke-Checked "npm" @("install", "--legacy-peer-deps")
  40. }
  41. Invoke-Checked "npm" @("run", "prepare")
  42. } finally {
  43. Pop-Location
  44. }
  45. Write-Step "Build backend core (net8.0)"
  46. Invoke-Checked "dotnet" @("build", "d:/Projects/Ai-DOP/SourceCode/references/Admin.NET/server/Admin.NET.Core/Admin.NET.Core.csproj", "--framework", "net8.0")
  47. if ($StartServices) {
  48. Write-Step "Starting backend and frontend services"
  49. Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$entryDir'; dotnet run --framework net8.0"
  50. Start-Process powershell -ArgumentList "-NoExit", "-Command", "Set-Location '$webDir'; npm run dev"
  51. Write-Step "Services started. Backend: http://localhost:5005 Frontend: http://localhost:8888"
  52. }
  53. Write-Step "Initialization complete."