generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 5
/
publishing.gradle
69 lines (53 loc) · 2.07 KB
/
publishing.gradle
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
import org.codehaus.groovy.runtime.MethodClosure
import java.util.regex.Pattern
static String getModrinthToken(Project project) {
File file = new File(project.getRootDir(), "modrinth_creds.txt")
if(file.isDirectory() || !file.exists()) {
System.err.println("Unable to find a Modrinth token! (Add a modrinth_creds.txt to root project dir)")
return ""
}
List<String> lines = file.readLines()
if(lines.size() == 0) {
System.err.println("Modrinth token file is empty!")
return ""
}
return lines.get(0)
}
static String getCurseToken(Project project) {
File file = new File(project.getRootDir(), "curse_creds.txt")
if(file.isDirectory() || !file.exists()) {
System.err.println("Unable to find a CurseForge token! (Add a curse_creds.txt to root project dir)")
return ""
}
List<String> lines = file.readLines()
if(lines.size() == 0) {
System.err.println("CurseForge token file is empty!")
return ""
}
return lines.get(0)
}
static String[] getSupportedVersions(Map<String, ?> properties) {
return properties.getOrDefault("supported_minecraft_versions", "")
.toString()
.split(Pattern.quote(","))
}
static String getFabricVersionString(Map<String, ?> properties) {
String[] versions = getSupportedVersions(properties)
return versions.size() > 0
? ">=%s".formatted(versions[0])
: "*"
}
static String getForgeVersionString(Map<String, ?> properties) {
String[] versions = getSupportedVersions(properties)
return versions.size() > 0
? "[%s,)".formatted(versions[0])
: "*"
}
//TODO: The type warnings and lack of autocomplete are annoying. Fix this.
ext {
getModrinthToken = this.&getModrinthToken as Closure<String>
getCurseToken = this.&getCurseToken as Closure<String>
getSupportedVersions = this.&getSupportedVersions as Closure<String[]>
getFabricVersionString = this.&getFabricVersionString as Closure<String>
getForgeVersionString = this.&getForgeVersionString as Closure<String>
}