mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-31 09:33:03 -06:00
Replace Publish-MacOSBundle.ps1 with a .NET 10 single-file C# script (#1515)
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
parent
5a26ba0b5a
commit
e794d7c833
|
|
@ -56,7 +56,7 @@
|
||||||
|
|
||||||
<Target Name="PublishMacOSBundle" AfterTargets="Publish" Condition="$(PublishMacOSBundle)">
|
<Target Name="PublishMacOSBundle" AfterTargets="Publish" Condition="$(PublishMacOSBundle)">
|
||||||
<Exec
|
<Exec
|
||||||
Command="pwsh -ExecutionPolicy Bypass -File $(ProjectDir)/Publish-MacOSBundle.ps1 -PublishDirPath $(PublishDir) -IconsFilePath $(ProjectDir)/../favicon.icns -FullVersion $(Version) -ShortVersion $(AssemblyVersion)"
|
Command="dotnet run --file "$(ProjectDir)Publish-MacOSBundle.csx" -- --publish-dir "$(PublishDir)" --icons-file "$(ProjectDir)../favicon.icns" --full-version $(Version) --short-version $(AssemblyVersion)"
|
||||||
LogStandardErrorAsError="true"
|
LogStandardErrorAsError="true"
|
||||||
/>
|
/>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
|
||||||
128
DiscordChatExporter.Gui/Publish-MacOSBundle.csx
Normal file
128
DiscordChatExporter.Gui/Publish-MacOSBundle.csx
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
#!/usr/bin/env -S dotnet run --
|
||||||
|
#:package CliFx
|
||||||
|
|
||||||
|
using CliFx;
|
||||||
|
using CliFx.Attributes;
|
||||||
|
using CliFx.Infrastructure;
|
||||||
|
|
||||||
|
return await new CliApplicationBuilder()
|
||||||
|
.AddCommand<PublishMacOSBundleCommand>()
|
||||||
|
.Build()
|
||||||
|
.RunAsync(args);
|
||||||
|
|
||||||
|
[Command(Description = "Publishes the GUI app as a macOS .app bundle.")]
|
||||||
|
public class PublishMacOSBundleCommand : ICommand
|
||||||
|
{
|
||||||
|
private const string BundleName = "DiscordChatExporter.app";
|
||||||
|
private const string AppName = "DiscordChatExporter";
|
||||||
|
private const string AppCopyright = "© Oleksii Holub";
|
||||||
|
private const string AppIdentifier = "me.Tyrrrz.DiscordChatExporter";
|
||||||
|
private const string AppSpokenName = "Discord Chat Exporter";
|
||||||
|
private const string AppIconName = "AppIcon";
|
||||||
|
|
||||||
|
[CommandOption("publish-dir", Description = "Path to the publish output directory.")]
|
||||||
|
public required string PublishDirPath { get; init; }
|
||||||
|
|
||||||
|
[CommandOption("icons-file", Description = "Path to the .icns icons file.")]
|
||||||
|
public required string IconsFilePath { get; init; }
|
||||||
|
|
||||||
|
[CommandOption("full-version", Description = "Full version string (e.g. '1.2.3.4').")]
|
||||||
|
public required string FullVersion { get; init; }
|
||||||
|
|
||||||
|
[CommandOption("short-version", Description = "Short version string (e.g. '1.2.3').")]
|
||||||
|
public required string ShortVersion { get; init; }
|
||||||
|
|
||||||
|
public async ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
// Set up paths
|
||||||
|
var publishDirPath = Path.GetFullPath(PublishDirPath);
|
||||||
|
var tempDirPath = Path.GetFullPath(
|
||||||
|
Path.Combine(publishDirPath, "../publish-macos-app-temp")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ensure the temporary directory is clean before use in case a previous run crashed
|
||||||
|
if (Directory.Exists(tempDirPath))
|
||||||
|
Directory.Delete(tempDirPath, true);
|
||||||
|
|
||||||
|
var bundleDirPath = Path.Combine(tempDirPath, BundleName);
|
||||||
|
var contentsDirPath = Path.Combine(bundleDirPath, "Contents");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Copy icons into the .app's Resources folder
|
||||||
|
Directory.CreateDirectory(Path.Combine(contentsDirPath, "Resources"));
|
||||||
|
File.Copy(
|
||||||
|
IconsFilePath,
|
||||||
|
Path.Combine(contentsDirPath, "Resources", "AppIcon.icns"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
// Generate the Info.plist metadata file with the app information
|
||||||
|
// lang=xml
|
||||||
|
var plistContent = $"""
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>{AppName}</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>{AppName}</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>{AppName}</string>
|
||||||
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
<string>{AppCopyright}</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>{AppIdentifier}</string>
|
||||||
|
<key>CFBundleSpokenName</key>
|
||||||
|
<string>{AppSpokenName}</string>
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>{AppIconName}</string>
|
||||||
|
<key>CFBundleIconName</key>
|
||||||
|
<string>{AppIconName}</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>{FullVersion}</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>{ShortVersion}</string>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true />
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
""";
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync(Path.Combine(contentsDirPath, "Info.plist"), plistContent);
|
||||||
|
|
||||||
|
// Delete the previous bundle if it exists
|
||||||
|
var existingBundlePath = Path.Combine(publishDirPath, BundleName);
|
||||||
|
if (Directory.Exists(existingBundlePath))
|
||||||
|
Directory.Delete(existingBundlePath, true);
|
||||||
|
|
||||||
|
// Move all files from the publish directory into the MacOS directory
|
||||||
|
Directory.CreateDirectory(Path.Combine(contentsDirPath, "MacOS"));
|
||||||
|
foreach (var entryPath in Directory.GetFileSystemEntries(publishDirPath))
|
||||||
|
{
|
||||||
|
var destinationPath = Path.Combine(
|
||||||
|
contentsDirPath,
|
||||||
|
"MacOS",
|
||||||
|
Path.GetFileName(entryPath)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Directory.Exists(entryPath))
|
||||||
|
Directory.Move(entryPath, destinationPath);
|
||||||
|
else
|
||||||
|
File.Move(entryPath, destinationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move the final bundle into the publish directory for upload
|
||||||
|
Directory.Move(bundleDirPath, Path.Combine(publishDirPath, BundleName));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Clean up the temporary directory
|
||||||
|
if (Directory.Exists(tempDirPath))
|
||||||
|
Directory.Delete(tempDirPath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
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 = @"
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleDisplayName</key>
|
|
||||||
<string>DiscordChatExporter</string>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>DiscordChatExporter</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>DiscordChatExporter</string>
|
|
||||||
<key>NSHumanReadableCopyright</key>
|
|
||||||
<string>© Oleksii Holub</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>me.Tyrrrz.DiscordChatExporter</string>
|
|
||||||
<key>CFBundleSpokenName</key>
|
|
||||||
<string>Discord Chat Exporter</string>
|
|
||||||
<key>CFBundleIconFile</key>
|
|
||||||
<string>AppIcon</string>
|
|
||||||
<key>CFBundleIconName</key>
|
|
||||||
<string>AppIcon</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>$FullVersion</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>$ShortVersion</string>
|
|
||||||
<key>NSHighResolutionCapable</key>
|
|
||||||
<true />
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
"@
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue