From c2403c15ab25d2a05338df4b6893493215f93c33 Mon Sep 17 00:00:00 2001 From: zhaowenkai <799480165@qq.com> Date: Tue, 24 Dec 2024 18:54:04 +0800 Subject: [PATCH] Fixed default method name conflicts --- .../CssInCSharp.CommandLine/Configuration.cs | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/generators/CssInCSharp.CommandLine/Configuration.cs b/generators/CssInCSharp.CommandLine/Configuration.cs index eb60264..396b9c1 100644 --- a/generators/CssInCSharp.CommandLine/Configuration.cs +++ b/generators/CssInCSharp.CommandLine/Configuration.cs @@ -1,7 +1,6 @@ using System.Text.Json; using System.Text.RegularExpressions; using CssInCSharp.Generator; -using CssInCSharp.Generator.Extensions; namespace CssInCSharp.CommandLine { @@ -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; @@ -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; } } }