#!/bin/bash # build-prisma-layer.sh # Script to rebuild the Prisma layer for Lambda deployment # Usage: ./build-prisma-layer.sh set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LAYER_PATH="$SCRIPT_DIR/layers/prisma/nodejs" echo "๐Ÿ”„ Building Prisma layer for Lambda..." # Step 1: Regenerate Prisma client echo "๐Ÿ“ฆ Regenerating Prisma client..." cd "$SCRIPT_DIR" npx prisma generate # Step 2: Clean layer node_modules echo "๐Ÿงน Cleaning layer node_modules..." rm -rf "$LAYER_PATH/node_modules" # Step 3: Install layer dependencies echo "๐Ÿ“ฅ Installing layer dependencies..." cd "$LAYER_PATH" npm install --production # Step 4: Copy generated Prisma client to layer echo "๐Ÿ“‹ Copying generated Prisma client to layer..." mkdir -p "$LAYER_PATH/node_modules/.prisma" cp -r "$SCRIPT_DIR/node_modules/.prisma/client" "$LAYER_PATH/node_modules/.prisma/client" # Step 5: Calculate layer size LAYER_SIZE=$(du -sh "$LAYER_PATH" | cut -f1) echo "โœ… Layer built successfully!" echo "๐Ÿ“Š Layer size: $LAYER_SIZE" # List contents echo "" echo "๐Ÿ“ Layer contents:" ls -d "$LAYER_PATH/node_modules"/*/ 2>/dev/null | xargs -n 1 basename | sed 's/^/ - /'