-
Notifications
You must be signed in to change notification settings - Fork 1
/
codeformat.sh
executable file
·142 lines (119 loc) · 3.25 KB
/
codeformat.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
UNCRUSTIFY_VER=0.76.0
SWIFTFORMAT_VER=0.53.7
CF_DIR=.codeformat
TMP_DIR=tmp
echo_info() {
ESC=$(printf '\033')
echo -e "${ESC}[36m$1${ESC}[m"
}
echo_err() {
ESC=$(printf '\033')
echo -e "${ESC}[31m$1${ESC}[m"
}
download_uncrustify() {
local arch="$1"
echo_info "arch=$arch"
echo_info "$(cmake --version)"
git clone https://github.com/uncrustify/uncrustify.git
cd uncrustify
git checkout uncrustify-$UNCRUSTIFY_VER
mkdir build
cd build
cmake -DCMAKE_OSX_ARCHITECTURES="$arch" -DCMAKE_BUILD_TYPE=Release ..
make
cd ../../
return 0
}
download_swiftformat() {
echo_info "$(swift -version)"
git clone https://github.com/nicklockwood/SwiftFormat
cd SwiftFormat
git checkout $SWIFTFORMAT_VER
swift build -c release
cd ../
return 0
}
install_tools() {
if [ -e $CF_DIR ]; then
rm -rf $CF_DIR
fi
mkdir $CF_DIR
cd $CF_DIR
mkdir $TMP_DIR
cd $TMP_DIR
download_uncrustify "$(uname -m)" || exit 1
download_swiftformat "$(uname -m)" || exit 1
# to $CF_DIR/
cd ../
# Move uncrustify command
mv ./$TMP_DIR/uncrustify/build/uncrustify .
# Move swiftformat command
mv ./$TMP_DIR/SwiftFormat/.build/release/swiftformat .
# Check version
echo_info "Uncrustify=$(./uncrustify --version)"
echo_info "SwiftFormat=$(./swiftformat -version)"
# Clean up
rm -rf $TMP_DIR
}
code_format() {
echo_info "ObjC code formatting..."
find . \
-type d -name "*.framework" -prune \
-a -type d -not -name "*.framework" \
-o -type d -name "*.xcframework" -prune \
-a -type d -not -name "*.xcframework" \
-o -type d -name "Frameworks" -prune \
-a -type d -not -name "Frameworks" \
-o -type d -name "Resources" -prune \
-a -type d -not -name "Resources" \
-o -type d -name "Pods" -prune \
-a -type d -not -name "Pods" \
-o -type d -name "build" -prune \
-a -type d -not -name "build" \
-o -type d -name "vendor" -prune \
-a -type d -not -name "vendor" \
-o -type d -name "node_modules" -prune \
-a -type d -not -name "node_modules" \
-o -type d -name ".build" -prune \
-a -type d -not -name ".build" \
-o -type d -name "Output" -prune \
-a -type d -not -name "Output" \
-o -name "*.m" \
-o -name "*.h" \
| xargs $(pwd)/.codeformat/uncrustify -c uncrustify-objc.cfg -l OC --no-backup
echo_info "Swift code formatting..."
find . \
-type d -name "*.framework" -prune \
-a -type d -not -name "*.framework" \
-o -type d -name "*.xcframework" -prune \
-a -type d -not -name "*.xcframework" \
-o -type d -name "Frameworks" -prune \
-a -type d -not -name "Frameworks" \
-o -type d -name "Resources" -prune \
-a -type d -not -name "Resources" \
-o -type d -name "Pods" -prune \
-a -type d -not -name "Pods" \
-o -type d -name "Carthage" -prune \
-a -type d -not -name "Carthage" \
-o -type d -name "build" -prune \
-a -type d -not -name "build" \
-o -type d -name "vendor" -prune \
-a -type d -not -name "vendor" \
-o -type d -name "node_modules" -prune \
-a -type d -not -name "node_modules" \
-o -type d -name ".build" -prune \
-a -type d -not -name ".build" \
-o -type d -name "Output" -prune \
-a -type d -not -name "Output" \
-o -name "*.swift" \
| xargs $(pwd)/.codeformat/swiftformat
}
OPT1=$1
if [ $OPT1 = "--install" ]; then
install_tools
elif [ $OPT1 = "--fix" ]; then
code_format
else
echo_err "Please add --install or --fix options."
fi