-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate-docs.sh
executable file
·48 lines (37 loc) · 1.35 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
#!/usr/bin/env bash
set -e
get_realpath() {
local target_file="$1"
# Check if 'realpath' exists
if command -v realpath >/dev/null 2>&1; then
realpath "$target_file"
elif command -v grealpath >/dev/null 2>&1; then
grealpath "$target_file"
else
echo "Neither realpath nor grealpath is installed. Exiting."
exit 1
fi
}
readonly BASEDIR="$(dirname -- "$0")"
readonly REPOROOT="$(get_realpath "$BASEDIR/../..")"
readonly GENOPENAPI="$(get_realpath "$REPOROOT/src/scripts/generate-openapi.sh")"
readonly DOCSDIR="$(get_realpath "$REPOROOT/src/docs")"
readonly TEMPLATESDIR="$(get_realpath "$DOCSDIR/macros")"
DATA_API_FILE="$(mktemp)"
exec 3>"$DATA_API_FILE"
exec 4<"$DATA_API_FILE"
rm "$DATA_API_FILE"
$GENOPENAPI -a >&3
DATA_CONST="$(cat "$DOCSDIR/constants.json")"
DATA="$(jq -s '. | add' <(cat <&4 | jq '.') <(echo "$DATA_CONST" | jq '{ "const": . }'))"
for file in "$REPOROOT"/[a-zA-Z]*/README.md.tera; do
dir="$(dirname -- "$file")"
namespace="$(basename -- "$dir")"
echo "$DATA" | tera --include-path "$TEMPLATESDIR" --template "$file" --stdin > "$dir/README.md"
git add "$dir/README.md"
done
for file in "$DOCSDIR"/*.tera; do
filename="$(basename -- "$file")"
echo "$DATA" | tera --include-path "$TEMPLATESDIR" --template "$file" --stdin > "$REPOROOT/${filename%.tera}"
git add "$REPOROOT/${filename%.tera}"
done