Skip to content

Commit

Permalink
Add simple custom pre-commit script
Browse files Browse the repository at this point in the history
  • Loading branch information
p2004a committed Jun 9, 2024
1 parent b3ed70e commit 837a581
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "tsc",
"build:prod": "tsc -p tsconfig.prod.json",
"test": "tsc && node --enable-source-maps --test --test-timeout=2500",
"test:clean": "rm -rf dist/ && npm run test",
"coverage": "tsc && node --enable-source-maps --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
Expand Down
25 changes: 25 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# The whole stashing dance based on: http://stackoverflow.com/a/20480591/1435658

# First, stash index and work dir, keeping only the
# to-be-committed changes in the working directory.
# Will also stash uncommitted files
old_stash=$(git rev-parse --quiet --verify refs/stash)
git stash push --quiet --include-untracked --keep-index
new_stash=$(git rev-parse --quiet --verify refs/stash)

# Skip if nothing was stashed
if [ "$old_stash" = "$new_stash" ]; then
exit 0
fi

# Restore the stash after the tests are run
restore() {
git reset --hard --quiet && git stash pop --index --quiet
}
trap restore EXIT

npm run format:check || exit 1
npm run lint || exit 1
npm run test:clean || exit 1

0 comments on commit 837a581

Please sign in to comment.