#!/bin/bash

# Script rápido para testar build após correção

FRONTEND_DIR="/var/www/gestorstream/frontend"
DIST_DIR="$FRONTEND_DIR/dist"

cd "$FRONTEND_DIR" || exit 1

echo "Testando build do frontend..."
rm -rf "$DIST_DIR"/* 2>/dev/null || true

export NODE_OPTIONS="--max-old-space-size=4096"
npm run build

if [ -f "$DIST_DIR/index.html" ]; then
    echo "✅ SUCESSO: index.html criado!"
    chown -R www-data:www-data "$DIST_DIR" 2>/dev/null || true
    find "$DIST_DIR" -type d -exec chmod 755 {} \; 2>/dev/null || true
    find "$DIST_DIR" -type f -exec chmod 644 {} \; 2>/dev/null || true
    systemctl reload nginx
    echo "✅ Permissões ajustadas e nginx recarregado!"
    exit 0
else
    echo "❌ ERRO: index.html ainda não existe!"
    exit 1
fi

