param(
[Parameter(Mandatory=$true)]
[string]$Version,
[Parameter(Mandatory=$false)]
[string]$Folder = (Get-Location).Path
)
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrEmpty($Version)) {
Write-Host "Usage: .\package.ps1 <version> [folder]"
exit 1
}
$TempDir = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
$LargeFiles = @()
$OriginalLocation = Get-Location
Set-Location $Folder
Get-ChildItem -Path . -Recurse -Directory -Name "__pycache__" | ForEach-Object {
Remove-Item -Path $_ -Recurse -Force
}
$LargeFiles = Get-ChildItem -Path . -Recurse -File | Where-Object { $_.Length -gt 100MB }
foreach ($file in $LargeFiles) {
Move-Item -Path $file.FullName -Destination $TempDir.FullName
}
$ZipName = "krita_vision_tools-windows-x64-$Version.zip"
& 7z a -tzip $ZipName ".\*" | Out-Null
foreach ($file in $LargeFiles) {
$tempFile = Join-Path $TempDir.FullName $file.Name
Move-Item -Path $tempFile -Destination $file.FullName
}
$HomeZipPath = Join-Path $Folder .. .. $ZipName
Move-Item -Path $ZipName -Destination $HomeZipPath
Remove-Item -Path $TempDir.FullName -Recurse -Force
Write-Host "Packaging complete. Zip file moved to $HomeZipPath"
Set-Location $OriginalLocation