build(git): add pre-commit to selective format, typecheck

This commit is contained in:
Marc 2023-12-31 14:23:15 -05:00
parent 36500ab588
commit a9d2bd38f7
Signed by: marc
GPG key ID: 048E042F22B5DC79
2 changed files with 20 additions and 0 deletions

View file

@ -15,4 +15,8 @@ if [[ -z $BIN_MATCH ]]; then
export PATH=$PATH:$BIN_PATH export PATH=$PATH:$BIN_PATH
fi fi
echo "Adding pre-commit hook"
cp ./script/pre-commit ./.git/hooks
chmod +x ./.git/hooks/pre-commit
echo "All done!" echo "All done!"

16
script/pre-commit Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
TASKS=""
if [ -n "$(git diff --cached --name-only origin/main -- ./frontend)" ]; then
TASKS="$TASKS fe:lint fe:typecheck"
fi
if [ -n "$(git diff --cached --name-only origin/main -- ./backend)" ]; then
TASKS="$TASKS be:lint"
fi
if [ -n "$TASKS" ]; then
echo "Running $TASKS"
task $TASKS
fi