From a9d2bd38f70d1f09dd3ffaa125c24b3d2c3632ae Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sun, 31 Dec 2023 14:23:15 -0500 Subject: [PATCH] build(git): add pre-commit to selective format, typecheck --- script/bootstrap | 4 ++++ script/pre-commit | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 script/pre-commit diff --git a/script/bootstrap b/script/bootstrap index a3b3a8c..b77c76e 100644 --- a/script/bootstrap +++ b/script/bootstrap @@ -15,4 +15,8 @@ if [[ -z $BIN_MATCH ]]; then export PATH=$PATH:$BIN_PATH fi +echo "Adding pre-commit hook" +cp ./script/pre-commit ./.git/hooks +chmod +x ./.git/hooks/pre-commit + echo "All done!" diff --git a/script/pre-commit b/script/pre-commit new file mode 100755 index 0000000..0668570 --- /dev/null +++ b/script/pre-commit @@ -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