Skip to content

Commit abe42c5

Browse files
authored
[docs] refactor build.sh (#5864)
1 parent 8ee7ecc commit abe42c5

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

ydb/docs/build.sh

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
# Use this script to build YDB docs with Open Source tools and start HTTP server
2-
# You may specify output directory as a parameter. If omitted, docs will be generated to a TEMP subdirectory
1+
#!/bin/bash
32

4-
echo Checking YFM installed...
5-
yfm --version
6-
if [[ $? -ge 1 ]]; then
7-
echo
8-
echo "You need to have YFM builder (https://diplodoc.com/docs/en/tools/docs/) installed to run this script, exiting"
9-
exit
10-
fi
3+
# Use this script to build YDB docs with open-source tools and start an HTTP server
4+
# You may specify the output directory as a parameter. If omitted, the docs will be generated to a TEMP subdirectory
5+
6+
set -e
117

12-
echo Checking Python3 installed...
13-
python3 --version
8+
check_dependency() {
9+
if ! command -v $1 &> /dev/null; then
10+
echo
11+
echo "You need to have $2 installed to run this script, exiting"
12+
echo "Installation instructions: $3"
13+
exit 1
14+
fi
15+
}
1416

15-
if [[ $? -ge 1 ]]; then
17+
start_server() {
1618
echo
17-
echo "You need to have Python3 (https://www.python.org/) installed to run this script, exiting"
18-
exit
19-
fi
19+
echo "Starting HTTP server, open the links in your browser:"
20+
echo
21+
echo "- http://localhost:8888/en (English)"
22+
echo "- http://localhost:8888/ru (Russian)"
23+
echo
24+
echo "Press Ctrl+C in this window to stop the HTTP server."
25+
echo
26+
python3 -m http.server 8888 -d $1
27+
}
2028

2129
DIR=${1:-"$TMPDIR"docs}
2230

23-
echo Starting YFM builder
24-
echo Output directory: $DIR
31+
check_dependency "yfm" "YFM builder" "https://diplodoc.com/docs/en/tools/docs/"
32+
check_dependency "python3" "Python3" "https://www.python.org/downloads/"
2533

26-
yfm -i . -o $DIR --allowHTML
34+
echo "Starting YFM builder"
35+
echo "Output directory: $DIR"
2736

28-
if [[ $? -ge 1 ]]; then
37+
if ! yfm -i . -o $DIR --allowHTML; then
2938
echo
30-
echo ================================
31-
echo YFM build completed with ERRORS!
32-
echo ================================
39+
echo "================================"
40+
echo "YFM build completed with ERRORS!"
41+
echo "================================"
42+
exit 1
3343
fi
3444

35-
echo
36-
echo Starting HTTP server, open the links in your browser:
37-
echo
38-
echo "- http://localhost:8888/en (English)"
39-
echo "- http://localhost:8888/ru (Russian)"
40-
echo
41-
echo Press Ctrl+C in this window to stop the HTTP server.
42-
echo
43-
44-
python3 -m http.server 8888 -d $DIR
45-
45+
start_server $DIR
4646

0 commit comments

Comments
 (0)