|
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 |
3 | 2 |
|
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 |
11 | 7 |
|
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 | +} |
14 | 16 |
|
15 | | -if [[ $? -ge 1 ]]; then |
| 17 | +start_server() { |
16 | 18 | 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 | +} |
20 | 28 |
|
21 | 29 | DIR=${1:-"$TMPDIR"docs} |
22 | 30 |
|
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/" |
25 | 33 |
|
26 | | -yfm -i . -o $DIR --allowHTML |
| 34 | +echo "Starting YFM builder" |
| 35 | +echo "Output directory: $DIR" |
27 | 36 |
|
28 | | -if [[ $? -ge 1 ]]; then |
| 37 | +if ! yfm -i . -o $DIR --allowHTML; then |
29 | 38 | 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 |
33 | 43 | fi |
34 | 44 |
|
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 |
46 | 46 |
|
0 commit comments