diff --git a/.husky/pre-commit b/.husky/pre-commit index be2b0e1d256..28467241bd1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,32 +1,28 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ensure_types_are_up_to_date() { types_path="packages/calcite-components/src/components.d.ts" if [ -n "$(git diff --name-only -- "$types_path")" ]; then echo "Automatically staging changes to \"$types_path\"" - git add "$types_path" + git add "$types_path" >/dev/null 2>&1 || true fi } update_stylelint_config_if_sass_file_edited() { - staged_files="$(git diff --cached --name-only --diff-filter=ACM)" + staged_files="$( + git diff --cached --name-only --diff-filter=ACM -- packages/**/*.scss + )" - for file in $staged_files; do - if [[ "$file" == *.scss ]]; then - npm run util:update-stylelint-custom-sass-functions - break - fi - done - - if [ -n "$(git diff --name-only -- "packages/calcite-components/.stylelintrc.json")" ]; then - git add "packages/calcite-components/.stylelintrc.json" + if [ -n "$staged_files" ]; then + npm run util:update-stylelint-custom-sass-functions + git add "packages/calcite-components/.stylelintrc.cjs" >/dev/null 2>&1 || true fi + + unset staged_files } check_ui_icon_name_consistency() { - svg_icon_dir="packages/calcite-ui-icons/icons" - # this pattern checks for `-.svg` or `--f.svg` for filled icons # where `` is kebab-case, `` is 16, 24, or 32 valid_pattern="^[a-z0-9-]+-(16|24|32)(-f)?\\.svg$" @@ -34,27 +30,33 @@ check_ui_icon_name_consistency() { # this pattern will check for invalid use of "-f-" anywhere except right before the size invalid_pattern="-[a-z0-9]+-f-" - staged_files="$(git diff --cached --name-only --diff-filter=ACM)" + staged_files="$( + git diff --cached --name-only --diff-filter=ACM -- packages/calcite-ui-icons/icons/*.svg + )" - for file in $staged_files; do - if [[ "$file" == "$svg_icon_dir"* ]]; then - if [[ "$file" == *.svg ]]; then - filename="$(basename "$file")" + if [ -n "$staged_files" ]; then + for file in $staged_files; do + filename="$(basename "$file")" - # first, ensure the filename follows the valid pattern - if ! [[ "$filename" =~ $valid_pattern ]]; then - echo "Error: File '$file' does not follow the naming convention (-.svg or --f.svg)." - exit 1 - fi + # first, ensure the filename follows the valid pattern + if ! echo "$filename" | grep -qE "$valid_pattern"; then + printf "%s\n%s" \ + "error: file '$file' does not follow the naming convention:" \ + "(-.svg | --f.svg)" + exit 1 + fi - # then, ensure there's no invalid use of "-f-" anywhere except right before the size - if [[ "$filename" =~ $invalid_pattern ]]; then - echo "Error: File '$file' has an invalid '-f-' and does not follow the naming convention (-.svg or --f.svg)." - exit 1 - fi + # then, ensure there's no invalid use of "-f-" anywhere except right before the size + if echo "$filename" | grep -qE "$invalid_pattern"; then + printf '%s\n%s' \ + "error: file '$file' has an invalid '-f-' and does not follow the naming convention:" \ + "(-.svg | --f.svg)" + exit 1 fi - fi - done + done + fi + + unset staged_files } lint-staged diff --git a/.husky/pre-push b/.husky/pre-push index 22e73a356d9..c8ce7f89399 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,14 +1,20 @@ -#!/usr/bin/env bash -# from https://riptutorial.com/git/example/16164/pre-push - -protected_branch="main" -current_branch=$(git rev-parse --abbrev-ref HEAD) - -if [ "$protected_branch" = "$current_branch" ] && bash -c ': >/dev/tty'; then - read -p "You're about to push main, is that what you intended? [y|n] " -n 1 -r /dev/null; then - exit 0 - fi - exit 1 +#!/usr/bin/env sh + +if ! bash -c ': >/dev/tty'; then + exit 0 fi + +current_branch="$(git rev-parse --abbrev-ref HEAD)" + +case "$current_branch" in + dev | main | rc) + printf "You're about to push a protected branch, is that what you intended? [y|n] " + read -r response + + case "$response" in + y | Y) exit 0 ;; + *) exit 1 ;; + esac + ;; + *) exit 0 ;; +esac diff --git a/support/updateStylelintCustomSassFunctions.ts b/support/updateStylelintCustomSassFunctions.ts index bd4b1cef104..c5333ba82a0 100644 --- a/support/updateStylelintCustomSassFunctions.ts +++ b/support/updateStylelintCustomSassFunctions.ts @@ -15,7 +15,7 @@ function collectSassFiles(dir: string): string[] { try { fs.readdirSync(dir, { recursive: true, withFileTypes: true }).forEach(dirent => { - const fullPath = path.join(dir, dirent.name); + const fullPath = path.join(dirent.parentPath, dirent.name); if (dirent.isFile() && fullPath.endsWith('.scss')) { sassFiles.push(fullPath);