#!/bin/bash
# deploy.sh

# Build the application
npm run build

# Backup current deployment
sudo cp -r /var/www/dist /var/www/dist.backup.$(date +%Y%m%d_%H%M%S)

# Deploy new build
sudo rm -rf /var/www/dist/*
sudo cp -r dist/* /var/www/dist/

# Set proper permissions
sudo chown -R www-data:www-data /var/www/dist
sudo chmod -R 755 /var/www/dist

# Test nginx config and reload
sudo nginx -t && sudo systemctl reload nginx

echo "Deployment completed successfully!"