Skip to content

Commit d4c0b14

Browse files
committed
Update BuildLibary.ps1
1 parent d3a21d4 commit d4c0b14

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

build/BuildLibary.ps1

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ $ErrorActionPreference = 'stop'
22

33
$zipUrl = 'https://arch-center.azureedge.net/icons/Azure_Public_Service_Icons_V21.zip'
44
$zipPath = 'Azure_Public_Service_Icons_V21.zip'
5-
$destinationPath = "./tmp/"
5+
$destinationPath = './tmp/'
66

77
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath
88
Expand-Archive -Path $zipPath -DestinationPath $destinationPath -Force
99
Remove-Item $zipPath
1010

11+
$combinedOutput = @()
12+
13+
# Function to convert SVGs to mxlibrary format
1114
function Convert-SvgToMxLibrary {
1215
param (
1316
[Parameter(Mandatory)]
@@ -17,19 +20,19 @@ function Convert-SvgToMxLibrary {
1720
[string]$OutputFile,
1821

1922
[int]$GeometryWidth = 48,
20-
[int]$GeometryHeight = 48
23+
[int]$GeometryHeight = 48,
24+
25+
[ref]$GlobalOutput
2126
)
2227

2328
$output = @()
24-
$output += "<mxlibrary>["
2529

2630
Get-ChildItem -Path $InputFolder -Filter *.svg | ForEach-Object {
2731
$file = $_
2832
$svgContent = Get-Content -Path $file.FullName -Raw
2933
$encodedSvg = [System.Uri]::EscapeDataString($svgContent)
3034
$imageUri = "data:image/svg+xml,$encodedSvg"
3135

32-
# Build mxCell XML
3336
$xml = @"
3437
<mxGraphModel>
3538
<root>
@@ -57,26 +60,40 @@ function Convert-SvgToMxLibrary {
5760

5861
$json = ($entry | ConvertTo-Json -Compress)
5962
$output += " $json,"
63+
64+
if ($GlobalOutput) {
65+
$GlobalOutput.Value += " $json,"
66+
}
6067
}
6168

62-
if ($output.Count -gt 1) {
69+
if ($output.Count -gt 0) {
6370
$output[-1] = $output[-1].TrimEnd(',')
6471
}
6572

66-
$output += "]</mxlibrary>"
67-
73+
$output = @("<mxlibrary>[") + $output + "]</mxlibrary>"
6874
$output -join "`n" | Set-Content -LiteralPath $OutputFile -Encoding UTF8
6975
Write-Host "Library saved to $OutputFile"
7076
}
7177

72-
$rootFolder = "./tmp/Azure_Public_Service_Icons/Icons"
78+
$rootFolder = './tmp/Azure_Public_Service_Icons/Icons'
79+
$buildPath = './tmp/Azure_Public_Service_Icons'
7380
$subFolders = Get-ChildItem -Path $rootFolder -Directory
7481
$folderNumber = 1
75-
$buildPath = './tmp/Azure_Public_Service_Icons'
7682

7783
foreach ($folder in $subFolders) {
7884
$prefix = $folderNumber.ToString("D3")
79-
Write-Host "Reading files in folder: $($folder.FullName)"
80-
Convert-SvgToMxLibrary -InputFolder $folder.FullName -OutputFile "$buildPath/$prefix $($folder.Name).xml"
85+
$outputFile = "$buildPath/$prefix $($folder.Name).xml"
86+
Write-Host "Reading files in folder: $($folder.FullName)"
87+
88+
Convert-SvgToMxLibrary -InputFolder $folder.FullName `
89+
-OutputFile $outputFile `
90+
-GlobalOutput ([ref]$combinedOutput)
8191
$folderNumber++
82-
}
92+
}
93+
94+
if ($combinedOutput.Count -gt 0) {
95+
$combinedOutput[-1] = $combinedOutput[-1].TrimEnd(',')
96+
}
97+
$combinedLibrary = @("<mxlibrary>[") + $combinedOutput + "]</mxlibrary>"
98+
$combinedLibrary -join "`n" | Set-Content -LiteralPath "$buildPath/000 all azure public service icons.xml" -Encoding UTF8
99+
Write-Host "Global library saved to 000 all azure public service icons.xml"

0 commit comments

Comments
 (0)