-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add git-hook on working-dir change, run yalc:publish
- Loading branch information
Showing
7 changed files
with
178 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# Catch cases where the work dir changed after a git command. | ||
# In that cases, run ./scripts/on-workdir-changed.sh | ||
|
||
|
||
function in_rebase { | ||
git_dir=$(git rev-parse --git-dir) | ||
# Check if git_dir/rebase-merge or /rebase_apply exist. | ||
# Then return the result | ||
return $([ -d "$git_dir/rebase-merge" ] || [ -d "$git_dir/rebase-apply" ]) | ||
} | ||
|
||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
cd "$ROOT_DIR" | ||
|
||
# If in rebase, this hook is called multiple times. | ||
# Skip here and wait for post-rewrite to have been called. | ||
if in_rebase; then | ||
exit 0 | ||
fi | ||
|
||
|
||
# Get first argument. If it is 1, this indicates, working dir files have changed. | ||
if [ "$1" = 1 ] ; then | ||
./scripts/on-workdir-changed.sh | ||
fi | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
# Catch cases where the work dir changed after a git rebase. | ||
# In that cases, run ./scripts/on-workdir-changed.sh | ||
|
||
|
||
# If coming from a rewrite-rebase ($1 == rebase), run on-workdir-changed. | ||
if [ "$1" = "rebase" ] ; then | ||
# cd to root directory | ||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
cd "$ROOT_DIR" | ||
|
||
./scripts/on-workdir-changed.sh | ||
fi |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
# This script is called when a git command possibly modified files in the working dir. | ||
|
||
|
||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
cd "$ROOT_DIR" | ||
|
||
./scripts/run-yalc-publish.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
# Script to run linter before commit. | ||
# This is called by `.git-hooks/pre-commit` | ||
|
||
|
||
echo "======================" | ||
echo "=== Running linter ===" | ||
echo "======================" | ||
|
||
cd $(git rev-parse --show-toplevel) | ||
|
||
FILES="$@" | ||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
|
||
MIDDLEWARE_FILES="$(echo "$FILES" | grep -E "src/middleware" | xargs -r realpath | sed 's/.*/"&"/')" | ||
FRONTEND_FILES="$(echo "$FILES" | grep -E "src/frontend" | xargs -r realpath | sed 's/.*/"&"/')" | ||
|
||
LINT_FILE_TYPES="js|jsx|ts|tsx" | ||
LINT_MIDDLEWARE_FILES=$(echo "$MIDDLEWARE_FILES" | grep -E "\.($LINT_FILE_TYPES)$") | ||
LINT_FRONTEND_FILES=$(echo "$FRONTEND_FILES" | grep -E "\.($LINT_FILE_TYPES)$") | ||
|
||
# Function to evaluate the linter results | ||
function evaluate_linter_results { | ||
if [ $? == 1 ]; then | ||
echo "=================================================================" | ||
echo "The linter found some errors. Please fix them before committing." | ||
echo "You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS" | ||
echo "=================================================================" | ||
exit 1 | ||
elif [ $? -ge 2 ]; then | ||
echo "===============================================================================" | ||
echo "Something went wrong running the linter. Have you bootstrapped the project yet?" | ||
echo "You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS" | ||
echo "===============================================================================" | ||
exit 1 | ||
fi | ||
} | ||
|
||
|
||
# Run linter on middleware and frontend files | ||
|
||
cd "$ROOT_DIR"/src/middleware | ||
yarn run lint-files $LINT_MIDDLEWARE_FILES | ||
evaluate_linter_results | ||
|
||
cd "$ROOT_DIR"/src/frontend | ||
yarn run lint-files $LINT_FRONTEND_FILES | ||
evaluate_linter_results | ||
|
||
|
||
echo "==== Linter done =====" | ||
|
||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# Script to run prettier on staged files before commit. | ||
# This is called by `.git-hooks/pre-commit` | ||
|
||
|
||
echo "========================" | ||
echo "=== Running prettier ===" | ||
echo "========================" | ||
|
||
FILES="$@" | ||
|
||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
|
||
MIDDLEWARE_FILES="$(echo "$FILES" | grep -E "src/middleware" | xargs -r realpath | sed 's/.*/"&"/')" | ||
FRONTEND_FILES="$(echo "$FILES" | grep -E "src/frontend" | xargs -r realpath | sed 's/.*/"&"/')" | ||
|
||
|
||
# Run prettier on all given files. | ||
cd "$ROOT_DIR"/src/middleware | ||
echo "$MIDDLEWARE_FILES" | xargs npx prettier --write --ignore-unknown | ||
cd "$ROOT_DIR"/src/frontend | ||
echo "$FRONTEND_FILES" | xargs npx prettier --write --ignore-unknown | ||
cd "$ROOT_DIR" | ||
|
||
if [ $? != 0 ]; then | ||
echo "========================================================================" | ||
echo "Something went wrong running prettier. Have you run \`npm install\` yet?" | ||
echo "You can skip pre-commit checks by setting \$SKIP_PRECOMMIT_CHECKS" | ||
echo "========================================================================" | ||
exit 1 | ||
fi | ||
|
||
echo "==== Prettier done =====" | ||
|
||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# Script to run yalc:publish. | ||
# Called by on-workdir-changed.sh | ||
|
||
|
||
echo == Running yalc:publish. | ||
|
||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
cd "$ROOT_DIR"/src/frontend | ||
|
||
# Run yalc:publish. If not available, just print an info message. | ||
yarn yalc:publish &> /dev/null || \ | ||
echo "==== yarn or yalc is not installed. Skipping yalc:publish" | ||
|
||
exit 0 |