Files
latex-docker/build-seminar.ps1
T

114 lines
3.6 KiB
PowerShell

<#
.SYNOPSIS
Kompiliert die Seminararbeit mithilfe des LaTeX Docker Containers.
.DESCRIPTION
Skript zum bequemen Bauen, Säubern oder Überwachen der LaTeX-Seminararbeit via Docker.
.PARAMETER Clean
Führt ein 'clean' durch (latexmk -C), um temporäre Build-Dateien zu löschen.
.PARAMETER Watch
Startet den kontinuierlichen Überwachungsmodus (latexmk -pvc).
.PARAMETER RebuildImage
Erzwingt das erneute Erstellen des Docker-Images vor dem LaTeX-Build.
.PARAMETER ProjectPath
Pfad zum LaTeX-Projektverzeichnis (Standard: '../Seminar_Arbeit_BITI_Gruber').
.PARAMETER File
Spezifische LaTeX-Datei zum Kompilieren (Standard: 'seminararbeit.tex').
.EXAMPLE
.\build-seminar.ps1
.EXAMPLE
.\build-seminar.ps1 -Clean
.EXAMPLE
.\build-seminar.ps1 -Watch
#>
[CmdletBinding()]
param(
[switch]$Clean,
[switch]$Watch,
[switch]$RebuildImage,
[string]$ProjectPath = "",
[string]$File = "seminararbeit.tex"
)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if ([string]::IsNullOrWhiteSpace($ProjectPath)) {
$ProjectPath = Join-Path $ScriptDir "..\Seminar_Arbeit_BITI_Gruber"
} elseif (-not [System.IO.Path]::IsPathRooted($ProjectPath)) {
$ProjectPath = Join-Path $ScriptDir $ProjectPath
}
$ErrorActionPreference = "Stop"
# Prüfen, ob Docker erreichbar ist
$dockerCmd = Get-Command docker -ErrorAction SilentlyContinue
if (-not $dockerCmd) {
Write-Error "Docker ist nicht in PATH verfügbar."
exit 1
}
$oldEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
& docker info 2>&1 | Out-Null
$dockerOk = ($LASTEXITCODE -eq 0)
$ErrorActionPreference = $oldEAP
if (-not $dockerOk) {
Write-Error "Docker Desktop ist anscheinend nicht gestartet oder nicht erreichbar."
exit 1
}
$ImageName = "latex-docker:latest"
$FullProjectPath = [System.IO.Path]::GetFullPath($ProjectPath)
if (-not (Test-Path $FullProjectPath)) {
Write-Error "Projektverzeichnis existiert nicht: $FullProjectPath"
exit 1
}
# Image prüfen bzw. bauen
$imageExists = docker images -q $ImageName
if (-not $imageExists -or $RebuildImage) {
Write-Host "==> Erstelle Docker Image '$ImageName'..." -ForegroundColor Cyan
docker build -t $ImageName -t "git.djnizz.at/nizz05/latex-docker:latest" "$PSScriptRoot"
if ($LASTEXITCODE -ne 0) {
Write-Error "Docker Build fehlgeschlagen."
exit 1
}
}
# Befehl bestimmen
$cmdArgs = @()
if ($Clean) {
Write-Host "==> Bereinige Projektverzeichnis: $FullProjectPath" -ForegroundColor Yellow
$cmdArgs += "clean"
} elseif ($Watch) {
Write-Host "==> Starte Watch-Modus für: $File" -ForegroundColor Cyan
$cmdArgs += "watch"
$cmdArgs += $File
} else {
Write-Host "==> Kompiliere Seminararbeit: $File" -ForegroundColor Green
$cmdArgs += "build"
$cmdArgs += $File
}
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
docker run --rm -v "${FullProjectPath}:/workspace" -w /workspace $ImageName @cmdArgs
$stopwatch.Stop()
if ($LASTEXITCODE -eq 0) {
if (-not $Clean -and -not $Watch) {
$pdfPath = Join-Path $FullProjectPath "out\seminararbeit.pdf"
Write-Host "`n[OK] Build erfolgreich abgeschlossen in $([math]::Round($stopwatch.Elapsed.TotalSeconds, 1))s!" -ForegroundColor Green
if (Test-Path $pdfPath) {
$pdfItem = Get-Item $pdfPath
Write-Host "PDF generiert: $pdfPath ($([math]::Round($pdfItem.Length / 1KB, 1)) KB)" -ForegroundColor Cyan
}
} else {
Write-Host "`n[OK] Aktion erfolgreich beendet!" -ForegroundColor Green
}
} else {
Write-Error "`n[FEHLER] LaTeX Build ist fehlgeschlagen mit Exit Code $LASTEXITCODE."
exit $LASTEXITCODE
}