/
update_docs.sh
executable file
·150 lines (113 loc) · 3.52 KB
/
update_docs.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
#!/bin/bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# update_docs: As it says, it updates the docs
#
# 1) update the documentation data from JSDocs of the ts files
# 2) build the ng-app and update the files in docs/ folder
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 0) some definitions and functions
#
set -e
sep='---------------------------------'
die ()
{
echo >&2 "$@"
exit 1
}
usage ()
{
echo "usage: <command>"
}
inPath='./projects/knora'
outPath='./src/data/documentation'
modules=('action' 'core' 'search' 'viewer')
jsdoc2json ()
{
arr=("$@")
for i in "${arr[@]}"
do
IFS='/' read -ra path <<< "$i"
# depth of path
num=( ${#path[@]} )
# echo ${num}
# module name
module=( ${path[3]} )
echo module: ${module}
# component name
# get filename from path
pos=$(( num-1 ))
# echo ${pos}
# filename
file=( ${path[${pos}]} )
IFS='.' read -ra names <<< "$file"
name=( ${names[0]} )
echo name: ${name}
# create json from jsdocs using dox
in=${i}
out=${outPath}/${module}/${name}.json
echo in: ${in}
echo out: ${out}
dox < ${in} > ${out}
echo ${sep}
done
}
if ! git diff-index --quiet HEAD --; then
die "Uncommited changes. Please commit your changes before running this script again."
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 1) create data documentation structure and copy all README files
#
# a) create data documentation folder if it doesn't exist
echo create data documentation folder
mkdir -p ${outPath}
echo ${sep}
# b) modules
for m in "${modules[@]}"
do
# create directory if it doesn't exist
echo create directory: ${m}
mkdir -p ${outPath}/${m}
echo copy module readme of ${m}
cp ${inPath}/${m}/README.md ${outPath}/${m}/readme.md
echo ${sep}
done
#
# c) demo app
# create directory if it doesn't exist
echo create directory: demo
mkdir -p ${outPath}/demo
echo copy readme of demo app
cp ./README.md ${outPath}/demo/readme.md
echo ${sep}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 2) update the documentation data from JSDocs of the ts files
#
# we should loop through the inPath to write the documentation data files as following:
#dox < projects/knora/action/src/lib/admin-image/admin-image.directive.ts > src/data/documentation/action/admin-image.json
# array of components
components=( $(find ${inPath} -iname "*.component.ts") )
jsdoc2json "${components[@]}"
# array of services
services=( $(find ${inPath} -iname "*.service.ts") )
jsdoc2json "${services[@]}"
# array of directive
directives=( $(find ${inPath} -iname "*.directive.ts") )
jsdoc2json "${directives[@]}"
# array of pipes
pipes=( $(find ${inPath} -iname "*.pipe.ts") )
jsdoc2json "${pipes[@]}"
# special files
special=( $(find ${inPath} -iname "convert-jsonld.ts") )
jsdoc2json "${special[@]}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 3) build the ng-app and update the files in docs/ folder
#
git rm -r docs/*
ng build --prod --base-href /dsp-ui/ --build-optimizer --aot --output-path docs
cp docs/index.html docs/404.html
git add docs/*
# if git diff-index --quiet HEAD --; then
# echo "You have to commit the changes in the documentation."
# git status
# fi