forked from GDQuest/gdscript-docs-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_reference
executable file
·129 lines (106 loc) · 4.03 KB
/
generate_reference
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
#!/usr/bin/env sh
project_directory="$1"
output_directory="export"
directories_override=""
format="markdown"
author="developer"
echo_help() {
echo '
Generate a code reference from GDScript
Usage:
generate_reference $project_directory [options]
Required arguments:
$project_directory -- path to your Godot project directory.
This directory or one of its subdirectories should contain a
project.godot file.
Options:
-h/--help -- Display this help message.
-o/--output-directory -- directory path to output the documentation into.
-d/--directory -- Name of a directory to find files and generate the code reference in the Godot project. You can use the option multiple times to generate a reference for multiple directories.
-f/--format -- Either `markdown` or `hugo`. If `hugo`, the output document includes a TOML front-matter at the top. Default: `markdown`.
-a/--author -- If --format is `hugo`, controls the author property in the TOML front-matter.
Usage example:
generate_reference ~/Repositories/other/nakama-godot/project/ -o export-nakama -d addons
This command walks files in the res://addons directory of the Godot Nakama project, and converts it
to markdown files output in ./export-nakama.
'
exit 0
}
arguments=$(getopt --name "generate_reference" -o "h,o:,d:,f:,a:" -l "help,output-directory:,directories:" -- "$@")
eval set -- "$arguments"
while true; do
case "$1" in
-h | --help)
echo_help
shift
;;
-o | --output-directory)
output_directory=$2
shift 2
;;
-d | --directory)
directories_override="$directories_override $2"
shift 2
;;
-f | --format)
format=$2
shift 2
;;
-a | --author)
author=$2
shift 2
;;
--)
shift
break
;;
*)
echo "Missing arguments. Try 'generate_reference --help' for more information"
exit 1
;;
esac
done
# Testing input parameters
if test -z "$project_directory"; then
echo "Missing first parameter: project_directory."
exit 1
fi
if ! test -d "$project_directory"; then
echo "Directory $project_directory does not exist, exiting."
exit 1
fi
godot_project_file=$(find "$project_directory" -iname project.godot -print -quit)
if ! test -f "$godot_project_file"; then
echo "Could not find a project.godot file in $project_directory. This program needs a Godot project to work."
exit 1
fi
# Generate reference JSON data from Godot
godot_project_dir=$(dirname "$godot_project_file")
path_ref_collector="godot-scripts/ReferenceCollectorCLI.gd"
path_collector="godot-scripts/Collector.gd"
# Overrides the content of the directories variable in ReferenceCollectorCLI.gd if we got --directory arguments
file_ref_collector=$(mktemp)
cat $path_ref_collector >$file_ref_collector
if test "$directories_override" != ""; then
args=$(echo $directories_override | sed -r 's/([-._a-zA-Z0-9]+)/"\1",/g' | sed -r 's/,$//')
sed -ri "s/^var directories.+/var directories := [$args]/" $file_ref_collector
fi
cp -v $file_ref_collector "$godot_project_dir/$(basename $path_ref_collector)"
cp -v $path_collector "$godot_project_dir"
echo "Generating reference json data..."
godot --editor --quit --script --no-window --path "$godot_project_dir" ReferenceCollectorCLI.gd >/dev/null
test $? -gt 0 && echo "There was an error running 'godot'.
The program 'godot' must be available on the system '\$PATH' variable for this program to work.
For more information, see https://en.wikipedia.org/wiki/PATH_(variable).
Exiting." && exit 1
echo "Done."
if ! test -f "$godot_project_dir/reference.json"; then
echo "There was an error generating the reference from Godot. The file $godot_project_dir/reference.json was not found."
exit 1
fi
rm -v "$godot_project_dir/$(basename $path_ref_collector)"
rm -v "$godot_project_dir/$(basename $path_collector)"
# Generate markdown files
echo "Generating markdown files in $output_directory"
! test -d "$output_directory" && mkdir -v "$output_directory"
python3 -m gdscript_docs_maker "$godot_project_dir/reference.json" --path $output_directory --format $format --author $author