diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3ca1db5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.{cs,vb}] +dotnet_diagnostic.CA1515.severity = none \ No newline at end of file diff --git a/.github/workflows/update-material-symbols.yml b/.github/workflows/update-material-symbols.yml index 6e1390d..256de1c 100644 --- a/.github/workflows/update-material-symbols.yml +++ b/.github/workflows/update-material-symbols.yml @@ -31,7 +31,7 @@ jobs: - name: Restore generator run: dotnet restore src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj - name: Generate Material Symbols - run: dotnet run --project src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj --configuration Release --no-restore -- materialsymbols + run: dotnet run --project src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj --configuration Release --no-restore -- --icon-type MaterialSymbols - name: Check Material Symbols font changes id: changes run: | diff --git a/src/GoogleMaterialDesignIconsGenerator/GenerateCommand.cs b/src/GoogleMaterialDesignIconsGenerator/GenerateCommand.cs new file mode 100644 index 0000000..8367fff --- /dev/null +++ b/src/GoogleMaterialDesignIconsGenerator/GenerateCommand.cs @@ -0,0 +1,47 @@ +using GoogleMaterialDesignIconsGenerator.Extensions; +using GoogleMaterialDesignIconsGenerator.Model; +using GoogleMaterialDesignIconsGenerator.Service; +using Spectre.Console; +using Spectre.Console.Cli; + +namespace GoogleMaterialDesignIconsGenerator; + +public sealed class GenerateCommand : AsyncCommand +{ + public override async Task ExecuteAsync(CommandContext context, GenerateCommandSettings settings, CancellationToken cancellationToken) + { + ArgumentNullException.ThrowIfNull(settings); + var iconType = ResolveIconType(settings); + + var codeGenerator = new CodeGenerationService(); + using var client = new IconHttpClientService(); + var metadata = await client.ParseIconsAsync().ConfigureAwait(false); + var filteredIcons = Utility.IconFilter.FilterByFamily(metadata, iconType); + var groupedIcons = Utility.IconFilter.GroupIconsByFamilies(filteredIcons, iconType); + var outputFolder = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, $"../../../../MudBlazor.FontIcons.{iconType.GetDescription()}")); + + codeGenerator.GenerateCsFilesUsingRoslyn(iconType, groupedIcons, folder: outputFolder); + + if (iconType == IconType.MaterialSymbols) + { + await client.DownloadMaterialSymbolsFontsAsync(Path.Combine(outputFolder, "wwwroot", "font"), cancellationToken).ConfigureAwait(false); + } + + return 0; + } + + private static IconType ResolveIconType(GenerateCommandSettings settings) + { + if (settings.IconType is { } iconTypeFromOption) + { + return iconTypeFromOption; + } + + return AnsiConsole.Prompt( + new SelectionPrompt() + .Title("What [green]icon[/] pack to generate?") + .PageSize(10) + .MoreChoicesText("[grey](Move up and down to reveal more options)[/]") + .AddChoices(IconType.MaterialIcons, IconType.MaterialSymbols)); + } +} diff --git a/src/GoogleMaterialDesignIconsGenerator/GenerateCommandSettings.cs b/src/GoogleMaterialDesignIconsGenerator/GenerateCommandSettings.cs new file mode 100644 index 0000000..c391cb1 --- /dev/null +++ b/src/GoogleMaterialDesignIconsGenerator/GenerateCommandSettings.cs @@ -0,0 +1,10 @@ +using Spectre.Console.Cli; +using GoogleMaterialDesignIconsGenerator.Model; + +namespace GoogleMaterialDesignIconsGenerator; + +public sealed class GenerateCommandSettings : CommandSettings +{ + [CommandOption("-t|--icon-type ")] + public IconType? IconType { get; init; } +} diff --git a/src/GoogleMaterialDesignIconsGenerator/Generator/IGenerator.cs b/src/GoogleMaterialDesignIconsGenerator/Generator/IGenerator.cs index 3dfd5b5..ab48d90 100644 --- a/src/GoogleMaterialDesignIconsGenerator/Generator/IGenerator.cs +++ b/src/GoogleMaterialDesignIconsGenerator/Generator/IGenerator.cs @@ -5,7 +5,7 @@ namespace GoogleMaterialDesignIconsGenerator.Generator; public interface IGenerator { - public string RootNamespace { get; } + string RootNamespace { get; } CompilationUnitSyntax GetCompilationUnitSyntax(KeyValuePair> group, string className, string familyPath); } \ No newline at end of file diff --git a/src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj b/src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj index 044e1e0..e5b34c0 100644 --- a/src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj +++ b/src/GoogleMaterialDesignIconsGenerator/GoogleMaterialDesignIconsGenerator.csproj @@ -16,7 +16,8 @@ - + + diff --git a/src/GoogleMaterialDesignIconsGenerator/Model/Google/Icon.cs b/src/GoogleMaterialDesignIconsGenerator/Model/Google/Icon.cs index 8a98951..1f683c8 100644 --- a/src/GoogleMaterialDesignIconsGenerator/Model/Google/Icon.cs +++ b/src/GoogleMaterialDesignIconsGenerator/Model/Google/Icon.cs @@ -1,5 +1,4 @@ -using System.Collections.ObjectModel; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace GoogleMaterialDesignIconsGenerator.Model.Google; diff --git a/src/GoogleMaterialDesignIconsGenerator/Model/Google/IconsMetadata.cs b/src/GoogleMaterialDesignIconsGenerator/Model/Google/IconsMetadata.cs index b6dfa86..d62a557 100644 --- a/src/GoogleMaterialDesignIconsGenerator/Model/Google/IconsMetadata.cs +++ b/src/GoogleMaterialDesignIconsGenerator/Model/Google/IconsMetadata.cs @@ -1,5 +1,4 @@ -using System.Collections.ObjectModel; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace GoogleMaterialDesignIconsGenerator.Model.Google; diff --git a/src/GoogleMaterialDesignIconsGenerator/Program.cs b/src/GoogleMaterialDesignIconsGenerator/Program.cs index f9d16ed..84f30a3 100644 --- a/src/GoogleMaterialDesignIconsGenerator/Program.cs +++ b/src/GoogleMaterialDesignIconsGenerator/Program.cs @@ -1,97 +1,17 @@ -using GoogleMaterialDesignIconsGenerator.Extensions; -using GoogleMaterialDesignIconsGenerator.Model; -using GoogleMaterialDesignIconsGenerator.Service; -using Spectre.Console; +using Spectre.Console.Cli; namespace GoogleMaterialDesignIconsGenerator; public static class Program { - public static async Task Main(string[] args) + public static Task Main(string[] args) { - var iconType = ResolveIconType(args); - - var codeGenerator = new CodeGenerationService(); - using var client = new IconHttpClientService(); - var metadata = await client.ParseIconsAsync().ConfigureAwait(false); - var filteredIcons = Utility.IconFilter.FilterByFamily(metadata, iconType); - var groupedIcons = Utility.IconFilter.GroupIconsByFamilies(filteredIcons, iconType); - var outputFolder = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, $"../../../../MudBlazor.FontIcons.{iconType.GetDescription()}")); - - codeGenerator.GenerateCsFilesUsingRoslyn(iconType, groupedIcons, folder: outputFolder); - - if (iconType == IconType.MaterialSymbols) - { - await client.DownloadMaterialSymbolsFontsAsync(Path.Combine(outputFolder, "wwwroot", "font")).ConfigureAwait(false); - } - } - - private static IconType ResolveIconType(IReadOnlyList args) - { - if (TryGetIconTypeFromArgs(args, out var iconType)) - { - return iconType; - } - - return AnsiConsole.Prompt( - new SelectionPrompt() - .Title("What [green]icon[/] pack to generate?") - .PageSize(10) - .MoreChoicesText("[grey](Move up and down to reveal more options)[/]") - .AddChoices([ - IconType.MaterialIcons, - IconType.MaterialSymbols - ])); - } - - private static bool TryGetIconTypeFromArgs(IReadOnlyList args, out IconType iconType) - { - iconType = default; - if (args.Count == 0) - { - return false; - } - - for (var i = 0; i < args.Count; i++) - { - if (!args[i].Equals("--icon-type", StringComparison.OrdinalIgnoreCase) && - !args[i].Equals("-t", StringComparison.OrdinalIgnoreCase)) - { - continue; - } - - if (i + 1 >= args.Count) - { - throw new ArgumentException("Missing value for --icon-type."); - } - - iconType = ParseIconType(args[i + 1]); - return true; - } - - iconType = ParseIconType(args[0]); - return true; - } - - private static IconType ParseIconType(string value) - { - var normalized = value - .Replace("-", string.Empty, StringComparison.Ordinal) - .Replace("_", string.Empty, StringComparison.Ordinal) - .Trim(); - - if (normalized.Equals("materialsymbols", StringComparison.OrdinalIgnoreCase) || - normalized.Equals("symbols", StringComparison.OrdinalIgnoreCase)) - { - return IconType.MaterialSymbols; - } - - if (normalized.Equals("materialicons", StringComparison.OrdinalIgnoreCase) || - normalized.Equals("icons", StringComparison.OrdinalIgnoreCase)) + var app = new CommandApp(); + app.Configure(config => { - return IconType.MaterialIcons; - } + config.SetApplicationName("GoogleMaterialDesignIconsGenerator"); + }); - throw new ArgumentException($"Unsupported icon type '{value}'. Use 'materialsymbols' or 'materialicons'."); + return app.RunAsync(args); } } diff --git a/src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs b/src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs index 95230e5..e35f373 100644 --- a/src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs +++ b/src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs @@ -26,5 +26,4 @@ public void GenerateCsFilesUsingRoslyn(IconType iconType, Dictionary