S05: build.ps1 repariert: Die zuvor eingebaute Write-Both-Hilfsfunktion und em-Dashes in Code-Strings hatten zu einem stillen Frueh-Abbruch unter Windows PowerShell 5.1 gefuehrt. Neue Version verwendet stattdessen direkte Write-Host/Write-Log-Paare an den Fortschrittsstellen, ASCII-only in Code-Strings, strukturell nah an der initial funktionierenden Version. Konsolenausgabe mit farbigen Statuszeilen pro Build-Phase ist jetzt sichtbar, Pandoc-Detail-Output bleibt im Log.

This commit is contained in:
tlg
2026-04-25 12:05:52 +02:00
parent cc1110aea6
commit 823331955b
6 changed files with 41 additions and 44 deletions

View File

@@ -7,17 +7,15 @@
Deterministischer Build ohne GUI oder Komfortfunktionen.
- PDF via Pandoc + LuaLaTeX, nutzt templates/template.tex
- DOCX via Pandoc, nutzt templates/reference.docx
- Log in output/build.log (überschrieben pro Build)
- Fortschrittsausgaben werden zusätzlich in der Konsole angezeigt
- Log in output/build.log (ueberschrieben pro Build)
- Fortschritt wird zusaetzlich in der Konsole angezeigt
- Exit-Code 0 = beide Ausgaben erfolgreich, 1 = ein oder beide Schritte fehlgeschlagen
.NOTES
Voraussetzungen auf dem System:
- Pandoc (im PATH)
- MiKTeX mit LuaLaTeX und den Paketen fontspec, microtype, polyglossia,
geometry, xcolor, hyperref, graphicx, enumitem, titlesec, fancyhdr,
lastpage, xurl.
- System-Fonts: IBM Plex Sans, IBM Plex Mono (für Windows installiert).
- MiKTeX mit LuaLaTeX
- System-Fonts: IBM Plex Sans und IBM Plex Mono fuer Windows installiert
MiKTeX mit "Install missing packages on the fly: Yes" zieht fehlende
LaTeX-Pakete beim ersten Lauf automatisch.
#>
@@ -42,27 +40,18 @@ if (-not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
}
# --- Log initialisieren (UTF-8 ohne BOM) --------------------------------------
# --- Log initialisieren (UTF-8 ohne BOM) -------------------------------------
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($logFile, '', $utf8NoBom)
# Schreibt nur in die Log-Datei (für Pandoc-Ausgaben und Detail-Zeilen)
function Write-Log {
param([string]$Line)
[System.IO.File]::AppendAllText($logFile, $Line + [Environment]::NewLine, $utf8NoBom)
}
[System.IO.File]::WriteAllText($logFile, '', $utf8NoBom)
# Schreibt auf Konsole UND in die Log-Datei (für Fortschritts-Meilensteine)
function Write-Both {
param(
[string]$Line,
[string]$Color = 'Gray'
)
Write-Host $Line -ForegroundColor $Color
Write-Log $Line
}
Write-Both ("===== Build gestartet: {0} =====" -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')) 'Cyan'
$startTs = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
Write-Host ""
Write-Host "===== Build gestartet: $startTs =====" -ForegroundColor Cyan
Write-Log "===== Build gestartet: $startTs ====="
Write-Log "Source: $sourceFile"
Write-Log "Template-TEX: $templateTex"
Write-Log "Reference: $referenceDoc"
@@ -71,21 +60,24 @@ Write-Log ''
$overallExit = 0
# --- Pflichtdateien prüfen ----------------------------------------------------
# --- Pflichtdateien pruefen --------------------------------------------------
foreach ($f in @($sourceFile, $templateTex, $referenceDoc)) {
if (-not (Test-Path $f)) {
Write-Both "FEHLER: Pflichtdatei fehlt: $f" 'Red'
Write-Host "FEHLER: Pflichtdatei fehlt: $f" -ForegroundColor Red
Write-Log "FEHLER: Pflichtdatei fehlt: $f"
$overallExit = 1
}
}
if ($overallExit -ne 0) {
Write-Both '===== Abbruch: Pflichtdateien fehlen =====' 'Red'
Write-Host "===== Abbruch: Pflichtdateien fehlen =====" -ForegroundColor Red
Write-Log "===== Abbruch: Pflichtdateien fehlen ====="
exit $overallExit
}
# --- PDF-Build ----------------------------------------------------------------
Write-Both '' 'Gray'
Write-Both '[1/2] PDF wird erzeugt (Pandoc + LuaLaTeX) ...' 'Yellow'
# --- PDF-Build ---------------------------------------------------------------
Write-Host ""
Write-Host "[1/2] PDF wird erzeugt (Pandoc + LuaLaTeX) ..." -ForegroundColor Yellow
Write-Log "--- Pandoc -> PDF (LuaLaTeX) ---"
$pdfArgs = @(
'--from=markdown+smart',
'--pdf-engine=lualatex',
@@ -100,15 +92,18 @@ $pdfExit = $LASTEXITCODE
$pdfOutput | ForEach-Object { Write-Log ([string]$_) }
if ($pdfExit -eq 0 -and (Test-Path $outputPdf)) {
$sizeKB = [math]::Round((Get-Item $outputPdf).Length / 1KB, 1)
Write-Both " PDF OK ($sizeKB KB): $outputPdf" 'Green'
Write-Host " PDF OK ($sizeKB KB): $outputPdf" -ForegroundColor Green
Write-Log "PDF OK: $outputPdf ($sizeKB KB)"
} else {
Write-Both " PDF FEHLER (Exit $pdfExit) Details siehe build.log" 'Red'
Write-Host " PDF FEHLER (Exit $pdfExit) - Details siehe build.log" -ForegroundColor Red
Write-Log "PDF FEHLER (Exit $pdfExit)"
$overallExit = 1
}
# --- DOCX-Build ---------------------------------------------------------------
Write-Both '' 'Gray'
Write-Both '[2/2] DOCX wird erzeugt (Pandoc) ...' 'Yellow'
# --- DOCX-Build --------------------------------------------------------------
Write-Host ""
Write-Host "[2/2] DOCX wird erzeugt (Pandoc) ..." -ForegroundColor Yellow
Write-Log "--- Pandoc -> DOCX ---"
$docxArgs = @(
'--from=markdown+smart',
"--reference-doc=$referenceDoc",
@@ -122,18 +117,21 @@ $docxExit = $LASTEXITCODE
$docxOutput | ForEach-Object { Write-Log ([string]$_) }
if ($docxExit -eq 0 -and (Test-Path $outputDocx)) {
$sizeKB = [math]::Round((Get-Item $outputDocx).Length / 1KB, 1)
Write-Both " DOCX OK ($sizeKB KB): $outputDocx" 'Green'
Write-Host " DOCX OK ($sizeKB KB): $outputDocx" -ForegroundColor Green
Write-Log "DOCX OK: $outputDocx ($sizeKB KB)"
} else {
Write-Both " DOCX FEHLER (Exit $docxExit) Details siehe build.log" 'Red'
Write-Host " DOCX FEHLER (Exit $docxExit) - Details siehe build.log" -ForegroundColor Red
Write-Log "DOCX FEHLER (Exit $docxExit)"
$overallExit = 1
}
Write-Both '' 'Gray'
$endTs = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
Write-Host ""
if ($overallExit -eq 0) {
Write-Both "===== Build beendet: $endTs, Exit-Code $overallExit (OK) =====" 'Cyan'
Write-Host "===== Build beendet: $endTs, Exit-Code $overallExit (OK) =====" -ForegroundColor Cyan
} else {
Write-Both "===== Build beendet: $endTs, Exit-Code $overallExit (FEHLER) =====" 'Red'
Write-Host "===== Build beendet: $endTs, Exit-Code $overallExit (FEHLER) =====" -ForegroundColor Red
}
Write-Log "===== Build beendet: $endTs, Exit-Code $overallExit ====="
exit $overallExit