Auto generate the whole doc index file

This commit is contained in:
ChillerDragon 2023-09-17 14:12:40 +02:00
parent f4e58619c5
commit 5da0593818
2 changed files with 48 additions and 26 deletions

View file

@ -1,17 +1,20 @@
<!-- THIS FILE IS AUTOGENERATED BY ./scripts/update_docs_index.sh -->
# teeworlds_network # teeworlds_network
Version v0.0.1 Version v0.0.1
## Classes ## Classes
### [ChatMessage](classes/ChatMessage.md)
### [Snapshot](classes/Snapshot.md) ### [ChatMessage](classes/ChatMessage.md)
### [Context](classes/Context.md) ### [Context](classes/Context.md)
### [Player](classes/Player.md) ### [Player](classes/Player.md)
### [Snapshot](classes/Snapshot.md)
### [TeeworldsClient](classes/TeeworldsClient.md) ### [TeeworldsClient](classes/TeeworldsClient.md)
[#on_disconnect(&block)](classes/TeeworldsClient.md#on_disconnect) [#on_disconnect(&block)](classes/TeeworldsClient.md#on_disconnect)

View file

@ -9,6 +9,14 @@ fi
tmpdir=scripts/tmp tmpdir=scripts/tmp
mkdir -p scripts/tmp mkdir -p scripts/tmp
tmpfile="$tmpdir/README.md"
version="$(grep TEEWORLDS_NETWORK_VERSION lib/version.rb | cut -d"'" -f2)"
if [ "$version" == "" ]
then
echo "Error: failed to get library version"
exit 1
fi
arg_generate_docs=0 arg_generate_docs=0
@ -23,42 +31,48 @@ do
fi fi
done done
function print_hooks() { function print_instance_methods() {
local version="$1" local class="$1"
local hook local hook
local hook_slug local hook_slug
while read -r hook while read -r hook
do do
hook_slug="${hook%%(*}" hook_slug="${hook%%(*}"
echo "" echo ""
echo "[#$hook](classes/TeeworldsClient.md#$hook_slug)" echo "[#$hook](classes/$class.md#$hook_slug)"
done < <(grep '###' "docs/$version/classes/TeeworldsClient.md" | cut -d'#' -f5) done < <(grep '### <a name="' "docs/$version/classes/$class.md" | cut -d'#' -f5)
} }
function gen_doc_index() { function list_classes() {
local version="$1" local class_path
local class_name
for class_path in ./docs/"$version"/classes/*.md
do
class_name="$(basename "$class_path" .md)"
class_path="$(echo "$class_path" | cut -d'/' -f4-)"
{
echo ""
echo "### [$class_name]($class_path)"
print_instance_methods "$class_name"
} >> "$tmpfile"
done
}
function check_diff_or_fix() {
local index_file="docs/$version/README.md" local index_file="docs/$version/README.md"
if [ ! -f "$index_file" ] if [ ! -f "$index_file" ]
then then
echo "Error: missing index file $index_file" echo "Error: missing index file $index_file"
exit 1 exit 1
fi fi
local tmpfile="$tmpdir/README.md"
{
awk '1;/TeeworldsClient/{exit}' "$index_file"
print_hooks "$version"
} > "$tmpfile"
if [ "$arg_generate_docs" == "1" ] if [ "$arg_generate_docs" == "1" ]
then then
mv "$tmpfile" "$index_file" mv "$tmpfile" "$index_file"
return return
fi fi
local diff local diff
if ! diff="$(diff "$tmpfile" "$index_file")" echo "$tmpfile" "$index_file"
then diff="$(diff "$tmpfile" "$index_file")"
echo "Error: failed to check diff"
exit 1
fi
if [ "$diff" != "" ] if [ "$diff" != "" ]
then then
echo "Error: documentation index is not up to date" echo "Error: documentation index is not up to date"
@ -70,14 +84,19 @@ function gen_doc_index() {
} }
function main() { function main() {
local version cat <<- EOF > "$tmpfile"
version="$(grep TEEWORLDS_NETWORK_VERSION lib/version.rb | cut -d"'" -f2)" <!-- THIS FILE IS AUTOGENERATED BY ./scripts/update_docs_index.sh -->
if [ "$version" == "" ]
then # teeworlds_network
echo "Error: failed to get library version"
exit 1 Version $version
fi
gen_doc_index "$version" ## Classes
EOF
list_classes
check_diff_or_fix
} }
main main