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
/
swift.go
88 lines (68 loc) · 2.34 KB
/
swift.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
package templates
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/abdfnx/botway/constants"
"github.com/abdfnx/looker"
)
func MainSwiftContent(platform string) string {
return Content("Sources/bwbot/main.swift", platform+"-swift", "", "")
}
func BotwaySwiftContent(botName string) string {
return Content("packages/botway-swift/main.swift", "botway", botName, "")
}
func PackageSwiftFileContent(botName, platform string) string {
return Content("Package.swift", platform+"-swift", botName, "")
}
func SwiftTemplate(botName, platform string) {
swiftPath, err := looker.LookPath("swift")
if err := os.Mkdir(filepath.Join(botName, "Sources"), os.ModePerm); err != nil {
log.Fatal(err)
}
if err := os.Mkdir(filepath.Join(botName, "Sources", botName), os.ModePerm); err != nil {
log.Fatal(err)
}
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" swift is not installed"))
} else {
mainFile := os.WriteFile(filepath.Join(botName, "Sources", botName, "main.swift"), []byte(MainSwiftContent(platform)), 0644)
botwaySwiftFile := os.WriteFile(filepath.Join(botName, "Sources", botName, "botway.swift"), []byte(BotwaySwiftContent(botName)), 0644)
packageSwiftFile := os.WriteFile(filepath.Join(botName, "Package.swift"), []byte(PackageSwiftFileContent(botName, platform)), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, "swift.dockerfile", platform)), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources(platform, "swift.md")), 0644)
if mainFile != nil {
log.Fatal(mainFile)
}
if botwaySwiftFile != nil {
log.Fatal(botwaySwiftFile)
}
if packageSwiftFile != nil {
log.Fatal(packageSwiftFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
swiftBuild := swiftPath + " build"
installCmd := exec.Command("bash", "-c", swiftBuild)
if runtime.GOOS == "windows" {
installCmd = exec.Command("powershell.exe", swiftBuild)
}
installCmd.Dir = botName
installCmd.Stdin = os.Stdin
installCmd.Stdout = os.Stdout
installCmd.Stderr = os.Stderr
err = installCmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, platform)
}
}