Files
MinglarBackendNestJS/build-prisma-layer.ps1

47 lines
1.8 KiB
PowerShell

# 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)" }