Add ability to manage all widget/applications
[src/app-framework-main.git] / gendocs.sh
1 #!/bin/bash
2
3 OUTFILENAME="Application-Framework-Service-Guide"
4
5 SCRIPT=$(basename $BASH_SOURCE)
6
7 VERSION=$(grep '"version":' $(dirname $BASH_SOURCE)/book.json | cut -d'"' -f 4)
8 [ "$VERSION" != "" ] && OUTFILENAME="${OUTFILENAME}_${VERSION}"
9
10
11 function usage() {
12     cat <<EOF >&2
13 Usage: $SCRIPT [options] [pdf|serve|doxygen]
14
15 Options:
16    --debug
17       enable debug when generating pdf or html documentation
18    -d|--dry
19       dry run
20    -h|--help
21       get this help
22
23 Example:
24     $SCRIPT pdf
25
26 EOF
27     exit ${1:-1}
28 }
29
30 function info() {
31     echo "$@" >&2
32 }
33
34 function error() {
35     info "error:" "$@"
36     exit 1
37 }
38
39 #default values
40 DEBUG_FLAG=""
41 DRY=""
42 DO_ACTION=""
43 OUT_DIR=./build
44
45 [[ $? != 0 ]] && usage
46 while [ $# -gt 0 ]; do
47     case "$1" in
48         --debug) DEBUG_FLAG="--log=debug --debug";;
49         -d|--dry) DRY=echo;;
50         -h|--help) usage 0;;
51         pdf | serve | doxygen) DO_ACTION=$1;;
52         --) break;;
53     esac
54     shift
55 done
56
57 cd $(dirname $0)
58 ROOTDIR=`pwd -P`
59
60 # Create out dir if needed
61 [ -d $OUT_DIR ] || mkdir -p $OUT_DIR
62
63 if [ "$DO_ACTION" = "pdf" -o "$DO_ACTION" = "serve" ]; then
64     GITBOOK=`which gitbook` || error "You must install gitbook first, using: sudo npm install -g gitbook-cli"
65     EBCONV=`which ebook-convert` || error "You must install calibre first, using: 'sudo apt install calibre' or refer to https://calibre-ebook.com/download"
66
67     if [ "$DO_ACTION" = "pdf" ]; then
68
69         # Update cover when book.json has been changed
70         [[ $ROOTDIR/book.json -nt $ROOTDIR/docs/cover.jpg ]] && { echo "Update cover files"; $ROOTDIR/docs/resources/make_cover.sh || exit 1; }
71
72         OUTFILE=$OUT_DIR/$OUTFILENAME.pdf
73         $DRY $GITBOOK pdf $ROOTDIR $OUTFILE $DEBUG_FLAG
74         [ "$?" = "0" ] && echo "PDF has been successfully generated in $OUTFILE"
75     else
76         $DRY $GITBOOK serve $DEBUG_FLAG
77     fi
78
79 elif [ "$DO_ACTION" = "doxygen" ]; then
80     $DRY cd $OUT_DIR && cmake .. && make doxygen $ROOTDIR/Doxyfile
81
82 else
83     echo "Unknown action !"
84     usage
85 fi