2023-09-17 11:50:33 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ ! -d spec ]
|
|
|
|
then
|
|
|
|
echo "Error: spec folder not found"
|
|
|
|
echo " run this script from the root of repo"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
tmpdir=scripts/tmp
|
|
|
|
mkdir -p scripts/tmp
|
2023-09-17 12:12:40 +00:00
|
|
|
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
|
2023-09-17 11:50:33 +00:00
|
|
|
|
|
|
|
arg_generate_docs=0
|
|
|
|
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
if [ "$arg" == "--fix" ] || [ "$arg" == "--generate-docs" ]
|
|
|
|
then
|
|
|
|
arg_generate_docs=1
|
|
|
|
else
|
|
|
|
echo "usage: ./scripts/update_docs_index.sh [--fix]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-09-17 12:12:40 +00:00
|
|
|
function print_instance_methods() {
|
|
|
|
local class="$1"
|
2023-09-17 11:50:33 +00:00
|
|
|
local hook
|
|
|
|
local hook_slug
|
|
|
|
while read -r hook
|
|
|
|
do
|
|
|
|
hook_slug="${hook%%(*}"
|
2023-09-17 13:24:40 +00:00
|
|
|
hook_slug="${hook_slug%%\?*}"
|
2023-09-17 11:50:33 +00:00
|
|
|
echo ""
|
2023-09-17 12:12:40 +00:00
|
|
|
echo "[#$hook](classes/$class.md#$hook_slug)"
|
2023-09-17 15:31:10 +00:00
|
|
|
done < <(grep '### <a name="' "docs/classes/$class.md" | cut -d'#' -f5)
|
2023-09-17 11:50:33 +00:00
|
|
|
}
|
|
|
|
|
2023-09-17 12:12:40 +00:00
|
|
|
function list_classes() {
|
|
|
|
local class_path
|
|
|
|
local class_name
|
2023-09-17 15:31:10 +00:00
|
|
|
for class_path in ./docs/classes/*.md
|
2023-09-17 12:12:40 +00:00
|
|
|
do
|
|
|
|
class_name="$(basename "$class_path" .md)"
|
2023-09-17 15:31:10 +00:00
|
|
|
class_path="$(echo "$class_path" | cut -d'/' -f3-)"
|
2023-09-17 12:12:40 +00:00
|
|
|
{
|
|
|
|
echo ""
|
|
|
|
echo "### [$class_name]($class_path)"
|
|
|
|
print_instance_methods "$class_name"
|
|
|
|
} >> "$tmpfile"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_diff_or_fix() {
|
2023-09-17 15:31:10 +00:00
|
|
|
local index_file="docs/README.md"
|
2023-09-17 11:50:33 +00:00
|
|
|
if [ ! -f "$index_file" ]
|
|
|
|
then
|
|
|
|
echo "Error: missing index file $index_file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "$arg_generate_docs" == "1" ]
|
|
|
|
then
|
|
|
|
mv "$tmpfile" "$index_file"
|
|
|
|
return
|
|
|
|
fi
|
2023-09-17 11:54:24 +00:00
|
|
|
local diff
|
2023-09-17 12:12:40 +00:00
|
|
|
echo "$tmpfile" "$index_file"
|
|
|
|
diff="$(diff "$tmpfile" "$index_file")"
|
2023-09-17 11:50:33 +00:00
|
|
|
if [ "$diff" != "" ]
|
|
|
|
then
|
|
|
|
echo "Error: documentation index is not up to date"
|
|
|
|
echo " to fix this run ./scripts/update_docs_index.sh --fix"
|
|
|
|
echo ""
|
|
|
|
echo "$diff"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
2023-09-17 12:12:40 +00:00
|
|
|
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
|
2023-09-17 11:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main
|
2023-09-17 12:12:40 +00:00
|
|
|
|