mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-31 17:43:04 -06:00
Use CliFx for argument parsing in Publish-MacOSBundle.csx
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/4ce0b5aa-af5d-4e9b-9265-2aab165d4b0a
This commit is contained in:
parent
f5e5eaada7
commit
bb87d5cb36
|
|
@ -1,97 +1,118 @@
|
|||
// Publishes the GUI app as a macOS .app bundle.
|
||||
// Usage: dotnet run Publish-MacOSBundle.csx -- <PublishDirPath> <IconsFilePath> <FullVersion> <ShortVersion>
|
||||
#:package CliFx@2.3.6
|
||||
|
||||
if (args.Length < 4)
|
||||
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
|
||||
{
|
||||
Console.Error.WriteLine(
|
||||
"Usage: dotnet run Publish-MacOSBundle.csx -- <PublishDirPath> <IconsFilePath> <FullVersion> <ShortVersion>"
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
[CommandParameter(0, Name = "publish-dir", Description = "Path to the publish output directory.")]
|
||||
public required string PublishDirPath { get; init; }
|
||||
|
||||
var publishDirPath = Path.GetFullPath(args[0]);
|
||||
var iconsFilePath = args[1];
|
||||
var fullVersion = args[2];
|
||||
var shortVersion = args[3];
|
||||
[CommandParameter(1, Name = "icons-file", Description = "Path to the .icns icons file.")]
|
||||
public required string IconsFilePath { get; init; }
|
||||
|
||||
// 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");
|
||||
[CommandParameter(2, Name = "full-version", Description = "Full version string (e.g. '1.2.3.4').")]
|
||||
public required string FullVersion { get; init; }
|
||||
|
||||
try
|
||||
{
|
||||
// Initialize the bundle's directory structure
|
||||
Directory.CreateDirectory(bundleDirPath);
|
||||
Directory.CreateDirectory(contentsDirPath);
|
||||
Directory.CreateDirectory(macosDirPath);
|
||||
Directory.CreateDirectory(resourcesDirPath);
|
||||
[CommandParameter(3, Name = "short-version", Description = "Short version string (e.g. '1.2.3').")]
|
||||
public required string ShortVersion { get; init; }
|
||||
|
||||
// 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))
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
var destination = Path.Combine(macosDirPath, Path.GetFileName(entry));
|
||||
if (Directory.Exists(entry))
|
||||
Directory.Move(entry, destination);
|
||||
else
|
||||
File.Move(entry, destination);
|
||||
// Setup paths
|
||||
var publishDirPath = Path.GetFullPath(PublishDirPath);
|
||||
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 default;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue