feat: Add smart document auto-detection and generic project path support for fellow students
This commit is contained in:
+31
-12
@@ -26,14 +26,29 @@ param(
|
||||
[switch]$Watch,
|
||||
[switch]$RebuildImage,
|
||||
[string]$ProjectPath = "",
|
||||
[string]$File = "seminararbeit.tex"
|
||||
[string]$File = ""
|
||||
)
|
||||
|
||||
$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
|
||||
# 1. Wenn im aktuellen Verzeichnis (wo der User steht) .tex-Dateien existieren -> nimm dieses
|
||||
if (Get-ChildItem -Path (Get-Location) -Filter "*.tex" -ErrorAction SilentlyContinue) {
|
||||
$ProjectPath = (Get-Location).Path
|
||||
}
|
||||
# 2. Falls ../Seminar_Arbeit_BITI_Gruber existiert
|
||||
elseif (Test-Path (Join-Path $ScriptDir "..\Seminar_Arbeit_BITI_Gruber")) {
|
||||
$ProjectPath = Join-Path $ScriptDir "..\Seminar_Arbeit_BITI_Gruber"
|
||||
}
|
||||
else {
|
||||
$ProjectPath = (Get-Location).Path
|
||||
}
|
||||
} else {
|
||||
# Prüfen, ob relativ zum aktuellen Verzeichnis oder relativ zum Skriptverzeichnis
|
||||
if (Test-Path $ProjectPath) {
|
||||
$ProjectPath = (Resolve-Path $ProjectPath).Path
|
||||
} elseif (Test-Path (Join-Path $ScriptDir $ProjectPath)) {
|
||||
$ProjectPath = (Resolve-Path (Join-Path $ScriptDir $ProjectPath)).Path
|
||||
}
|
||||
}
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -81,13 +96,15 @@ if ($Clean) {
|
||||
Write-Host "==> Bereinige Projektverzeichnis: $FullProjectPath" -ForegroundColor Yellow
|
||||
$cmdArgs += "clean"
|
||||
} elseif ($Watch) {
|
||||
Write-Host "==> Starte Watch-Modus für: $File" -ForegroundColor Cyan
|
||||
$targetName = if ($File) { $File } else { "Hauptdokument" }
|
||||
Write-Host "==> Starte Watch-Modus für: $targetName in $FullProjectPath" -ForegroundColor Cyan
|
||||
$cmdArgs += "watch"
|
||||
$cmdArgs += $File
|
||||
if ($File) { $cmdArgs += $File }
|
||||
} else {
|
||||
Write-Host "==> Kompiliere Seminararbeit: $File" -ForegroundColor Green
|
||||
$targetName = if ($File) { $File } else { "Dokument (Auto-Detection)" }
|
||||
Write-Host "==> Kompiliere LaTeX-Projekt: $targetName in $FullProjectPath" -ForegroundColor Green
|
||||
$cmdArgs += "build"
|
||||
$cmdArgs += $File
|
||||
if ($File) { $cmdArgs += $File }
|
||||
}
|
||||
|
||||
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
@@ -98,11 +115,13 @@ $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
|
||||
# Zuletzt geänderte PDF-Datei im Projekt/out-Verzeichnis suchen
|
||||
$pdfFile = Get-ChildItem -Path $FullProjectPath -Filter "*.pdf" -Recurse -File -ErrorAction SilentlyContinue |
|
||||
Sort-Object LastWriteTime -Descending |
|
||||
Select-Object -First 1
|
||||
if ($pdfFile) {
|
||||
Write-Host "PDF generiert: $($pdfFile.FullName) ($([math]::Round($pdfFile.Length / 1KB, 1)) KB)" -ForegroundColor Cyan
|
||||
}
|
||||
} else {
|
||||
Write-Host "`n[OK] Aktion erfolgreich beendet!" -ForegroundColor Green
|
||||
|
||||
Reference in New Issue
Block a user