-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-common-project-files.sh
executable file
·155 lines (135 loc) · 3.75 KB
/
setup-common-project-files.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
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Calls all common project setup scripts. Exceptions can be enabled with flags.
#
# Author Hans Seiffert
# Updated Kevin Delord
#
# Last revised 17/09/2020
#
# Constants
#
readonly noSwiftlintFlag="--no-swiftlint"
readonly noPRTemplateCopyFlag="--no-pr-template-copy"
readonly noXcodeCheck="--no-xcodecheck"
readonly targetTypeFlag="--targettype"
readonly breakingInternalFrameworkVersioningFlag="--use-breaking-internal-framework-versioning"
readonly swiftUIFlag="--SwiftUI"
readonly buildConfigurationFlag="--buildconfig" # deprecated
readonly noCodebeatFlag="--no-codebeat" # deprecated
readonly noCodeClimateFlag="--no-codeclimate" # deprecated
readonly scriptBaseFolderPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#
# Variables
#
isFramework=false
useBreakingInternalFrameworkVersioning=false
copyPRTemplate=true
callSwiftlint=true
checkXcodeVersion=false
projectDir="$(pwd)"
isSwiftUIProject=false
#
# Methods
#
function display_usage () {
echo "This script performs all common project setup scripts by default. You can optionally pass the projects base directory path as argument. Exceptions can be declared with the flags:"
echo -e "$noSwiftlintFlag\t\t\t\t- Don't run swiftlint"
echo -e "$noPRTemplateCopyFlag\t\t\t- Don't copy the GitHub PR Template file"
echo -e "$breakingInternalFrameworkVersioningFlag\t -Use the \"BreakingInternal framework versioning system\" (only for frameworks)"
echo -e "$swiftUIFlag\t\t\t\t- Use custom SwiftLint rules for swift ui projects"
echo -e "\nUsage:\n$ $0 $swiftUIFlag"
echo -e "or:\n$ $0 $swiftUIFlag /Code/Project/Test"
exit 1
}
#
# Read flags
#
while test $# -gt 0; do
case "$1" in
$buildConfigurationFlag) # Deprecated parameter
# For legacy and retro-compatibility keep the 'switch-case' and pass through the arguments
shift
shift
# break
;;
$targetTypeFlag)
configName=$(echo "$2" | awk '{print tolower($0)}')
if [ $configName = "com.apple.product-type.framework" ]; then
isFramework=true
fi
shift
shift
# break
;;
$noSwiftlintFlag)
callSwiftlint=false
shift
# break
;;
$noPRTemplateCopyFlag)
copyPRTemplate=false
shift
# break
;;
$noCodebeatFlag) # Deprecated parameter
# For legacy and retro-compatibility keep the 'switch-case' and pass through the arguments
shift
# break
;;
$breakingInternalFrameworkVersioningFlag)
useBreakingInternalFrameworkVersioning=true
shift
# break
;;
$swiftUIFlag)
isSwiftUIProject=true
shift
# break
;;
$noCodeClimateFlag) # Deprecated parameter
# For legacy and retro-compatibility keep the 'switch-case' and pass through the arguments
shift
# break
;;
$noXcodeCheck)
checkXcodeVersion=false
shift
# break
;;
-*)
display_usage
shift
;;
*)
# This is the project directory
projectDir="$1"
shift
;;
esac
done
# Go the folder which contains this script
cd "$scriptBaseFolderPath"
#
# Call scripts
#
if [ $callSwiftlint = true ]; then
./SwiftLint/copy-and-run-swiftlint-config.sh "$projectDir" $isFramework $isSwiftUIProject || exit 1;
fi
if [ $isFramework = true ]; then
./DrString/copy-and-run-DrString-config.sh "$projectDir" || exit 1;
fi
if [ $copyPRTemplate = true ]; then
mkdir -p "$projectDir/.github"
if [ $isFramework = true ]; then
if [ $useBreakingInternalFrameworkVersioning = true ]; then
cp "./Github/PR-Template-Framework-BreakingInternal-Versioning.md" "$projectDir/.github/PULL_REQUEST_TEMPLATE.md" || exit 1;
else
cp "./Github/PR-Template-Framework.md" "$projectDir/.github/PULL_REQUEST_TEMPLATE.md" || exit 1;
fi
exit 0
fi
cp "./Github/PR-Template-App.md" "$projectDir/.github/PULL_REQUEST_TEMPLATE.md" || exit 1;
fi
if [ $checkXcodeVersion = true ]; then
./Xcode/check-xcode-version.swift;
fi