-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
60 lines (43 loc) · 1.15 KB
/
Makefile
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
# Configuration variables:
.DEFAULT_GOAL := build
# Prepare Application workspace
build:
swift build -c release
cp -f .build/release/Murray /usr/local/bin/murray
archive:
swift build -c release
cp -f .build/release/Murray ./murray
chmod +x murray
zip murray.zip murray
# Install dependencies, download build resources and add pre-commit hook
lint:
swiftformat ./Sources
swiftlint --fix
swiftlint lint --strict
git_setup:
eval "$$add_pre_commit_script"
setup:
brew update && brew bundle
make git_setup
# Define pre commit script to auto lint and format the code
define _add_pre_commit
if [ -d ".git" ]; then
SWIFTLINT_PATH=`which swiftlint`
SWIFTFORMAT_PATH=`which swiftformat`
cat > .git/hooks/pre-commit << ENDOFFILE
#!/bin/sh
FILES=\$(git diff --cached --name-only --diff-filter=ACMR "*.swift" | sed 's| |\\ |g')
[ -z "\$FILES" ] && exit 0
# Format
${SWIFTFORMAT_PATH} \$FILES
# Lint
${SWIFTLINT_PATH} --fix \$FILES
${SWIFTLINT_PATH} lint \$FILES
# Add back the formatted/linted files to staging
echo "\$FILES" | xargs git add
exit 0
ENDOFFILE
chmod +x .git/hooks/pre-commit
fi
endef
export add_pre_commit_script = $(value _add_pre_commit)