# build-prisma-layer.ps1 # Script to rebuild the Prisma layer for Lambda deployment # Usage: .\build-prisma-layer.ps1 $ErrorActionPreference = "Stop" $projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $layerPath = Join-Path $projectRoot "layers\prisma\nodejs" $nodeModulesPath = Join-Path $layerPath "node_modules" Write-Host "๐Ÿ”„ Building Prisma layer for Lambda..." -ForegroundColor Cyan # Step 1: Regenerate Prisma client Write-Host "๐Ÿ“ฆ Regenerating Prisma client..." -ForegroundColor Yellow Push-Location $projectRoot npx prisma generate Pop-Location # Step 2: Clean layer node_modules Write-Host "๐Ÿงน Cleaning layer node_modules..." -ForegroundColor Yellow if (Test-Path $nodeModulesPath) { Remove-Item -Recurse -Force $nodeModulesPath } # Step 3: Install layer dependencies Write-Host "๐Ÿ“ฅ Installing layer dependencies..." -ForegroundColor Yellow Push-Location $layerPath npm install --production Pop-Location # Step 4: Copy generated Prisma client to layer Write-Host "๐Ÿ“‹ Copying generated Prisma client to layer..." -ForegroundColor Yellow $sourcePrisma = Join-Path $projectRoot "node_modules\.prisma\client" $destPrisma = Join-Path $nodeModulesPath ".prisma\client" New-Item -ItemType Directory -Force -Path (Split-Path $destPrisma) | Out-Null Copy-Item -Path $sourcePrisma -Destination $destPrisma -Recurse -Force # Step 5: Calculate layer size $layerSize = (Get-ChildItem -Path $layerPath -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB Write-Host "โœ… Layer built successfully!" -ForegroundColor Green Write-Host "๐Ÿ“Š Layer size: $([math]::Round($layerSize, 2)) MB" -ForegroundColor Cyan # List contents Write-Host "`n๐Ÿ“ Layer contents:" -ForegroundColor Cyan Get-ChildItem $nodeModulesPath -Directory | ForEach-Object { Write-Host " - $($_.Name)" }