|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | + |
| 3 | +$root = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 4 | +$lambdaRoot = Join-Path $root "lambda_tools" |
| 5 | +$distRoot = Join-Path $lambdaRoot "dist" |
| 6 | +$buildRoot = Join-Path $lambdaRoot ".lambda_build" |
| 7 | + |
| 8 | +if (-not (Test-Path $lambdaRoot)) { |
| 9 | + throw "lambda_tools folder not found: $lambdaRoot" |
| 10 | +} |
| 11 | + |
| 12 | +$excluded = @( |
| 13 | + "shared_lambda", |
| 14 | + "dist", |
| 15 | + ".lambda_build", |
| 16 | + "tests", |
| 17 | + "tool_schemas", |
| 18 | + "__pycache__", |
| 19 | + ".pytest_cache" |
| 20 | +) |
| 21 | + |
| 22 | +$functionDirs = Get-ChildItem -Path $lambdaRoot -Directory | |
| 23 | + Where-Object { $excluded -notcontains $_.Name } |
| 24 | + |
| 25 | +if (-not $functionDirs) { |
| 26 | + throw "No Lambda function folders found under $lambdaRoot" |
| 27 | +} |
| 28 | + |
| 29 | +New-Item -ItemType Directory -Force -Path $distRoot | Out-Null |
| 30 | + |
| 31 | +if (Test-Path $buildRoot) { |
| 32 | + Remove-Item -Recurse -Force $buildRoot |
| 33 | +} |
| 34 | +New-Item -ItemType Directory -Force -Path $buildRoot | Out-Null |
| 35 | + |
| 36 | +foreach ($dir in $functionDirs) { |
| 37 | + $stage = Join-Path $buildRoot $dir.Name |
| 38 | + $zipPath = Join-Path $distRoot "$($dir.Name).zip" |
| 39 | + |
| 40 | + New-Item -ItemType Directory -Force -Path $stage | Out-Null |
| 41 | + |
| 42 | + Copy-Item -Path (Join-Path $dir.FullName "*") -Destination $stage -Recurse -Force |
| 43 | + |
| 44 | + $shared = Join-Path $lambdaRoot "shared_lambda" |
| 45 | + if (Test-Path $shared) { |
| 46 | + Copy-Item -Path $shared -Destination (Join-Path $stage "shared_lambda") -Recurse -Force |
| 47 | + } |
| 48 | + |
| 49 | + Get-ChildItem -Path $stage -Recurse -Directory -Force | |
| 50 | + Where-Object { $_.Name -in @("__pycache__", ".pytest_cache") } | |
| 51 | + Remove-Item -Recurse -Force |
| 52 | + |
| 53 | + Get-ChildItem -Path $stage -Recurse -File -Force | |
| 54 | + Where-Object { $_.Name -like "*.pyc" -or $_.Name -eq ".env" } | |
| 55 | + Remove-Item -Force |
| 56 | + |
| 57 | + if (Test-Path $zipPath) { |
| 58 | + Remove-Item -Force $zipPath |
| 59 | + } |
| 60 | + |
| 61 | + Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zipPath -Force |
| 62 | + Write-Host "Created $zipPath" |
| 63 | +} |
| 64 | + |
| 65 | +Remove-Item -Recurse -Force $buildRoot |
| 66 | +Write-Host "Done. Zip files are in $distRoot" |
0 commit comments