forked from Suwayomi/Tachidesk-Sorayomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·108 lines (92 loc) · 2.58 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
printf "\e[33;1m%s\e[0m\n" 'Started Sorayomi Pre-Commit hook'
# Undo the stash of the files
pop_stash_files () {
if [ -n "$hasChanges" ]; then
printf "\e[33;1m%s\e[0m\n" '=== Applying git stash changes ==='
git stash pop
fi
}
#
# Stash unstaged files
#
hasChanges=$(git diff)
if [ -n "$hasChanges" ]; then
printf "\e[33;1m%s\e[0m\n" 'Stashing unstaged changes'
git stash push --keep-index
fi
printf "\e[33;1m%s\e[0m\n" '=== Running Pub get ==='
flutter pub get
printf "\e[33;1m%s\e[0m\n" 'Finished Running Pub get'
#
# Localization
#
printf "\e[33;1m%s\e[0m\n" '=== Running Localization ==='
flutter gen-l10n
hasNewFilesFormatted=$(git diff)
if [ -n "$hasNewFilesFormatted" ]; then
git add .
printf "\e[33;1m%s\e[0m\n" 'Generated locale files added to git stage'
fi
printf "\e[33;1m%s\e[0m\n" 'Finished Running Localization'
printf '%s\n' "${avar}"
#
# Build Runner
#
printf "\e[33;1m%s\e[0m\n" '=== Running Build Runner ==='
dart run build_runner build --delete-conflicting-outputs
hasNewFilesFormatted=$(git diff)
if [ -n "$hasNewFilesFormatted" ]; then
git add .
printf "\e[33;1m%s\e[0m\n" 'Generated locale files added to git stage'
fi
printf "\e[33;1m%s\e[0m\n" 'Finished Running Build Runner'
printf '%s\n' "${avar}"
#
# Flutter formatter
#
printf "\e[33;1m%s\e[0m\n" '=== Running Flutter Formatter ==='
dart format .
hasNewFilesFormatted=$(git diff)
if [ -n "$hasNewFilesFormatted" ]; then
git add .
printf "\e[33;1m%s\e[0m\n" 'Formmated files added to git stage'
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter Formatter'
printf '%s\n' "${avar}"
#
# Dart Fix
#
printf "\e[33;1m%s\e[0m\n" '=== Running Dart Fix ==='
dart fix --apply
hasNewFilesFormatted=$(git diff)
if [ -n "$hasNewFilesFormatted" ]; then
git add .
printf "\e[33;1m%s\e[0m\n" 'Fixed files added to git stage'
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Dart Fix'
printf '%s\n' "${avar}"
#
# Flutter Analyzer
#
printf "\e[33;1m%s\e[0m\n" '=== Running Flutter analyzer ==='
flutter analyze
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" '=== Flutter analyzer error ==='
pop_stash_files
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter analyzer'
printf '%s\n' "${avar}"
# Unit tests
# printf "\e[33;1m%s\e[0m\n" '=== Running Unit Tests ==='
# flutter test
# if [ $? -ne 0 ]; then
# printf "\e[31;1m%s\e[0m\n" '=== Unit tests error ==='
# pop_stash_files
# exit 1
# fi
# printf "\e[33;1m%s\e[0m\n" 'Finished running Unit Tests'
# printf '%s\n' "${avar}"
printf "\e[33;1m%s\e[0m\n" 'Finished running Sorayomi Pre-hook'
pop_stash_files