blob: 27b72405335c211231e9ff3746f9879ae976ecc2 (
plain)
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
|
#!/usr/bin/env bash
set -o noglob
: ${1?"Usage: $0 <check|save|check-all|save-all>"}
PRETTIER_PATH=$(git rev-parse --show-toplevel)/node_modules/.bin/prettier
if [ ! -f $PRETTIER_PATH ]; then
echo "ERROR: Prettier not found!"
exit 1
fi
case $1 in
check)
action=check
files=staged
;;
save)
action=save
files=staged
;;
check-all)
action=check
files=all
;;
save-all)
action=save
files=all
;;
*)
echo "$1 is not a valid argument, please use check, save, check-all or save-all"
exit 1
;;
esac
echo -e "Loading $files files ...\n"
if [ "$files" == "staged" ]; then
file_list=$(git diff --name-only --cached --diff-filter=ACMRTUB '*.vue' '*.js' '*.scss' | tr '\r\n' ' ')
else
file_list="**/*.vue **/*.js **/*.scss"
fi
if [ "$action" == "check" ]; then
if $PRETTIER_PATH --list-different $file_list; then
echo -e "\nFormat of $files files is correct."
exit 0
else
echo -e "\n===============================\nGitLab uses Prettier to format all JavaScript code.\nPlease format each file listed above or run 'yarn prettier-$files-save'\n===============================\n"
exit 1
fi
fi
if [ "$action" == "save" ]; then
if $PRETTIER_PATH --write $file_list; then
echo -e "\nFormatted $files files successfully with prettier."
exit 0
else
echo -e "\nSomething went wrong while formatting with prettier."
exit 1
fi
fi
echo "ERROR: Something went wrong"
exit 1
|