From 2ce68cdca697132261b712f2c571747af841a297 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 13 Apr 2025 11:56:02 +0200 Subject: [PATCH] Added UpdateWebAssetsCommand --- app/Build/Commands/UpdateWebAssetsCommand.cs | 42 ++++++++++++++++++++ app/Build/Program.cs | 1 + 2 files changed, 43 insertions(+) create mode 100644 app/Build/Commands/UpdateWebAssetsCommand.cs diff --git a/app/Build/Commands/UpdateWebAssetsCommand.cs b/app/Build/Commands/UpdateWebAssetsCommand.cs new file mode 100644 index 00000000..a40e3ee1 --- /dev/null +++ b/app/Build/Commands/UpdateWebAssetsCommand.cs @@ -0,0 +1,42 @@ +// ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable UnusedType.Global +// ReSharper disable UnusedMember.Global + +namespace Build.Commands; + +public sealed class UpdateWebAssetsCommand +{ + [Command("update-web", Description = "Update web assets")] + public void UpdateWebAssets() + { + if(!Environment.IsWorkingDirectoryValid()) + return; + + var rid = Environment.GetRidsForCurrentOS().First(); + var cwd = Environment.GetAIStudioDirectory(); + var contentPath = Path.Join(cwd, "bin", "release", "net9.0", rid, "publish", "wwwroot", "_content"); + var isMudBlazorDirectoryPresent = Directory.Exists(Path.Join(contentPath, "MudBlazor")); + if (!isMudBlazorDirectoryPresent) + { + Console.WriteLine($"No web assets found for RID '{rid}'. Please publish the project first."); + return; + } + + Directory.CreateDirectory(Path.Join(cwd, "wwwroot", "system")); + var sourcePaths = Directory.EnumerateFiles(contentPath, "*", SearchOption.AllDirectories); + var counter = 0; + foreach(var sourcePath in sourcePaths) + { + counter++; + var relativePath = Path.GetRelativePath(cwd, sourcePath); + var targetPath = Path.Join(cwd, "wwwroot", relativePath); + var targetDirectory = Path.GetDirectoryName(targetPath); + if (targetDirectory != null) + Directory.CreateDirectory(targetDirectory); + + File.Copy(sourcePath, targetPath, true); + } + + Console.WriteLine($"{counter:###,###} web assets updated successfully."); + } +} \ No newline at end of file diff --git a/app/Build/Program.cs b/app/Build/Program.cs index 4e974cb1..04d524be 100644 --- a/app/Build/Program.cs +++ b/app/Build/Program.cs @@ -4,4 +4,5 @@ var builder = CoconaApp.CreateBuilder(); var app = builder.Build(); app.AddCommands(); app.AddCommands(); +app.AddCommands(); app.Run(); \ No newline at end of file