mirror of
https://github.com/modernuo/ModernUO
synced 2026-08-11 22:23:06 -04:00
## Summary Replaces the basic `publish.cmd`/`publish.sh` scripts with an interactive **BuildTool** — a C# console app using [Spectre.Console](https://spectreconsole.net/) that guides users through publishing, prerequisite checking, and cross-compilation. ### Why The community found the existing publish scripts unhelpful for newcomers. They worked but didn't walk users through the process, didn't check prerequisites, and provided no feedback when things went wrong. ### What's New **Interactive BuildTool** (`Projects/BuildTool/`) - NativeAOT-compiled C# console app with true-color ASCII logo and ModernUO brand gold/silver palette - Guided publish wizard with step-by-step back navigation (Ctrl+C or menu "Back" to go to previous step) - Prerequisite checking: .NET SDK version, VC++ Redistributable (Windows), native libraries (Linux/macOS) - .NET SDK auto-install offer via Microsoft's official install scripts - Platform detection: Windows 10 vs 11 (build number), macOS codenames, Linux distro + kernel version - Cross-compilation support: skips native library checks, shows target prerequisites after build - Non-interactive mode for CI: `--config Release --skip-prereqs` - Backward-compatible positional args: `publish.cmd release win x64` still works **Shell Wrappers** (`publish.cmd`, `publish.ps1`, `publish.sh`) - Try native BuildTool binary first (downloaded from GitHub Releases) - Fall back to `dotnet run --project Projects/BuildTool` if unavailable - SDK bootstrapping: offer to install .NET if not found **CI/CD Updates** - Build/test workflows target `Projects/Application/Application.csproj` instead of the solution (excludes BuildTool and test projects from publish) - New `build-tool-release.yml` workflow builds NativeAOT binaries for win-x64, win-arm64, osx-arm64, linux-x64, linux-arm64 - Minimum SDK bumped to 10.0.201 (required for Serialization Generator 2.14.3 / Roslyn 5.3.0) **Other Changes** - Solution converted from `.sln` to `.slnx` - Updated README with interactive mode instructions and deployment guidance ## Screenshots <img width="320" height="378" alt="image" src="https://github.com/user-attachments/assets/83c057c5-3992-4dbd-99fa-0e3c24ef6428" /> <img width="749" height="554" alt="image" src="https://github.com/user-attachments/assets/e4ee4d6f-71d4-47f9-86b6-8fd1ca3c3e7a" />
173 lines
4.4 KiB
C#
173 lines
4.4 KiB
C#
using System.Text;
|
|
using BuildTool;
|
|
using BuildTool.Interactive;
|
|
using BuildTool.Platform;
|
|
using BuildTool.Prerequisites;
|
|
using BuildTool.Publishing;
|
|
|
|
Console.OutputEncoding = Encoding.UTF8;
|
|
|
|
var repoRoot = FindRepoRoot();
|
|
if (repoRoot is null)
|
|
{
|
|
Console.Error.WriteLine("Error: Could not find ModernUO.slnx. Run this tool from the repository root.");
|
|
return 1;
|
|
}
|
|
|
|
var options = ParseArguments(args);
|
|
|
|
// Interactive mode: no args provided
|
|
if (options.Interactive)
|
|
{
|
|
// Handle Ctrl+C by signaling our cancellation token (not killing the process)
|
|
Console.CancelKeyPress += (_, e) =>
|
|
{
|
|
e.Cancel = true;
|
|
InteractiveCancellation.Instance.Cancel();
|
|
};
|
|
|
|
var platform = PlatformDetector.Detect();
|
|
return GuidedMode.Run(platform, repoRoot);
|
|
}
|
|
|
|
// Non-interactive mode
|
|
var detectedPlatform = PlatformDetector.Detect();
|
|
options.Os ??= detectedPlatform.OsRid;
|
|
options.Arch ??= detectedPlatform.ArchRid;
|
|
var rid = $"{options.Os}-{options.Arch}";
|
|
|
|
// Run prerequisite checks unless skipped
|
|
if (!options.SkipPrereqs)
|
|
{
|
|
var sdkResult = DotNetSdkManager.CheckSdk(repoRoot);
|
|
if (!sdkResult.Passed)
|
|
{
|
|
Console.Error.WriteLine($"Error: {sdkResult.Details}");
|
|
if (sdkResult.DownloadUrl is not null)
|
|
{
|
|
Console.Error.WriteLine($"Download: {sdkResult.DownloadUrl}");
|
|
}
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return options.Action switch
|
|
{
|
|
BuildAction.Publish => PublishOrchestrator.Run(options.Config, rid, interactive: false),
|
|
BuildAction.Migrate => SchemaMigrator.Run(interactive: false),
|
|
_ => 1
|
|
};
|
|
|
|
static BuildOptions ParseArguments(string[] args)
|
|
{
|
|
var options = new BuildOptions();
|
|
|
|
if (args.Length == 0)
|
|
{
|
|
options.Interactive = true;
|
|
return options;
|
|
}
|
|
|
|
// Check for named arguments first
|
|
var hasNamedArgs = false;
|
|
for (var i = 0; i < args.Length; i++)
|
|
{
|
|
switch (args[i])
|
|
{
|
|
case "--config" when i + 1 < args.Length:
|
|
{
|
|
options.Config = NormalizeConfig(args[++i]);
|
|
hasNamedArgs = true;
|
|
break;
|
|
}
|
|
case "--os" when i + 1 < args.Length:
|
|
{
|
|
options.Os = args[++i].ToLowerInvariant();
|
|
hasNamedArgs = true;
|
|
break;
|
|
}
|
|
case "--arch" when i + 1 < args.Length:
|
|
{
|
|
options.Arch = args[++i].ToLowerInvariant();
|
|
hasNamedArgs = true;
|
|
break;
|
|
}
|
|
case "--action" when i + 1 < args.Length:
|
|
{
|
|
options.Action = args[++i].ToLowerInvariant() switch
|
|
{
|
|
"migrate" => BuildAction.Migrate,
|
|
_ => BuildAction.Publish
|
|
};
|
|
hasNamedArgs = true;
|
|
break;
|
|
}
|
|
case "--skip-prereqs":
|
|
{
|
|
options.SkipPrereqs = true;
|
|
hasNamedArgs = true;
|
|
break;
|
|
}
|
|
case "--interactive":
|
|
{
|
|
options.Interactive = true;
|
|
hasNamedArgs = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (hasNamedArgs)
|
|
{
|
|
return options;
|
|
}
|
|
|
|
// Positional argument parsing (backward compat: [config] [os] [arch])
|
|
if (args.Length >= 1)
|
|
{
|
|
options.Config = NormalizeConfig(args[0]);
|
|
}
|
|
|
|
if (args.Length >= 2)
|
|
{
|
|
options.Os = args[1].ToLowerInvariant();
|
|
}
|
|
|
|
if (args.Length >= 3)
|
|
{
|
|
options.Arch = args[2].ToLowerInvariant();
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
static string NormalizeConfig(string config) =>
|
|
config.ToLowerInvariant() switch
|
|
{
|
|
"release" => "Release",
|
|
"debug" => "Debug",
|
|
_ => char.ToUpperInvariant(config[0]) + config[1..].ToLowerInvariant()
|
|
};
|
|
|
|
static string? FindRepoRoot()
|
|
{
|
|
// Check current directory first
|
|
var current = Directory.GetCurrentDirectory();
|
|
if (File.Exists(Path.Combine(current, "ModernUO.slnx")))
|
|
{
|
|
return current;
|
|
}
|
|
|
|
// Walk up to find the solution file
|
|
var dir = new DirectoryInfo(current);
|
|
while (dir?.Parent is not null)
|
|
{
|
|
dir = dir.Parent;
|
|
if (File.Exists(Path.Combine(dir.FullName, "ModernUO.slnx")))
|
|
{
|
|
return dir.FullName;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|