Skip to content

Commit fad7ec5

Browse files
committed
feat(codestyle): swift-format improvements
- Update scripts - Use local version
1 parent 18680f3 commit fad7ec5

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/Packages
44
/*.xcodeproj
55
xcuserdata/
6+
Scripts/.installed

.swift-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 1,
3-
"lineLength": 100,
3+
"lineLength": 120,
44
"indentation": {
55
"spaces": 2
66
},

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
install_format:
2+
./scripts/install_swift-format
3+
14
format:
2-
swift-format --in-place --recursive \
5+
./scripts/.installed/swift-format --in-place --recursive \
36
./Package.swift ./Sources ./Tests
47

58
test:

Scripts/install_swift-format

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
_get_parent_dir_abs_path() {
4+
echo "$(cd "$(dirname "$1")" && pwd)"
5+
}
6+
7+
# ––––––––––––––––––––––––––– config –––––––––––––––––––––––––––
8+
9+
TOOL_NAME="swift-format"
10+
TOOL_OWNER="apple"
11+
TOOL_CHECKOUT="tags/0.50400.0"
12+
13+
# ––––––––––––––––––––––––– constants ––––––––––––––––––––––––––
14+
15+
SCRIPT_DIR=$(_get_parent_dir_abs_path $0)
16+
TOOLS_INSTALL_PATH="${SCRIPT_DIR}/.installed"
17+
TOOL_INSTALL_PATH="${TOOLS_INSTALL_PATH}/${TOOL_NAME}"
18+
TEMP_INSTALL_PATH="${TOOLS_INSTALL_PATH}/install-${TOOL_NAME}"
19+
20+
# ––––––––––––––––––––––––––– steps ––––––––––––––––––––––––––––
21+
22+
tool_fetch() {
23+
git clone "https://github.com/${TOOL_OWNER}/${TOOL_NAME}.git"
24+
cd "${TOOL_NAME}"
25+
git checkout ${TOOL_CHECKOUT}
26+
}
27+
28+
tool_build() {
29+
swift build --product="${TOOL_NAME}" -c release --disable-sandbox
30+
}
31+
32+
tool_install() {
33+
install "${TEMP_INSTALL_PATH}/${TOOL_NAME}/.build/release/${TOOL_NAME}" "${TOOLS_INSTALL_PATH}"
34+
}
35+
36+
# ––––––––––––––––––––––––––– script –––––––––––––––––––––––––––
37+
38+
set_bold=$(tput bold)
39+
set_normal=$(tput sgr0)
40+
41+
log() {
42+
printf "\n$1 ${set_bold}$2${set_normal}\n"
43+
}
44+
45+
_trap_exit() {
46+
rm -rf "${TEMP_INSTALL_PATH}"
47+
}
48+
49+
set -e
50+
trap _trap_exit err exit SIGTERM SIGINT
51+
52+
if [ -f "${TOOL_INSTALL_PATH}" ]; then
53+
log "⚠️" " ${TOOL_NAME} already installed"
54+
exit 0
55+
fi
56+
57+
if [ ! -d "${TEMP_INSTALL_PATH}" ]; then
58+
mkdir -p "${TEMP_INSTALL_PATH}"
59+
fi
60+
61+
cd "${TEMP_INSTALL_PATH}"
62+
63+
log "⬇️" " Fetching ${TOOL_NAME}...\n"
64+
65+
tool_fetch
66+
67+
log "🔨" "Building ${TOOL_NAME}...\n"
68+
69+
tool_build
70+
71+
log "♻️" " Installing ${TOOL_NAME}..."
72+
73+
tool_install
74+
75+
log "💧" "Performing cleanup..."
76+
rm -rf "${TEMP_INSTALL_PATH}"
77+
78+
if [ -f "${TOOL_INSTALL_PATH}" ]; then
79+
log "" "${TOOL_NAME} successfully installed"
80+
exit 0
81+
fi
82+
83+
log "🚫" "${TOOL_NAME} failed to install"

0 commit comments

Comments
 (0)