diff --git a/extension/asset_platform.go b/extension/asset_platform.go index ceadf444..eca2997f 100644 --- a/extension/asset_platform.go +++ b/extension/asset_platform.go @@ -366,7 +366,7 @@ func createConfigFromPath(entryPointName string, extensionRoot string) Extension Views: []string{ "Resources/views", }, - TechnicalName: strings.ReplaceAll(ToSnakeCase(entryPointName), "_", "-"), + TechnicalName: esbuild.ToKebabCase(entryPointName), Administration: ExtensionAssetConfigAdmin{ Path: "Resources/app/administration/src", EntryFilePath: entryFilePathAdmin, diff --git a/extension/util.go b/extension/util.go index fe6216a2..4a1763cc 100644 --- a/extension/util.go +++ b/extension/util.go @@ -3,21 +3,9 @@ package extension import ( "os" "path/filepath" - "regexp" "strings" ) -var ( - matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)") - matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])") -) - -func ToSnakeCase(str string) string { - snake := matchFirstCap.ReplaceAllString(str, "${1}_${2}") - snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}") - return strings.ToLower(snake) -} - func PlatformPath(projectRoot, component, path string) string { if _, err := os.Stat(filepath.Join(projectRoot, "src", "Core", "composer.json")); err == nil { return filepath.Join(projectRoot, "src", component, path) diff --git a/internal/esbuild/esbuild.go b/internal/esbuild/esbuild.go index 3a34b81f..7efdcc6e 100644 --- a/internal/esbuild/esbuild.go +++ b/internal/esbuild/esbuild.go @@ -93,7 +93,7 @@ func Context(ctx context.Context, options AssetCompileOptions) (api.BuildContext } func CompileExtensionAsset(ctx context.Context, options AssetCompileOptions) (*AssetCompileResult, error) { - technicalName := strings.ReplaceAll(toSnakeCase(options.Name), "_", "-") + technicalName := ToKebabCase(options.Name) jsFile := filepath.Join(options.Path, options.OutputDir, "js", technicalName+".js") cssFile := filepath.Join(options.Path, options.OutputDir, "css", technicalName+".css") diff --git a/internal/esbuild/util.go b/internal/esbuild/util.go index ff0a489b..b9d4ef53 100644 --- a/internal/esbuild/util.go +++ b/internal/esbuild/util.go @@ -8,9 +8,9 @@ import ( var matchLetter = regexp.MustCompile(`[A-Z]`) // @see https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php#L31 -func toSnakeCase(str string) string { +func ToKebabCase(str string) string { converted := matchLetter.ReplaceAllStringFunc(str, func(match string) string { - return "_" + strings.ToLower(match) + return "-" + strings.ToLower(match) }) return converted[1:] } diff --git a/internal/esbuild/util_test.go b/internal/esbuild/util_test.go index afa439a6..39c1b6a8 100644 --- a/internal/esbuild/util_test.go +++ b/internal/esbuild/util_test.go @@ -6,8 +6,9 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSnakeCase(t *testing.T) { - assert.Equal(t, "foo_bar", toSnakeCase("FooBar")) - assert.Equal(t, "frosh_tools", toSnakeCase("FroshTools")) - assert.Equal(t, "my_module_name_s_w6", toSnakeCase("MyModuleNameSW6")) +func TestKebabCase(t *testing.T) { + assert.Equal(t, "foo-bar", ToKebabCase("FooBar")) + assert.Equal(t, "f-o-o-bar-baz", ToKebabCase("FOOBarBaz")) + assert.Equal(t, "frosh-tools", ToKebabCase("FroshTools")) + assert.Equal(t, "my-module-name-s-w6", ToKebabCase("MyModuleNameSW6")) }