mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-31 17:43:04 -06:00
Replace Publish-MacOSBundle.ps1 with Publish-MacOSBundle.csx (.NET 10 single-file app)
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/3f6969d8-9bf9-4236-9b69-3dfe23d765a8
This commit is contained in:
parent
5a26ba0b5a
commit
f5e5eaada7
|
|
@ -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 $(ProjectDir)/Publish-MacOSBundle.csx -- $(PublishDir) $(ProjectDir)/../favicon.icns $(Version) $(AssemblyVersion)"
|
||||||
LogStandardErrorAsError="true"
|
LogStandardErrorAsError="true"
|
||||||
/>
|
/>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
|
||||||
97
DiscordChatExporter.Gui/Publish-MacOSBundle.csx
Normal file
97
DiscordChatExporter.Gui/Publish-MacOSBundle.csx
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
// Publishes the GUI app as a macOS .app bundle.
|
||||||
|
// Usage: dotnet run Publish-MacOSBundle.csx -- <PublishDirPath> <IconsFilePath> <FullVersion> <ShortVersion>
|
||||||
|
|
||||||
|
if (args.Length < 4)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine(
|
||||||
|
"Usage: dotnet run Publish-MacOSBundle.csx -- <PublishDirPath> <IconsFilePath> <FullVersion> <ShortVersion>"
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var publishDirPath = Path.GetFullPath(args[0]);
|
||||||
|
var iconsFilePath = args[1];
|
||||||
|
var fullVersion = args[2];
|
||||||
|
var shortVersion = args[3];
|
||||||
|
|
||||||
|
// Setup paths
|
||||||
|
var tempDirPath = Path.GetFullPath(Path.Combine(publishDirPath, "../publish-macos-app-temp"));
|
||||||
|
var bundleName = "DiscordChatExporter.app";
|
||||||
|
var bundleDirPath = Path.Combine(tempDirPath, bundleName);
|
||||||
|
var contentsDirPath = Path.Combine(bundleDirPath, "Contents");
|
||||||
|
var macosDirPath = Path.Combine(contentsDirPath, "MacOS");
|
||||||
|
var resourcesDirPath = Path.Combine(contentsDirPath, "Resources");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Initialize the bundle's directory structure
|
||||||
|
Directory.CreateDirectory(bundleDirPath);
|
||||||
|
Directory.CreateDirectory(contentsDirPath);
|
||||||
|
Directory.CreateDirectory(macosDirPath);
|
||||||
|
Directory.CreateDirectory(resourcesDirPath);
|
||||||
|
|
||||||
|
// Copy icons into the .app's Resources folder
|
||||||
|
File.Copy(iconsFilePath, Path.Combine(resourcesDirPath, "AppIcon.icns"), overwrite: true);
|
||||||
|
|
||||||
|
// Generate the Info.plist metadata file with the app information
|
||||||
|
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>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>
|
||||||
|
""";
|
||||||
|
|
||||||
|
File.WriteAllText(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, recursive: true);
|
||||||
|
|
||||||
|
// Move all files from the publish directory into the MacOS directory
|
||||||
|
foreach (var entry in Directory.GetFileSystemEntries(publishDirPath))
|
||||||
|
{
|
||||||
|
var destination = Path.Combine(macosDirPath, Path.GetFileName(entry));
|
||||||
|
if (Directory.Exists(entry))
|
||||||
|
Directory.Move(entry, destination);
|
||||||
|
else
|
||||||
|
File.Move(entry, destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
@ -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