Auto generate the whole doc index file
This commit is contained in:
parent
f4e58619c5
commit
5da0593818
|
@ -1,17 +1,20 @@
|
|||
<!-- THIS FILE IS AUTOGENERATED BY ./scripts/update_docs_index.sh -->
|
||||
|
||||
# teeworlds_network
|
||||
|
||||
Version v0.0.1
|
||||
|
||||
## Classes
|
||||
|
||||
### [ChatMessage](classes/ChatMessage.md)
|
||||
|
||||
### [Snapshot](classes/Snapshot.md)
|
||||
### [ChatMessage](classes/ChatMessage.md)
|
||||
|
||||
### [Context](classes/Context.md)
|
||||
|
||||
### [Player](classes/Player.md)
|
||||
|
||||
### [Snapshot](classes/Snapshot.md)
|
||||
|
||||
### [TeeworldsClient](classes/TeeworldsClient.md)
|
||||
|
||||
[#on_disconnect(&block)](classes/TeeworldsClient.md#on_disconnect)
|
||||
|
|
|
@ -9,6 +9,14 @@ fi
|
|||
|
||||
tmpdir=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
|
||||
|
||||
|
@ -23,42 +31,48 @@ do
|
|||
fi
|
||||
done
|
||||
|
||||
function print_hooks() {
|
||||
local version="$1"
|
||||
function print_instance_methods() {
|
||||
local class="$1"
|
||||
local hook
|
||||
local hook_slug
|
||||
while read -r hook
|
||||
do
|
||||
hook_slug="${hook%%(*}"
|
||||
echo ""
|
||||
echo "[#$hook](classes/TeeworldsClient.md#$hook_slug)"
|
||||
done < <(grep '###' "docs/$version/classes/TeeworldsClient.md" | cut -d'#' -f5)
|
||||
echo "[#$hook](classes/$class.md#$hook_slug)"
|
||||
done < <(grep '### <a name="' "docs/$version/classes/$class.md" | cut -d'#' -f5)
|
||||
}
|
||||
|
||||
function gen_doc_index() {
|
||||
local version="$1"
|
||||
function list_classes() {
|
||||
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"
|
||||
if [ ! -f "$index_file" ]
|
||||
then
|
||||
echo "Error: missing index file $index_file"
|
||||
exit 1
|
||||
fi
|
||||
local tmpfile="$tmpdir/README.md"
|
||||
{
|
||||
awk '1;/TeeworldsClient/{exit}' "$index_file"
|
||||
print_hooks "$version"
|
||||
} > "$tmpfile"
|
||||
if [ "$arg_generate_docs" == "1" ]
|
||||
then
|
||||
mv "$tmpfile" "$index_file"
|
||||
return
|
||||
fi
|
||||
local diff
|
||||
if ! diff="$(diff "$tmpfile" "$index_file")"
|
||||
then
|
||||
echo "Error: failed to check diff"
|
||||
exit 1
|
||||
fi
|
||||
echo "$tmpfile" "$index_file"
|
||||
diff="$(diff "$tmpfile" "$index_file")"
|
||||
if [ "$diff" != "" ]
|
||||
then
|
||||
echo "Error: documentation index is not up to date"
|
||||
|
@ -70,14 +84,19 @@ function gen_doc_index() {
|
|||
}
|
||||
|
||||
function main() {
|
||||
local version
|
||||
version="$(grep TEEWORLDS_NETWORK_VERSION lib/version.rb | cut -d"'" -f2)"
|
||||
if [ "$version" == "" ]
|
||||
then
|
||||
echo "Error: failed to get library version"
|
||||
exit 1
|
||||
fi
|
||||
gen_doc_index "$version"
|
||||
cat <<- EOF > "$tmpfile"
|
||||
<!-- THIS FILE IS AUTOGENERATED BY ./scripts/update_docs_index.sh -->
|
||||
|
||||
# teeworlds_network
|
||||
|
||||
Version $version
|
||||
|
||||
## Classes
|
||||
|
||||
EOF
|
||||
list_classes
|
||||
check_diff_or_fix
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
|
|
Loading…
Reference in a new issue