-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_commit_hook.sh
executable file
·74 lines (61 loc) · 1.93 KB
/
pre_commit_hook.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env sh
# This line is very important, otherwise the hook doesn't prevent the commit or merge
# in case of a failure.
set -e
set -x
simulated_git_branch="$1"
git_branch="$(git rev-parse --abbrev-ref HEAD)"
# Assumption for all `if [ "$branch" = "main" ]` blocks:
# - we develop on branches other than `main`
# - we release new versions on `main`
if [ "$simulated_git_branch" == "" ]; then
if [ "$git_branch" = "main" ]; then
check_mode="full"
elif [ "$git_branch" == "beetpx.dev" ]; then
check_mode="none"
else
check_mode="dev"
fi
else
if [ "$simulated_git_branch" == "main" ]; then
check_mode="full"
elif [ "$simulated_git_branch" == "beetpx.dev" ]; then
check_mode="none"
else
check_mode="dev"
fi
fi
if [ "$check_mode" == "none" ]; then
exit 0
fi
if [ "$check_mode" == "full" ]; then
# If version got bumped in package.json, update the version in package-lock.json as well
npm install
fi
# Make sure everything is formatted as desired
npm run format
if [ "$check_mode" == "full" ]; then
# Make sure TypeScript types and Jest tests didn't break due to most recent changes.
# We do this on a `main` branch only in order to allow broken tests while development
# is in progress.
npm run test
fi
if [ "$check_mode" == "full" ]; then
echo "Checking the playground project ..."
cd ./playground/
npm install
npm run format
npm run tsc
npm run test --if-present
cd ../
fi
# Generate up-to-date JS and .d.ts files out of the TypeScript source.
# Thanks to this command being run on every commit, users can refer to
# any commit of this repo in their `package.json` files and have BeetPx
# ready to use there.
# We do this on all branches, because during engine development we might
# want to install a specific non-versioned commit of BeetPx in a game
# repository.
npm run compile
# Whatever was changed due to commands above, let's add it to the commit
git add --all .