Skip to content

Commit

Permalink
Fixed default method name conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
yoli799480165 committed Dec 24, 2024
1 parent e604789 commit c2403c1
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions generators/CssInCSharp.CommandLine/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json;
using System.Text.RegularExpressions;
using CssInCSharp.Generator;
using CssInCSharp.Generator.Extensions;

namespace CssInCSharp.CommandLine
{
Expand Down Expand Up @@ -36,11 +35,37 @@ internal class IncludeItem

public IncludeItem Update()
{
if (CsOptions is not { DefaultClassName: not null }) return this;
var match = Regex.Match(CsOptions.DefaultClassName, @"(\{(dir|file):?(\S*)\})\w*");
if (!match.Success) return this;
if (match.Groups.Count < 3) return this;
if (Dest == null) return this;
UpdateDefaultClassName();
UpdateDefaultExportMethodName();
return this;
}

private void UpdateDefaultClassName()
{
if (CsOptions is not { DefaultClassName: not null }) return;
var name = ParseName(CsOptions.DefaultClassName);
if (!string.IsNullOrEmpty(name))
{
CsOptions.DefaultClassName = Util.PurifyFileName(name);
}
}

private void UpdateDefaultExportMethodName()
{
if (CsOptions is not { DefaultExportMethodName: not null }) return;
var name = ParseName(CsOptions.DefaultExportMethodName);
if (!string.IsNullOrEmpty(name))
{
CsOptions.DefaultExportMethodName = Util.PurifyFileName(name);
}
}

private string? ParseName(string option)
{
var match = Regex.Match(option, @"(\{(dir|file):?(\S*)\})\w*");
if (!match.Success) return null;
if (match.Groups.Count < 3) return null;
if (Dest == null) return null;

var replace = match.Groups[1].Value;
var type = match.Groups[2].Value;
Expand All @@ -64,11 +89,9 @@ public IncludeItem Update()

if (!string.IsNullOrEmpty(name))
{
name = CsOptions.DefaultClassName.Replace(replace, name);
CsOptions.DefaultClassName = Util.PurifyFileName(name);
name = option.Replace(replace, name);
}

return this;
return name;
}
}
}

0 comments on commit c2403c1

Please sign in to comment.