param( [Parameter(Mandatory=$true)] [string]$PublishDirPath, [Parameter(Mandatory=$true)] [string]$IconsFilePath, [Parameter(Mandatory=$true)] [string]$FullVersion, [Parameter(Mandatory=$true)] [string]$ShortVersion ) $ErrorActionPreference = "Stop" # Setup paths $tempDirPath = Join-Path $PublishDirPath "../publish-macos-app-temp" $bundleName = "DiscordChatExporter.app" $bundleDirPath = Join-Path $tempDirPath $bundleName $contentsDirPath = Join-Path $bundleDirPath "Contents" $macosDirPath = Join-Path $contentsDirPath "MacOS" $resourcesDirPath = Join-Path $contentsDirPath "Resources" try { # Initialize the bundle's directory structure New-Item -Path $bundleDirPath -ItemType Directory -Force New-Item -Path $contentsDirPath -ItemType Directory -Force New-Item -Path $macosDirPath -ItemType Directory -Force New-Item -Path $resourcesDirPath -ItemType Directory -Force # Copy icons into the .app's Resources folder Copy-Item -Path $IconsFilePath -Destination (Join-Path $resourcesDirPath "AppIcon.icns") -Force # Generate the Info.plist metadata file with the app information $plistContent = @" CFBundleDisplayName DiscordChatExporter CFBundleName DiscordChatExporter CFBundleExecutable DiscordChatExporter NSHumanReadableCopyright © Oleksii Holub CFBundleIdentifier me.Tyrrrz.DiscordChatExporter CFBundleSpokenName Discord Chat Exporter CFBundleIconFile AppIcon CFBundleIconName AppIcon CFBundleVersion $FullVersion CFBundleShortVersionString $ShortVersion NSHighResolutionCapable CFBundlePackageType APPL "@ Set-Content -Path (Join-Path $contentsDirPath "Info.plist") -Value $plistContent # Delete the previous bundle if it exists if (Test-Path (Join-Path $PublishDirPath $bundleName)) { Remove-Item -Path (Join-Path $PublishDirPath $bundleName) -Recurse -Force } # Move all files from the publish directory into the MacOS directory Get-ChildItem -Path $PublishDirPath | ForEach-Object { Move-Item -Path $_.FullName -Destination $macosDirPath -Force } # Move the final bundle into the publish directory for upload Move-Item -Path $bundleDirPath -Destination $PublishDirPath -Force } finally { # Clean up the temporary directory Remove-Item -Path $tempDirPath -Recurse -Force }