mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-30 02:00:10 +02:00
add package.json & prettier to commit flow!
This commit is contained in:
23
git-hooks/pre-commit
Executable file
23
git-hooks/pre-commit
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
# RUN PRETTIER
|
||||
jsjsonfiles=$(git diff --staged --name-only | grep ".*\.\(js\|json\)")
|
||||
echo "$jsjsonfiles" | xargs ./node_modules/.bin/prettier --single-quote --use-tabs --write
|
||||
echo "$jsjsonfiles" | xargs git add
|
||||
|
||||
# Fetch .js or .json filed from staged files
|
||||
jsfiles=$(git diff --staged --name-only --diff-filter=ACM | grep '\.js$')
|
||||
|
||||
[ -z "$jsfiles" ] && exit 0
|
||||
|
||||
# ESLINT CHECK
|
||||
eslintresult=$(./node_modules/.bin/eslint --color $jsfiles)
|
||||
|
||||
if [[ $eslintresult != "" ]]; then
|
||||
echo "$eslintresult"
|
||||
exit 1 # reject
|
||||
fi
|
||||
|
||||
echo "\033[32m✔ ESlint passed\033[0m"
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user