param( [string]$PythonHome = $env:EDGE_PYTHON_HOME ) $ErrorActionPreference = "Stop" function Resolve-PythonHome { param([string]$InputPythonHome) if ($InputPythonHome) { return (Resolve-Path -LiteralPath $InputPythonHome).Path } $candidates = @( "C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python311", "C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312", "C:\Python311", "C:\Python312" ) foreach ($candidate in $candidates) { if (Test-Path (Join-Path $candidate "python.exe")) { return (Resolve-Path -LiteralPath $candidate).Path } } throw "PythonHome not provided and no local Python runtime directory was found." } $root = Split-Path -Parent $PSScriptRoot $dist = Join-Path $root "dist" $timestamp = Get-Date -Format "yyyyMMdd-HHmmss" $packageRoot = Join-Path $dist "edge-agent-windows-$timestamp" $runtimeRoot = Join-Path $packageRoot "runtime\python" $zipPath = Join-Path $dist "edge-agent-windows-$timestamp.zip" $resolvedPythonHome = Resolve-PythonHome -InputPythonHome $PythonHome if (Test-Path $zipPath) { Remove-Item -LiteralPath $zipPath -Force } New-Item -ItemType Directory -Path $packageRoot -Force | Out-Null New-Item -ItemType Directory -Path $runtimeRoot -Force | Out-Null New-Item -ItemType Directory -Path $dist -Force | Out-Null Copy-Item -LiteralPath (Join-Path $root "app") -Destination $packageRoot -Recurse Copy-Item -LiteralPath (Join-Path $root "README.md") -Destination $packageRoot Copy-Item -LiteralPath (Join-Path $root "pyproject.toml") -Destination $packageRoot Copy-Item -LiteralPath (Join-Path $PSScriptRoot "start-windows.ps1") -Destination (Join-Path $packageRoot "start.ps1") Get-ChildItem -LiteralPath $resolvedPythonHome -Force | Copy-Item -Destination $runtimeRoot -Recurse Compress-Archive -Path (Join-Path $packageRoot "*") -DestinationPath $zipPath -Force Write-Output $zipPath