Skip to content

Commit c248a08

Browse files
committed
improve error handling and formatting in font gen script
1 parent 53226c8 commit c248a08

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

scripts/Generate-Fonts.ps1

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
Lightweight wrapper that invokes `assets/fonts/fontforge-ufo-to-ttf.pe`
66
to generate .ttf files.
77
.PARAMETER Publish
8-
(Optional) Specifies whether generated .ttf files should be moved from the
8+
Specifies whether generated .ttf files should be moved from the
99
source assets folder into the application assets folder. If not specified,
1010
generated .ttf files remain in the source assets folder.
1111
.EXAMPLE
1212
PS> .\scripts\Generate-Fonts.ps1
1313
.EXAMPLE
1414
PS> .\scripts\Generate-Fonts.ps1 -Publish
1515
.NOTES
16-
FontForge must be installed and included on the system PATH environment
17-
variables.
16+
FontForge must be installed and included in the PATH environment variable.
1817
#>
1918

2019
[CmdletBinding()]
@@ -31,31 +30,44 @@ $fontsPath = Join-Path -Path $repositoryPath -ChildPath "assets\fonts"
3130
$publishPath = Join-Path -Path $repositoryPath -ChildPath "Screenbox\Assets\Fonts"
3231

3332
if (-not (Get-Command "fontforge" -ErrorAction SilentlyContinue)) {
34-
Write-Error "FontForge is not installed or not in PATH environment variable."
33+
Write-Error "Install the latest version of FontForge.`nAfter FontForge is installed, make sure that the location of the 'fontforge.exe' is included in the PATH environment variable." -Category NotInstalled
34+
exit 1
35+
}
36+
37+
if (-not (Test-Path (Join-Path -Path $fontsPath -ChildPath $ScriptFileName))) {
38+
Write-Error "The script file $ScriptFileName was not found." -Category ObjectNotFound
3539
exit 1
3640
}
3741

3842
$ufoDirs = @(Get-ChildItem -Path $fontsPath -Filter '*.ufo' -Directory -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName)
3943

4044
if ($ufoDirs.Count -gt 0) {
41-
Write-Host "Found UFO packages:`n$($ufoDirs -join "`n")"
45+
Write-Output "Found UFO packages:`n$($ufoDirs -join "`n")"
4246

4347
# Build argument list: -script <scriptFile> <ufo#1> <ufo#2> ...
4448
$cmdArgs = @('-script', (Join-Path -Path $fontsPath -ChildPath $ScriptFileName)) + $ufoDirs
4549
& "fontforge" @cmdArgs
4650

4751
if ($Publish) {
4852
try {
49-
Move-Item -Path (Join-Path $fontsPath '*.ttf') -Destination $publishPath -Force -ErrorAction Stop
50-
} catch [System.Management.Automation.ItemNotFoundException] {
51-
Write-Host "No .ttf files found in the folder $fontsPath."
52-
} catch {
53+
$ttfFiles = @(Get-ChildItem -Path $fontsPath -Filter '*.ttf' -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName)
54+
55+
if ($ttfFiles.Count -eq 0) {
56+
Write-Error "No .ttf files found in the folder: $fontsPath" -Category ObjectNotFound
57+
exit 1
58+
}
59+
60+
Move-Item -Path $ttfFiles -Destination $publishPath -Force -ErrorAction Stop
61+
}
62+
catch {
5363
Write-Error $_.Exception.Message
5464
exit 1
5565
}
5666
}
5767

58-
} else {
59-
Write-Host "No UFO packages found in the folder $fontsPath."
6068
exit 0
6169
}
70+
else {
71+
Write-Error "No UFO packages found in the folder: $fontsPath" -Category ObjectNotFound
72+
exit 1
73+
}

0 commit comments

Comments
 (0)