-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·53 lines (40 loc) · 1.14 KB
/
pre-commit
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
#!/bin/sh
# Copy screenshot to master.
git rm -f vt/screenshots/master/* > /dev/null
cp vt/screenshots/current/* vt/screenshots/master
touch vt/screenshots/master/.master
git add vt/screenshots/master
TSLINT=./node_modules/.bin/tslint
PRETTIER=./node_modules/.bin/prettier
PRESUBMIT_CHECKED_DIR=.presubmit-checked-list
mkdir -p $PRESUBMIT_CHECKED_DIR
which $TSLINT > /dev/null | exit 1
which $PRETTIER > /dev/null | exit 1
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.tsx\?$' | tr '\n' ' ');
for file in $FILES
do
if [ $(echo $file | grep '.d.ts') ]; then
continue;
fi
FILEKEY=${file//\//-}
if [ -e $PRESUBMIT_CHECKED_DIR/$FILEKEY ]; then
continue
fi
echo "prettier ./$file";
# Prettify staged .ts files
$PRETTIER ./$file --write;
echo "lint ./$file";
if [[ $file == *"vt/"* ]]; then
cd vt
../$TSLINT ./$file -c ./tslint.json -p . --fix;
cd ../
else
$TSLINT ./$file -c ./tslint.json --exclude './src/**/*.css' -p ./ --fix;
fi
if [ $? -ne 0 ];then
exit 1;
fi
touch $PRESUBMIT_CHECKED_DIR/$FILEKEY
# Add back the modified/prettified files to staging
git add $file
done