forked from klemiwary/Riakuto-StartingReact-ja4.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-staged-each.sh
executable file
·37 lines (31 loc) · 930 Bytes
/
lint-staged-each.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
# lint-staged-each.sh
# execute each lint-staged entry in sub-directories projects recursively
#
# Riakuto! Project by Klemiwary Books
fileTypes="js|jsx|ts|tsx|html|json|css|sass|scss|less|gql|graphql"
target="src|public"
# detect git against tag
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# detect staged projects
stagedProjects=$( \
git diff --cached --name-only --diff-filter=AM $against | \
grep -E ".*($target)\/" | \
grep -E "^.*\/.*\.($fileTypes)$" | \
grep -vE "(package|tsconfig).*\.json" | \
sed -r "s/($target)\/.*$//g" | \
uniq \
)
# execute each lint-staged
rootDir=$(pwd | sed -r "s/\/\.git\/hooks//")
for project in ${stagedProjects[@]}; do
echo "Executing $project lint-staged entry..."
cd "$rootDir/$project"
npx lint-staged 2>/dev/null
done