diff --git a/.gitignore b/.gitignore index 2518e23..98e8478 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.vscode/** \ No newline at end of file +.vscode/** +my-repo* +test-* diff --git a/README.md b/README.md index 53480c0..d5a9bc4 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ echo "My Tool" | ./create-package Package names are automatically sanitized: - Converted to lowercase +- Any run of whitespace characters (spaces, tabs, etc.) is replaced with a single dash +- All other special characters are removed (only `[a-z0-9-]` are retained) - Spaces and underscores are replaced with dashes - Only `[a-z0-9-]` characters are retained (letters, numbers, dashes) - Multiple consecutive dashes are collapsed into one @@ -37,6 +39,11 @@ Package names are automatically sanitized: # Creates: my-tool/my-tool ./create-package "My Tool" +# Creates: my-repo/my-repo +./create-package "my repo" + +# Creates: my-repo2/my-repo2 +./create-package "my ^ repo2" # Creates: hello-world/hello-world echo "Hello_World" | ./create-package diff --git a/create-package b/create-package index 7788d98..8ae7281 100755 --- a/create-package +++ b/create-package @@ -37,12 +37,14 @@ fi # Sanitize the package name: # 1. Convert to lowercase +# 2. Replace any run of whitespace characters with a single dash # 2. Replace spaces and underscores with dashes # 3. Remove any characters that are not [a-z0-9-] # 4. Collapse multiple consecutive dashes into one # 5. Remove leading/trailing dashes sanitized=$(echo "$package_name" | \ tr '[:upper:]' '[:lower:]' | \ + sed 's/[[:space:]]\+/-/g' | \ tr ' _' '-' | \ sed 's/[^a-z0-9-]//g' | \ sed 's/-\+/-/g' | \