This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kotlin.go
111 lines (86 loc) · 3.11 KB
/
kotlin.go
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
package templates
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/abdfnx/botway/constants"
"github.com/abdfnx/looker"
)
func MainKtContent(platform string) string {
return Content("app/src/main/kotlin/core/Bot.kt", platform+"-kotlin", "", "")
}
func BuildGradleKtsContent(platform string) string {
return Content("app/build.gradle.kts", platform+"-kotlin", "", "")
}
func SettingsGradleKts() string {
return Content("settings.gradle.kts", "discord-kotlin", "", "")
}
func KotlinTemplate(botName, platform string) {
createDirs(botName, "kotlin", platform)
gradle, err := looker.LookPath("gradle")
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" gradle is not wrappered"))
} else {
botlinFile := os.WriteFile(filepath.Join(botName, "app", "src", "main", "kotlin", "botway", "Botway.kt"), []byte(BotlinContent()), 0644)
mainFile := os.WriteFile(filepath.Join(botName, "app", "src", "main", "kotlin", "core", "Bot.kt"), []byte(MainKtContent(platform)), 0644)
buildGradleFile := os.WriteFile(filepath.Join(botName, "app", "build.gradle.kts"), []byte(BuildGradleKtsContent(platform)), 0644)
gradleWrapperPropsFile := os.WriteFile(filepath.Join(botName, "gradle", "wrapper", "gradle-wrapper.properties"), []byte(GradleWrapperPropsContent()), 0644)
gradlewFile := os.WriteFile(filepath.Join(botName, "gradlew"), []byte(GradlewContent()), 0644)
gradlewBatFile := os.WriteFile(filepath.Join(botName, "gradlew.bat"), []byte(GradlewBatContent()), 0644)
settingsFile := os.WriteFile(filepath.Join(botName, "settings.gradle.kts"), []byte(SettingsGradleKts()), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, "gradle.dockerfile", platform)), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources(platform, "kotlin.md")), 0644)
gitattributesFile := os.WriteFile(filepath.Join(botName, ".gitattributes"), []byte(DotGitattributesContent()), 0644)
if botlinFile != nil {
log.Fatal(botlinFile)
}
if mainFile != nil {
log.Fatal(mainFile)
}
if buildGradleFile != nil {
log.Fatal(buildGradleFile)
}
if gradleWrapperPropsFile != nil {
log.Fatal(gradleWrapperPropsFile)
}
if gradlewFile != nil {
log.Fatal(gradlewFile)
}
if gradlewBatFile != nil {
log.Fatal(gradlewBatFile)
}
if settingsFile != nil {
log.Fatal(settingsFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
if gitattributesFile != nil {
log.Fatal(gitattributesFile)
}
gradleWrapper := gradle + " wrapper"
wrapperCmd := exec.Command("bash", "-c", gradleWrapper)
if runtime.GOOS == "windows" {
wrapperCmd = exec.Command("powershell.exe", gradleWrapper)
}
wrapperCmd.Dir = botName
wrapperCmd.Stdin = os.Stdin
wrapperCmd.Stdout = os.Stdout
wrapperCmd.Stderr = os.Stderr
err = wrapperCmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, platform)
}
}