#!/bin/bash

echo "🧹 Cleaning old PM2 process..."
pm2 delete my-portfolio || true

echo "📥 Pulling latest code..."
cd ~/my-portfolio || exit
git reset --hard HEAD
git clean -fd
git pull origin main

echo "📦 Installing dependencies..."
npm install --production

echo "🏗️ Building project..."
npm run build --no-lint

echo "🚀 Starting app with PM2..."
pm2 start npm --name "my-portfolio" -- start

pm2 save

echo "📜 Showing last logs..."
pm2 logs my-portfolio --lines 20
