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
/
csharp.go
71 lines (55 loc) · 1.74 KB
/
csharp.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
package templates
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/abdfnx/botway/constants"
"github.com/abdfnx/looker"
)
func MainCsContent(platform string) string {
return Content("src/Main.cs", platform+"-csharp", "", "")
}
func BotCSharpProj(platform string) string {
return Content(platform+"-csharp.csproj", platform+"-csharp", "", "")
}
func CsharpTemplate(botName, platform string) {
dotnetPath, err := looker.LookPath("dotnet")
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" dotnet is not installed"))
} else {
mainFile := os.WriteFile(filepath.Join(botName, "src", "Main.cs"), []byte(MainCsContent(platform)), 0644)
csprojFile := os.WriteFile(filepath.Join(botName, botName+".csproj"), []byte(BotCSharpProj(platform)), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, "csharp.dockerfile", platform)), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources(platform, "csharp.md")), 0644)
if mainFile != nil {
log.Fatal(mainFile)
}
if csprojFile != nil {
log.Fatal(csprojFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
dotNetRestore := dotnetPath + " restore"
restoreCmd := exec.Command("bash", "-c", dotNetRestore)
if runtime.GOOS == "windows" {
restoreCmd = exec.Command("powershell.exe", dotNetRestore)
}
restoreCmd.Dir = botName
restoreCmd.Stdin = os.Stdin
restoreCmd.Stdout = os.Stdout
restoreCmd.Stderr = os.Stderr
err = restoreCmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, platform)
}
}