diff --git a/CompressIconFolders.ps1 b/CompressIconFolders.ps1 index bb46414..c0605f5 100644 --- a/CompressIconFolders.ps1 +++ b/CompressIconFolders.ps1 @@ -27,6 +27,9 @@ if (-not (Test-Path $iconDirectory)) { exit 1 } +# Use Git to check for changes in the Resources/Icons directory +$gitChangedFiles = git status --porcelain | Select-String -Pattern "^.+/Resources/Icons/" + $folders = Get-ChildItem -Path $iconDirectory -Directory # Iterate through each folder @@ -34,16 +37,40 @@ foreach ($folder in $folders) { # Define the full path to the folder and the destination zip file $folderPath = Join-Path -Path $folder.FullName -ChildPath "*.*" $destinationPath = "$($folder.FullName).zip" + + # Check if the zip file exists + $zipExists = Test-Path $destinationPath + + # Determine if we need to update the zip file + $updateRequired = $false + if ($zipExists) { + if ($gitChangedFiles.Count -gt 0) { + foreach ($changedFile in $gitChangedFiles) { + if ($changedFile -like "*$($folder.Name)/*") { + $updateRequired = $true + Write-Output "$destinationPath exists, but there are changes, updating it." + break + } + } + } + } else { + $updateRequired = $true + Write-Output "$destinationPath doesn't exists, need to create it." + } - # Compress the folder into a zip file - Compress-Archive -Path $folderPath -DestinationPath $destinationPath -Force + if ($updateRequired) { + # Compress the folder into a zip file + Compress-Archive -Path $folderPath -DestinationPath $destinationPath -Force + } else { + Write-Output "$destinationPath is up to date. No action required." + } + # Check if the zip file was created successfully if (Test-Path $destinationPath) { # Delete the original folder if the zip file exists Remove-Item -Path $folder.FullName -Recurse -Force } else { Write-Error "Failed to create $destinationPath" - exit 1 - } + } }