forked from GDQuest/gdscript-docs-maker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_reference.bat
94 lines (76 loc) · 2.54 KB
/
generate_reference.bat
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
@echo off
:: Usage: windows.bat path\to\project [project-name]
:: Project name is optional - will default to "project"
:: The project location must contain a project.godot file
:: Configuration: Modify ReferenceCollectorCLI.gd with paths relative to the project's res://
where /q godot*
if ERRORLEVEL 1 (
ECHO "Godot is missing from the PATH environment."
EXIT /B
)
where /q python*
IF ERRORLEVEL 1 (
ECHO "Python is missing from the PATH environment."
EXIT /B
)
for /f "delims=" %%F in ('where godot*') do set godot="%%F"
set project_path=%1
IF NOT EXIST "%project_path%\project.godot" (
echo Could not find a project.godot in %project_path%. This program needs a Godot project to work.
EXIT /B
)
IF [%2] == [] (
set project_name=project
) else (
set project_name=%2
)
IF NOT EXIST "%project_name%" (
:: Creates the directory with project name.
mkdir "%project_name%"
)
set gdscript_path=godot-scripts
set gdscript_1=ReferenceCollectorCLI.gd
set gdscript_2=Collector.gd
:: Copies the CLI gdscript to the project location so godot can find it in res://
copy /Y "%gdscript_path%\%gdscript_1%" "%project_path%\ReferenceCollectorCLI.gd" >nul
copy /Y "%gdscript_path%\%gdscript_2%" "%project_path%\Collector.gd" >nul
echo Generating reference...
:: Runs godot in editor mode, runs the script ReferenceCollectorCLI, and quits
%godot% -e -q -s --no-window --path "%project_path%" ReferenceCollectorCLI.gd >nul
:: Removes the CLI tool from the project.
erase /Q "%project_path%\ReferenceCollectorCLI.gd"
erase /Q "%project_path%\Collector.gd"
IF NOT EXIST "%project_path%\reference.json" (
echo There was an error generating the reference from godot.
EXIT /B
) else (
echo Done.
)
:: Empty current version of export if it exists
if EXIST export (
erase /Q export
)
echo Generating markdown files in %project_name%
:: Runs the markdown creator.
:: TODO: Skip the moving by having the python script output export into the project folder
python -m gdscript_docs_maker "%project_path%/reference.json"
IF NOT EXIST export (
goto :PythonError
) else (
for /F %%i in ('dir /b "export\*.*"') do (
goto :Success
)
:PythonError
echo Python module failed to create markdown exportribution
EXIT /B
)
:Success
IF EXIST "%project_name%" (
:: Move all files in export into project name export
erase /Q "%project_name%"
move /Y export\* "%project_name%" >nul
rmdir /q /s export
) ELSE (
:: Puts the resulting exportribution result into the project folder.
move /Y export "%project_name%"
)