Last active
March 31, 2021 01:23
-
-
Save oukayuka/bd8b2ac927afb9b3be26c1fefea885b5 to your computer and use it in GitHub Desktop.
Execute each lint-staged entry in sub-directories projects recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# lint-staged-around | |
# execute each lint-staged entry in sub-directories projects recursively | |
# | |
# Riakuto! Project by Klemiwary Books | |
fileTypes="js|jsx|ts|tsx|html|css|less|sass|scss|gql|graphql|json" | |
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 | |
# pick 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Introducing Steps
For example, file structure like this...
1. Put this script file on Git repository root
2. Install simple-git-hooks in each project
3. Edit package.json
4. Overwrite Git hooks