-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
executable file
·125 lines (110 loc) · 5.32 KB
/
setup.bat
File metadata and controls
executable file
·125 lines (110 loc) · 5.32 KB
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
@echo off
setlocal enabledelayedexpansion
:: Load config values
set CONFIG_FILE=setup.config
if not exist "%CONFIG_FILE%" (
echo %CONFIG_FILE% file not found
exit /b 1
)
:: Read values from config file
set "MOD_ID="
set "MOD_NAME="
set "MAVEN_GROUP="
set "ACCESS_WIDENER="
set "MIXIN="
set "USE_CONFIG="
for /f "tokens=1,2 delims==" %%A in (%CONFIG_FILE%) do (
set "key=%%A"
set "value=%%B"
set "key=!key: =!"
set "value=!value: =!"
if "!key!"=="mod_id" set "MOD_ID=!value!"
if "!key!"=="mod_name" set "MOD_NAME=!value!"
if "!key!"=="maven_group" set "MAVEN_GROUP=!value!"
if "!key!"=="access_widener" set "ACCESS_WIDENER=!value!"
if "!key!"=="mixin" set "MIXIN=!value!"
if "!key!"=="use_pistonlib_config" set "USE_CONFIG=!value!"
)
if "%MOD_ID%"=="" (
echo mod_id is not set in %CONFIG_FILE%.
exit /b 1
)
if "%MOD_NAME%"=="" (
echo mod_name is not set in %CONFIG_FILE%.
exit /b 1
)
if "%MAVEN_GROUP%"=="" (
echo maven_group is not set in %CONFIG_FILE%.
exit /b 1
)
:: Handle accessWidener
if "%ACCESS_WIDENER%"!="true" (
powershell -Command "(Get-Content 'build.gradle') | Where-Object {$_ -notmatch 'src/main/resources/pistonmodtemplate.accesswidener'} | Set-Content 'build.gradle'"
powershell -Command "(Get-Content 'src/main/resources/fabric.mod.json') | Where-Object {$_ -notmatch 'pistonmodtemplate.accesswidener'} | Set-Content 'src/main/resources/fabric.mod.json'"
if exist src\main\resources\pistonmodtemplate.accesswidener del src\main\resources\pistonmodtemplate.accesswidener
)
:: Handle mixin
if "%MIXIN%"!="true" (
powershell -Command "(Get-Content 'src/main/resources/fabric.mod.json') | Where-Object {$_ -notmatch 'pistonmodtemplate.mixins.json'} | Set-Content 'src/main/resources/fabric.mod.json'"
if exist src\main\resources\pistonmodtemplate.mixins.json del src\main\resources\pistonmodtemplate.mixins.json
)
if "%MIXIN%"=="true" (
mkdir "src/main/java/ca/fxco/pistonmodtemplate/mixin"
)
:: Handle use_pistonlib_config
if "%USE_CONFIG%"!="true" (
if exist src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplateConfig.java del src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplateConfig.java
if exist src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplatePistonLibConfig.java del src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplatePistonLibConfig.java
:: Remove pistonlib-configfield block in fabric.mod.json
powershell -Command "$lines = Get-Content 'src/main/resources/fabric.mod.json'; $i = 0; $newLines = @(); while ($i -lt $lines.Length) { if ($lines[$i] -match 'pistonlib-configfield') { $i += 3 } else { $newLines += $lines[$i]; $i++ } }; $newLines | Set-Content 'src/main/resources/fabric.mod.json'"
:: TODO - Figure out how to remove the trailing comma
)
if "%USE_CONFIG%"=="true" (
:: Replace PistonModTemplate with PistonModTemplatePistonLibConfig
if exist src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplate.java del src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplate.java
ren src\main\java\ca\fxco\pistonmodtemplate\PistonModTemplatePistonLibConfig.java PistonModTemplate.java
powershell -Command "(Get-Content 'src/main/java/ca/fxco/pistonmodtemplate/PistonModTemplate.java') -replace 'PistonModTemplatePistonLibConfig', 'PistonModTemplate' | Set-Content 'src/main/java/ca/fxco/pistonmodtemplate/PistonModTemplate.java'"
powershell -Command "(Get-Content 'src/main/java/ca/fxco/pistonmodtemplate/PistonModTemplate.java') | Where-Object {$_ -notmatch 'THIS CLASS IS ONLY USED DURING THE SETUP'} | Set-Content 'src/main/java/ca/fxco/pistonmodtemplate/PistonModTemplate.java'"
)
:: Rename directories
for /d /r %%D in (*pistonmodtemplate*) do (
set "newdir=%%D"
set "newdir=!newdir:pistonmodtemplate=%MOD_ID%!"
if not "%%D"=="!newdir!" ren "%%D" "!newdir!"
)
:: Rename files mod_id
for /r %%F in (*pistonmodtemplate*) do (
set "newfile=%%F"
set "newfile=!newfile:pistonmodtemplate=%MOD_ID%!"
if not "%%F"=="!newfile!" ren "%%F" "!newfile!"
)
:: Rename files mod_name
for /r %%F in (*PistonModTemplate*) do (
set "newfile=%%F"
set "newfile=!newfile:PistonModTemplate=%MOD_NAME%!"
if not "%%F"=="!newfile!" ren "%%F" "!newfile!"
)
:: Replace mod_id occurrences in files
for /r %%F in (*) do (
powershell -Command "(Get-Content '%%F') -replace 'pistonmodtemplate', '%MOD_ID%' | Set-Content '%%F'"
)
:: Replace mod_name occurrences in files
for /r %%F in (*) do (
powershell -Command "(Get-Content '%%F') -replace 'PistonModTemplate', '%MOD_NAME%' | Set-Content '%%F'"
)
:: Change Maven Group
if not "%MAVEN_GROUP%"=="ca.fxco" (
set "OLD_PACKAGE_PATH=ca.fxco"
set "NEW_PACKAGE_PATH=%MAVEN_GROUP:.=\%"
mkdir "src\main\java\%NEW_PACKAGE_PATH%"
move "src\main\java\%OLD_PACKAGE_PATH%\*" "src\main\java\%NEW_PACKAGE_PATH%"
rmdir /s /q "src\main\java\%OLD_PACKAGE_PATH%"
for /r %%F in (src\main\java\*) do (
powershell -Command "(Get-Content '%%F') | Where-Object { $_ -notmatch 'ca\.fxco\.pistonlib' } | ForEach-Object { $_ -replace 'ca\.fxco', '%MAVEN_GROUP%' } | Set-Content '%%F'"
)
:: Replace maven_group in gradle.properties
powershell -Command "(Get-Content gradle.properties) -replace 'ca\.fxco', '%MAVEN_GROUP%' | Set-Content gradle.properties"
)
:: Remove setup files
del /f /q "setup.bat" "setup.sh" "setup.config"
echo Setup completed successfully.