-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgenerate-sdks
executable file
·182 lines (149 loc) · 3.88 KB
/
generate-sdks
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
set -e
DIR=$(cd `dirname $0` && pwd)
SDKS=( dotnet java-v1 java-v2 node php python ruby )
SHOW_HELP=0
TARGET_SDK=
while getopts ":t:h" opt; do
case $opt in
t) TARGET_SDK="$OPTARG"
;;
h) SHOW_HELP=1
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
function main() {
if [[ $SHOW_HELP -eq 1 ]]; then
show_help
exit 0
fi
if [[ -z ${TARGET_SDK} ]]; then
show_help
exit 0
fi
validate_sdk_choice $TARGET_SDK
if [[ "${TARGET_SDK}" != "all" ]]; then
build_sdk $TARGET_SDK
else
for SDK in "${SDKS[@]}"
do :
build_sdk $SDK
done
fi
printf "Success! All SDKs built!\n"
exit 0
}
function show_help() {
cat << EOF
Usage: generate-sdks [OPTION]
Builds a given SDK into the sdks/[SDK] directory.
**WARNING** All files and directories present in the sdks/[SDK] directory will
be DELETED and REBUILT!
-t target SDK, "all", "dotnet", "java-v2", "java-v1", "node", "php", "python", "ruby"
-h display this help and exit
Example: generate-sdks -t php
EOF
exit 0
}
function validate_sdk_choice()
{
SDK="$1"
if [[
"${SDK}" != "all" &&
"${SDK}" != "dotnet" &&
"${SDK}" != "java-v1" &&
"${SDK}" != "java-v2" &&
"${SDK}" != "node" &&
"${SDK}" != "php" &&
"${SDK}" != "python" &&
"${SDK}" != "ruby"
]]; then
printf "Invalid SDK (-t) value: ${SDK}\n"
show_help
exit 1
fi
}
function build_sdk()
{
SDK="$1"
SDK_DIR="${DIR}/sdks/${SDK}"
printf "Building ${SDK} SDK\n"
clear_previous_build_files $SDK
copy_oas $SDK
copy_examples $SDK
copy_test_fixtures $SDK
bash "${SDK_DIR}/run-build"
printf "\n\n"
printf "########\n"
printf "######## Done building ${SDK} SDK\n"
printf "########\n"
printf "\n\n"
}
function clear_previous_build_files()
{
SDK="$1"
SDK_DIR="${DIR}/sdks/${SDK}"
printf "Clearing previous build files ...\n"
if [[ "${SDK}" == "dotnet" ]]; then
rm -rf "${SDK_DIR}/docs"
rm -rf "${SDK_DIR}/src/HelloSign"
elif [[ "${SDK}" == "java-v2" || "${SDK}" == "java-v1" ]]; then
rm -rf "${SDK_DIR}/docs"
rm -rf "${SDK_DIR}/src/main"
elif [[ "${SDK}" == "node" ]]; then
rm -rf "${SDK_DIR}/api"
rm -rf "${SDK_DIR}/dist"
rm -rf "${SDK_DIR}/docs"
rm -rf "${SDK_DIR}/model"
rm -rf "${SDK_DIR}/types"
elif [[ "${SDK}" == "php" ]]; then
rm -rf "${SDK_DIR}/docs"
rm -rf "${SDK_DIR}/src"
elif [[ "${SDK}" == "python" ]]; then
rm -rf "${SDK_DIR}/docs"
rm -rf "${SDK_DIR}/hellosign_sdk"
elif [[ "${SDK}" == "ruby" ]]; then
rm -rf "${SDK_DIR}/docs"
rm -rf "${SDK_DIR}/lib"
fi
}
function copy_oas()
{
SDK="$1"
SDK_DIR="${DIR}/sdks/${SDK}"
printf "Copying openapi-sdk.yaml ...\n"
rm -f "${SDK_DIR}/openapi-sdk.yaml"
cp -r "${DIR}/openapi-sdk.yaml" "${SDK_DIR}/openapi-sdk.yaml"
}
function copy_examples()
{
SDK="$1"
SDK_DIR="${DIR}/sdks/${SDK}"
printf "Copying examples ...\n"
rm -rf "${SDK_DIR}/examples"
mkdir -p "${SDK_DIR}/examples"
if [[ "${SDK}" == "dotnet" ]]; then
cp -r "${DIR}/sandbox/dotnet/src/Dropbox.SignSandbox/"*.cs "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "java-v2" || "${SDK}" == "java-v1" ]]; then
cp -r "${DIR}/sandbox/java/src/main/java/com/dropbox/sign_sandbox/"*.java "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "node" ]]; then
cp -r "${DIR}/sandbox/node/src/"*.ts "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "php" ]]; then
cp -r "${DIR}/sandbox/php/src/"*.php "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "python" ]]; then
cp -r "${DIR}/sandbox/python/src/"*.py "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "ruby" ]]; then
cp -r "${DIR}/sandbox/ruby/src/"*.rb "${SDK_DIR}/examples/"
fi
}
function copy_test_fixtures()
{
SDK="$1"
SDK_DIR="${DIR}/sdks/${SDK}"
printf "Copying test_fixtures ...\n"
rm -rf "${SDK_DIR}/test_fixtures"
cp -r "${DIR}/test_fixtures" "${SDK_DIR}/test_fixtures"
}
main