-
Notifications
You must be signed in to change notification settings - Fork 14
/
make.sh
executable file
·322 lines (265 loc) · 6.52 KB
/
make.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
#
# OpenTHC API Makefile
#
# (c) 2018 OpenTHC, Inc.
# This file is part of OpenTHC API released under MIT License
#
# SPDX-License-Identifier: MIT
#
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
BIN_SELF=$(readlink -f "$0")
APP_ROOT=$(dirname "$BIN_SELF")
CMD=${1:-help}
DONE_MAKE_CODE_OPENAPI=""
DONE_MAKE_CODE_OPENAPI_PHP=""
DONE_MAKE_DOCS=""
DONE_MAKE_DOCS_DOXYGEN=""
DONE_MAKE_DOCS_ASCIIDOC=""
DONE_MAKE_DOCS_OPENAPI=""
function _make_code_openapi()
{
if [ -z "$DONE_MAKE_CODE_OPENAPI" ]
then
_make_docs_openapi
_make_code_openapi_php
# Go
rm -fr ./webroot/sdk/go
rm -fr ./webroot/sdk/go.zip
mkdir -p ./webroot/sdk/go
java -jar swagger-codegen-cli.jar \
generate \
--lang go \
--input-spec ./webroot/openapi.yaml \
--output ./webroot/sdk/go \
>/dev/null \
|| true
#cd ./webroot/sdk && zip -r go.zip ./go/
# JavaScript
rm -fr ./webroot/sdk/javascript
mkdir -p ./webroot/sdk/javascript
java -jar swagger-codegen-cli.jar \
generate \
--lang javascript \
--input-spec ./webroot/openapi.yaml \
--output ./webroot/sdk/javascript \
>/dev/null \
|| true
# Python
rm -fr ./webroot/sdk/python
mkdir -p ./webroot/sdk/python
java -jar swagger-codegen-cli.jar \
generate \
--lang python \
--input-spec ./webroot/openapi.yaml \
--output ./webroot/sdk/python \
>/dev/null \
|| true
zip -r ./webroot/sdk/python.zip ./webroot/sdk/python/
fi
DONE_MAKE_CODE_OPENAPI="done"
}
function _make_code_openapi_php()
{
if [ -z "$DONE_MAKE_CODE_OPENAPI_PHP" ]
then
rm -fr ./webroot/sdk/php
rm -fr ./webroot/sdk/php.zip
java -jar swagger-codegen-cli.jar \
generate \
--verbose \
--lang php \
--api-package "FOO" \
--input-spec ./webroot/openapi.yaml \
--output ./webroot/sdk/php \
>/dev/null \
|| true
zip -r ./webroot/sdk/php.zip ./webroot/sdk/php/ \
>/dev/null \
|| true
fi
DONE_MAKE_CODE_OPENAPI_PHP="done"
}
function _make_docs()
{
if [ -z "$DONE_MAKE_DOCS" ]
then
_make_docs_asciidoc
_make_docs_doxygen
_make_docs_openapi
_make_docs_openapi_html
_make_docs_redoc
fi
DONE_MAKE_DOCS="done"
}
function _make_docs_asciidoc()
{
if [ -z "$DONE_MAKE_DOCS_ASCIIDOC" ]
then
# mkdir -p ./webroot/doc/asciidoctor
# mkdir -p ./webroot/doc/revealjs
asciidoctor \
--verbose \
--backend=html5 \
--require=asciidoctor-diagram \
--section-numbers \
--out-file=./webroot/doc/asciidoctor/index.html \
./doc/index.ad
asciidoctor \
--verbose \
--backend=pdf \
--require=asciidoctor-diagram \
--require=asciidoctor-pdf \
--section-numbers \
--out-file=./webroot/doc/openthc.pdf \
./doc/index.ad
asciidoctor \
--backend=revealjs \
--require=asciidoctor-diagram \
--require=asciidoctor-revealjs \
--out-file=./webroot/doc/revealjs/index.html \
./doc/index.ad
fi
DONE_MAKE_DOCS_ASCIIDOC="done"
}
function _make_docs_openapi()
{
if [ -z "$DONE_MAKE_DOCS_OPENAPI" ]
then
if [ ! -d ./webroot/openapi-ui/ ]
then
git clone https://github.com/swagger-api/swagger-ui.git ./webroot/openapi-ui/
else
pushd ./webroot/openapi-ui/
git pull
popd
fi
php ./bin/build-openapi.php > ./webroot/openapi.yaml
# sed -i 's/url: "https:\/\/petstore.swagger.io\/v2\/swagger.json"/url: "\/openapi.yaml"/' webroot/openapi-ui/dist/swagger-initializer.js
fi
DONE_MAKE_DOCS_OPENAPI="done"
}
function _make_docs_doxygen()
{
if [ -z "$DONE_MAKE_DOCS_DOXYGEN" ]
then
doxygen etc/Doxyfile
fi
DONE_MAKE_DOCS_DOXYGEN="done"
}
#
# HTML Stuff from OpenAPI
#
function _make_docs_openapi_html()
{
rm -fr ./webroot/doc/openapi-html
mkdir -p ./webroot/doc/openapi-html
java -jar swagger-codegen-cli.jar \
generate \
--lang html \
--input-spec ./webroot/openapi.yaml \
--output ./webroot/doc/openapi-html || true
# HTML-v2 SDK?
rm -fr ./webroot/doc/openapi-html-v2
mkdir -p ./webroot/doc/openapi-html-v2
java -jar swagger-codegen-cli.jar \
generate \
--lang html2 \
--input-spec ./webroot/openapi.yaml \
--output ./webroot/doc/openapi-html-v2 || true
}
#
#
# Stopped Working Recently
function _make_docs_redoc()
{
mkdir -p ./webroot/doc/redoc
npx @redocly/cli build-docs ./webroot/openapi.yaml
mv ./redoc-static.html ./webroot/doc/redoc/index.html
}
#
# Action
case "$CMD" in
#
# All the things
"install")
composer install --no-ansi --no-dev --no-progress --quiet --classmap-authoritative
npm install --quiet >/dev/null
_make_docs
_make_code_openapi
. vendor/openthc/common/lib/lib.sh
copy_bootstrap
copy_fontawesome
copy_jquery
outpath="webroot/vendor/highlight.js"
mkdir -p "$outpath/"
cp node_modules/@highlightjs/cdn-assets/styles/atom-one-dark.min.css "$outpath/"
cp node_modules/@highlightjs/cdn-assets/highlight.min.js "$outpath/"
# curl https://home > index.html
;;
"system-install")
# apt-get -qqy install doxygen graphviz libyaml-dev default-jre php-dev php-yaml python-pip ruby
# gem install asciidoctor
# gem install asciidoctor-diagram asciidoctor-revealjs coderay pygments.rb
# gem install asciidoctor-pdf --pre
wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.43/swagger-codegen-cli-3.0.43.jar \
-O swagger-codegen-cli.jar
;;
#
# Generate openapi/swagger Docs with https://github.com/swagger-api/swagger-codegen
"code-openapi")
_make_code_openapi
;;
#
# Update the PHP SDK
"code-openapi-php")
_make_code_openapi_php
_make_docs_openapi
;;
#
# Build a bunch of docs
"docs")
_make_docs
;;
#
# Generate asciidoc formats
"docs-asciidoc")
_make_docs_asciidoc
;;
#
# Generate Doxygent stuff
"docs-doxygen")
_make_docs_doxygen
;;
#
# Build the OpenAPI docs (/doc/openapi-ui/dist)
"docs-openapi")
_make_docs_openapi
_make_docs_openapi_html
;;
#
# Build API Reference with ReDoc
"docs-redoc")
_make_docs_openapi
_make_docs_redoc
;;
"help"|*)
echo
echo "You must supply a make command"
echo
# works a bit better
# grep --null-data --only-matching --perl-regexp '\s*#\n\s*#.*\n\s*["\w\-]+.*\n' "$0" \
# | awk '{ printf " \033[0;49;32m%-20s\033[0m%s\n", $0, gensub(/^# /, "", 1, x) };'
grep --null-data --only-matching --perl-regexp '\s*#\n\s*#.*\n\s*["\w\-]+.*\n' "$0" \
| awk '/\s*"\w+/ { printf " \033[0;49;32m%-20s\033[0m %s\n", $0, gensub(/^\s*# /, "", 1, x) }; { x=$$0 }' \
| sort
# parses make file
# grep --null-data --only-matching --perl-regexp "#\n#.*\n[\w\-]+(:|\)).*\n" "$0" \
# | awk '/[a-zA-Z0-9_-]+:/ { printf " \033[0;49;32m%-20s\033[0m%s\n", $$1, gensub(/^# /, "", 1, x) }; { x=$$0 }'
# | sort
echo
;;
esac