|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [int]$HttpPort = 7071, |
| 4 | + [int]$ProcessorPort = 7072, |
| 5 | + [switch]$NoFrontend |
| 6 | +) |
| 7 | + |
| 8 | +Write-Host 'Starting CIPP local offload simulation' -ForegroundColor Cyan |
| 9 | + |
| 10 | +# Verify Windows Terminal is available |
| 11 | +Get-Command wt -ErrorAction Stop | Out-Null |
| 12 | + |
| 13 | +# Stop any existing node processes |
| 14 | +Get-Process node -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue |
| 15 | + |
| 16 | +# Run installation script to ensure dependencies are installed and updated before starting emulators |
| 17 | +pwsh -File (Join-Path $PSScriptRoot 'Start-CippDevInstallation.ps1') |
| 18 | +Write-Host 'Starting emulators...' -ForegroundColor Cyan |
| 19 | + |
| 20 | +$repoRoot = (Get-Item $PSScriptRoot).Parent.Parent.FullName |
| 21 | +$apiPath = Join-Path -Path $repoRoot -ChildPath 'CIPP-API' |
| 22 | +$frontendPath = Join-Path -Path $repoRoot -ChildPath 'CIPP' |
| 23 | + |
| 24 | +if (-not (Test-Path $apiPath)) { |
| 25 | + throw "CIPP-API path not found: $apiPath" |
| 26 | +} |
| 27 | + |
| 28 | +$azuriteCommand = 'try { azurite } catch { Write-Error $_.Exception.Message } finally { Read-Host "Press Enter to exit" }' |
| 29 | + |
| 30 | +$httpHostCommand = @' |
| 31 | +try { |
| 32 | + $env:WEBSITE_SITE_NAME = "cipp-http" |
| 33 | + $env:CIPP_PROCESSOR = "false" |
| 34 | + $env:AzureFunctionsWebHost__hostid = "cipp-http" |
| 35 | +
|
| 36 | + Set-Item -Path "Env:AzureWebJobs.CIPPTimer.Disabled" -Value "1" |
| 37 | + Set-Item -Path "Env:AzureWebJobs.CIPPActivityFunction.Disabled" -Value "1" |
| 38 | + Set-Item -Path "Env:AzureWebJobs.CIPPOrchestrator.Disabled" -Value "1" |
| 39 | + Set-Item -Path "Env:AzureWebJobs.CIPPQueueTrigger.Disabled" -Value "1" |
| 40 | +
|
| 41 | + func start --port {HTTP_PORT} |
| 42 | +} catch { |
| 43 | + Write-Error $_.Exception.Message |
| 44 | +} finally { |
| 45 | + Read-Host "Press Enter to exit" |
| 46 | +} |
| 47 | +'@ |
| 48 | + |
| 49 | +$processorHostCommand = @' |
| 50 | +try { |
| 51 | + $env:WEBSITE_SITE_NAME = "cipp-proc" |
| 52 | + $env:CIPP_PROCESSOR = "true" |
| 53 | + $env:AzureFunctionsWebHost__hostid = "cipp-proc" |
| 54 | +
|
| 55 | + Set-Item -Path "Env:AzureWebJobs.CIPPHttpTrigger.Disabled" -Value "1" |
| 56 | +
|
| 57 | + func start --port {PROCESSOR_PORT} |
| 58 | +} catch { |
| 59 | + Write-Error $_.Exception.Message |
| 60 | +} finally { |
| 61 | + Read-Host "Press Enter to exit" |
| 62 | +} |
| 63 | +'@ |
| 64 | + |
| 65 | +$httpHostCommand = $httpHostCommand.Replace('{HTTP_PORT}', $HttpPort.ToString()) |
| 66 | +$processorHostCommand = $processorHostCommand.Replace('{PROCESSOR_PORT}', $ProcessorPort.ToString()) |
| 67 | + |
| 68 | +$frontendCommand = 'try { npm run dev } catch { Write-Error $_.Exception.Message } finally { Read-Host "Press Enter to exit" }' |
| 69 | +$swaCommand = 'try { npm run start-swa } catch { Write-Error $_.Exception.Message } finally { Read-Host "Press Enter to exit" }' |
| 70 | + |
| 71 | +$azuriteEncoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($azuriteCommand)) |
| 72 | +$httpHostEncoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($httpHostCommand)) |
| 73 | +$processorHostEncoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($processorHostCommand)) |
| 74 | +$frontendEncoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($frontendCommand)) |
| 75 | +$swaEncoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($swaCommand)) |
| 76 | + |
| 77 | +if ($NoFrontend) { |
| 78 | + wt --title CIPP-Offload-Sim`; new-tab --title 'Azurite' -d $repoRoot pwsh -EncodedCommand $azuriteEncoded`; new-tab --title 'FunctionApp-HTTP' -d $apiPath pwsh -EncodedCommand $httpHostEncoded`; new-tab --title 'FunctionApp-Processor' -d $apiPath pwsh -EncodedCommand $processorHostEncoded |
| 79 | +} else { |
| 80 | + wt --title CIPP-Offload-Sim`; new-tab --title 'Azurite' -d $repoRoot pwsh -EncodedCommand $azuriteEncoded`; new-tab --title 'FunctionApp-HTTP' -d $apiPath pwsh -EncodedCommand $httpHostEncoded`; new-tab --title 'FunctionApp-Processor' -d $apiPath pwsh -EncodedCommand $processorHostEncoded`; new-tab --title 'CIPP Frontend' -d $frontendPath pwsh -EncodedCommand $frontendEncoded`; new-tab --title 'SWA' -d $frontendPath pwsh -EncodedCommand $swaEncoded |
| 81 | +} |
| 82 | + |
| 83 | +Write-Host "Started offload simulation tabs (HTTP:$HttpPort, Processor:$ProcessorPort)." -ForegroundColor Green |
0 commit comments