testes/git-auto-sync.ps1

43 lines
1.5 KiB
PowerShell

# Script de Automação Git para IntraNet
# Este script monitora a pasta atual e realiza git commit/push automaticamente.
$Watcher = New-Object IO.FileSystemWatcher
$Watcher.Path = $PSScriptRoot
$Watcher.Filter = "*.*"
$Watcher.IncludeSubdirectories = $true
$Watcher.EnableRaisingEvents = $true
$Action = {
$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
# Ignora pastas de controle e log
if ($path -match "node_modules" -or $path -match ".git") { return }
Write-Host "Alteração detectada em $path ($changeType)" -ForegroundColor Cyan
try {
Write-Host "Gerando build de produção..." -ForegroundColor Gray
npm run build
git add .
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
git commit -m "Auto-deploy: $timestamp (Build included)"
git push origin frontend
Write-Host "Sincronização concluída com sucesso!" -ForegroundColor Green
}
catch {
Write-Host "Erro ao sincronizar com o Git: $_" -ForegroundColor Red
}
}
Register-ObjectEvent $Watcher "Changed" -Action $Action
Register-ObjectEvent $Watcher "Created" -Action $Action
Register-ObjectEvent $Watcher "Deleted" -Action $Action
Register-ObjectEvent $Watcher "Renamed" -Action $Action
Write-Host "Monitoramento do Git iniciado na branch 'frontend'..." -ForegroundColor Yellow
Write-Host "Pressione Ctrl+C para parar."
while ($true) { Start-Sleep -Seconds 5 }