Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{cs,vb}]
dotnet_diagnostic.CA1515.severity = none
2 changes: 1 addition & 1 deletion .github/workflows/update-material-symbols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
47 changes: 47 additions & 0 deletions src/GoogleMaterialDesignIconsGenerator/GenerateCommand.cs
Original file line number Diff line number Diff line change
@@ -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<GenerateCommandSettings>
{
public override async Task<int> 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<IconType>()
.Title("What [green]icon[/] pack to generate?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more options)[/]")
.AddChoices(IconType.MaterialIcons, IconType.MaterialSymbols));
}
}
10 changes: 10 additions & 0 deletions src/GoogleMaterialDesignIconsGenerator/GenerateCommandSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Spectre.Console.Cli;
using GoogleMaterialDesignIconsGenerator.Model;

namespace GoogleMaterialDesignIconsGenerator;

public sealed class GenerateCommandSettings : CommandSettings
{
[CommandOption("-t|--icon-type <ICON_TYPE>")]
public IconType? IconType { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GoogleMaterialDesignIconsGenerator.Generator;

public interface IGenerator
{
public string RootNamespace { get; }
string RootNamespace { get; }

CompilationUnitSyntax GetCompilationUnitSyntax(KeyValuePair<string, IReadOnlyCollection<Icon>> group, string className, string familyPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0-3.final" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console" Version="0.54.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.53.1" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/GoogleMaterialDesignIconsGenerator/Model/Google/Icon.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace GoogleMaterialDesignIconsGenerator.Model.Google;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace GoogleMaterialDesignIconsGenerator.Model.Google;

Expand Down
94 changes: 7 additions & 87 deletions src/GoogleMaterialDesignIconsGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -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<int> 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<string> args)
{
if (TryGetIconTypeFromArgs(args, out var iconType))
{
return iconType;
}

return AnsiConsole.Prompt(
new SelectionPrompt<IconType>()
.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<string> 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<GenerateCommand>();
app.Configure(config =>
{
return IconType.MaterialIcons;
}
config.SetApplicationName("GoogleMaterialDesignIconsGenerator");
});

throw new ArgumentException($"Unsupported icon type '{value}'. Use 'materialsymbols' or 'materialicons'.");
return app.RunAsync(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class CodeGenerationService
{
public void GenerateCsFilesUsingRoslyn(IconType iconType, Dictionary<string, IReadOnlyCollection<Icon>> groupedIcons, string folder)

Check warning on line 10 in src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs

View workflow job for this annotation

GitHub Actions / build-pack

Member 'GenerateCsFilesUsingRoslyn' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 10 in src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs

View workflow job for this annotation

GitHub Actions / build-pack

Member 'GenerateCsFilesUsingRoslyn' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 10 in src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs

View workflow job for this annotation

GitHub Actions / Analyze C# (csharp, manual)

Member 'GenerateCsFilesUsingRoslyn' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 10 in src/GoogleMaterialDesignIconsGenerator/Service/CodeGenerationService.cs

View workflow job for this annotation

GitHub Actions / Analyze C# (csharp, manual)

Member 'GenerateCsFilesUsingRoslyn' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
ArgumentNullException.ThrowIfNull(groupedIcons);

Expand All @@ -26,5 +26,4 @@
File.WriteAllText(path, code);
}
}

}
Loading