-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_reference
executable file
·168 lines (138 loc) · 5.22 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env sh
project_directory="$1"
output_directory="entities"
directories_override=""
create_index=""
verbosity_level=""
get_version=""
doc_version=""
echo_help() {
echo '
Generate reST file references 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.
-i/ -- Create a reST index file in the output directory that
references all the API reST files.
-v/--verbose -- Set the verbosity level.
For example -vv sets verbosity to level 2. Default: 0.
-V/--version -- Print the version number and exit.
--doc-version -- Set the document version number if there is no
version set in the JSON file. Defaults to 0.0.0
Usage example:
generate_reference ~/Repositories/other/nakama-godot/project/
-o docs/source/api/addons -d addons -i -v --doc-version 0.1.5
This command walks files in the res://addons directory of the Godot Nakama
project, and stores the resultant code dump in the docs/source/api/addons
directory of the current pwd. It then invokes gdscript2rest and creates
the reST files in the same directory, detailing each file processed, creating
an index file and setting the version to 0.1.5
'
exit 0
}
arguments=$(getopt --name "generate_reference" -o "h,o:,d:,i,v::,V" -l "help,output-directory:,directory:,verbose, doc-version:" -- "$@")
eval set -- "$arguments"
while true; do
case "$1" in
-h | --help)
echo_help
shift
;;
-o | --output-directory)
output_directory=$2
echo setting output directory to $output_directory
shift 2
;;
-d | --directory)
directories_override="$directories_override $2"
shift 2
;;
-i)
create_index=$1
shift
;;
-v)
verbosity_level=$1$2
shift 2
;;
--verbose)
verbosity_level=$1
shift 1
;;
-V | --version)
get_version=$1
shift 1
;;
--doc-version)
doc_version="--doc-version $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/(\",\/\")/\\\//g' | sed -r 's/,$//')
# echo "directories after first sed scan: " $args1
# echo $args1 | sed -r 's/(\",\/\")/\//g'
# args=$(echo $args1 | sed -r 's/,$//')
# echo "directories after second sed scan: " $args
sed -ri "s/^var directories.+/var directories := [$args]/" $file_ref_collector
fi
# echo $file_ref_collector
# exit
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)"
! test -d "$output_dir" && mkdir -v -p "$output_directory"
mv -v $godot_project_dir/reference.json $output_directory/reference.json
# Generate markdown files
echo "Generating reStructuredText files in $output_directory with options --path $output_directory $create_index $verbosity_level $get_version $doc_version"
python3 -m gdscript2rest "$output_directory/reference.json" --path $output_directory $create_index $verbosity_level $get_version $doc_version