diff options
Diffstat (limited to 'scripts/frontend/execute-on-staged-files.sh')
-rwxr-xr-x | scripts/frontend/execute-on-staged-files.sh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/frontend/execute-on-staged-files.sh b/scripts/frontend/execute-on-staged-files.sh new file mode 100755 index 00000000000..f218926f098 --- /dev/null +++ b/scripts/frontend/execute-on-staged-files.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# The yarn run command we'd like to run +command="$1" +# The file types we'd like to target, use something like '(js|vue)' +file_types="$2" + +# Removing first two arguments +shift +shift + +# Read all staged non-deleted files into an array +staged_files=() +while IFS= read -r line; do + staged_files+=( "$line" ) +done < <( git diff --diff-filter=d --cached --name-only | { grep -E ".$file_types$" || true; }) + +if [ "${#staged_files[@]}" == "0" ]; then + echo "No staged '$file_types' files" +else + echo "Running $command on ${#staged_files[@]} staged '$file_types' files" + yarn run "$command" "$@" "${staged_files[@]}" +fi |