mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-31 17:43:04 -06:00
Remove CliFx dependency from script to fix macOS CI timeout
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/55dce499-3afd-4c84-a913-19f7412efe1b
This commit is contained in:
parent
8d03008e2e
commit
d8b46b5610
|
|
@ -1,128 +1,103 @@
|
||||||
#!/usr/bin/env -S dotnet run --
|
#!/usr/bin/env -S dotnet run --
|
||||||
#:package CliFx
|
|
||||||
|
|
||||||
using CliFx;
|
// Set up arguments
|
||||||
using CliFx.Attributes;
|
string GetArg(string name)
|
||||||
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";
|
var idx = Array.IndexOf(args, name);
|
||||||
private const string AppName = "DiscordChatExporter";
|
if (idx < 0 || idx + 1 >= args.Length)
|
||||||
private const string AppCopyright = "© Oleksii Holub";
|
throw new InvalidOperationException($"Missing required option: {name}");
|
||||||
private const string AppIdentifier = "me.Tyrrrz.DiscordChatExporter";
|
return args[idx + 1];
|
||||||
private const string AppSpokenName = "Discord Chat Exporter";
|
}
|
||||||
private const string AppIconName = "AppIcon";
|
|
||||||
|
var publishDirPathArg = GetArg("--publish-dir");
|
||||||
[CommandOption("publish-dir", Description = "Path to the publish output directory.")]
|
var iconsFilePathArg = GetArg("--icons-file");
|
||||||
public required string PublishDirPath { get; init; }
|
var fullVersionArg = GetArg("--full-version");
|
||||||
|
var shortVersionArg = GetArg("--short-version");
|
||||||
[CommandOption("icons-file", Description = "Path to the .icns icons file.")]
|
|
||||||
public required string IconsFilePath { get; init; }
|
const string BundleName = "DiscordChatExporter.app";
|
||||||
|
const string AppName = "DiscordChatExporter";
|
||||||
[CommandOption("full-version", Description = "Full version string (e.g. '1.2.3.4').")]
|
const string AppCopyright = "© Oleksii Holub";
|
||||||
public required string FullVersion { get; init; }
|
const string AppIdentifier = "me.Tyrrrz.DiscordChatExporter";
|
||||||
|
const string AppSpokenName = "Discord Chat Exporter";
|
||||||
[CommandOption("short-version", Description = "Short version string (e.g. '1.2.3').")]
|
const string AppIconName = "AppIcon";
|
||||||
public required string ShortVersion { get; init; }
|
|
||||||
|
// Set up paths
|
||||||
public async ValueTask ExecuteAsync(IConsole console)
|
var publishDirPath = Path.GetFullPath(publishDirPathArg);
|
||||||
{
|
var tempDirPath = Path.GetFullPath(Path.Combine(publishDirPath, "../publish-macos-app-temp"));
|
||||||
// Set up paths
|
|
||||||
var publishDirPath = Path.GetFullPath(PublishDirPath);
|
// Ensure the temporary directory is clean before use in case a previous run crashed
|
||||||
var tempDirPath = Path.GetFullPath(
|
if (Directory.Exists(tempDirPath))
|
||||||
Path.Combine(publishDirPath, "../publish-macos-app-temp")
|
Directory.Delete(tempDirPath, true);
|
||||||
);
|
|
||||||
|
var bundleDirPath = Path.Combine(tempDirPath, BundleName);
|
||||||
// Ensure the temporary directory is clean before use in case a previous run crashed
|
var contentsDirPath = Path.Combine(bundleDirPath, "Contents");
|
||||||
if (Directory.Exists(tempDirPath))
|
|
||||||
Directory.Delete(tempDirPath, true);
|
try
|
||||||
|
{
|
||||||
var bundleDirPath = Path.Combine(tempDirPath, BundleName);
|
// Copy icons into the .app's Resources folder
|
||||||
var contentsDirPath = Path.Combine(bundleDirPath, "Contents");
|
Directory.CreateDirectory(Path.Combine(contentsDirPath, "Resources"));
|
||||||
|
File.Copy(iconsFilePathArg, Path.Combine(contentsDirPath, "Resources", "AppIcon.icns"), true);
|
||||||
try
|
|
||||||
{
|
// Generate the Info.plist metadata file with the app information
|
||||||
// Copy icons into the .app's Resources folder
|
// lang=xml
|
||||||
Directory.CreateDirectory(Path.Combine(contentsDirPath, "Resources"));
|
var plistContent = $"""
|
||||||
File.Copy(
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
IconsFilePath,
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
Path.Combine(contentsDirPath, "Resources", "AppIcon.icns"),
|
<plist version="1.0">
|
||||||
true
|
<dict>
|
||||||
);
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>{AppName}</string>
|
||||||
// Generate the Info.plist metadata file with the app information
|
<key>CFBundleName</key>
|
||||||
// lang=xml
|
<string>{AppName}</string>
|
||||||
var plistContent = $"""
|
<key>CFBundleExecutable</key>
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<string>{AppName}</string>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<key>NSHumanReadableCopyright</key>
|
||||||
<plist version="1.0">
|
<string>{AppCopyright}</string>
|
||||||
<dict>
|
<key>CFBundleIdentifier</key>
|
||||||
<key>CFBundleDisplayName</key>
|
<string>{AppIdentifier}</string>
|
||||||
<string>{AppName}</string>
|
<key>CFBundleSpokenName</key>
|
||||||
<key>CFBundleName</key>
|
<string>{AppSpokenName}</string>
|
||||||
<string>{AppName}</string>
|
<key>CFBundleIconFile</key>
|
||||||
<key>CFBundleExecutable</key>
|
<string>{AppIconName}</string>
|
||||||
<string>{AppName}</string>
|
<key>CFBundleIconName</key>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<string>{AppIconName}</string>
|
||||||
<string>{AppCopyright}</string>
|
<key>CFBundleVersion</key>
|
||||||
<key>CFBundleIdentifier</key>
|
<string>{fullVersionArg}</string>
|
||||||
<string>{AppIdentifier}</string>
|
<key>CFBundleShortVersionString</key>
|
||||||
<key>CFBundleSpokenName</key>
|
<string>{shortVersionArg}</string>
|
||||||
<string>{AppSpokenName}</string>
|
<key>NSHighResolutionCapable</key>
|
||||||
<key>CFBundleIconFile</key>
|
<true />
|
||||||
<string>{AppIconName}</string>
|
<key>CFBundlePackageType</key>
|
||||||
<key>CFBundleIconName</key>
|
<string>APPL</string>
|
||||||
<string>{AppIconName}</string>
|
</dict>
|
||||||
<key>CFBundleVersion</key>
|
</plist>
|
||||||
<string>{FullVersion}</string>
|
""";
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>{ShortVersion}</string>
|
await File.WriteAllTextAsync(Path.Combine(contentsDirPath, "Info.plist"), plistContent);
|
||||||
<key>NSHighResolutionCapable</key>
|
|
||||||
<true />
|
// Delete the previous bundle if it exists
|
||||||
<key>CFBundlePackageType</key>
|
var existingBundlePath = Path.Combine(publishDirPath, BundleName);
|
||||||
<string>APPL</string>
|
if (Directory.Exists(existingBundlePath))
|
||||||
</dict>
|
Directory.Delete(existingBundlePath, true);
|
||||||
</plist>
|
|
||||||
""";
|
// Move all files from the publish directory into the MacOS directory
|
||||||
|
Directory.CreateDirectory(Path.Combine(contentsDirPath, "MacOS"));
|
||||||
await File.WriteAllTextAsync(Path.Combine(contentsDirPath, "Info.plist"), plistContent);
|
foreach (var entryPath in Directory.GetFileSystemEntries(publishDirPath))
|
||||||
|
{
|
||||||
// Delete the previous bundle if it exists
|
var destinationPath = Path.Combine(contentsDirPath, "MacOS", Path.GetFileName(entryPath));
|
||||||
var existingBundlePath = Path.Combine(publishDirPath, BundleName);
|
|
||||||
if (Directory.Exists(existingBundlePath))
|
if (Directory.Exists(entryPath))
|
||||||
Directory.Delete(existingBundlePath, true);
|
Directory.Move(entryPath, destinationPath);
|
||||||
|
else
|
||||||
// Move all files from the publish directory into the MacOS directory
|
File.Move(entryPath, destinationPath);
|
||||||
Directory.CreateDirectory(Path.Combine(contentsDirPath, "MacOS"));
|
}
|
||||||
foreach (var entryPath in Directory.GetFileSystemEntries(publishDirPath))
|
|
||||||
{
|
// Move the final bundle into the publish directory for upload
|
||||||
var destinationPath = Path.Combine(
|
Directory.Move(bundleDirPath, Path.Combine(publishDirPath, BundleName));
|
||||||
contentsDirPath,
|
}
|
||||||
"MacOS",
|
finally
|
||||||
Path.GetFileName(entryPath)
|
{
|
||||||
);
|
// Clean up the temporary directory
|
||||||
|
if (Directory.Exists(tempDirPath))
|
||||||
if (Directory.Exists(entryPath))
|
Directory.Delete(tempDirPath, true);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue