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
/
Copy pathdart.go
71 lines (55 loc) · 1.71 KB
/
dart.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 MainDartContent(platform string) string {
return Content("src/main.dart", platform+"-dart", "", "")
}
func PubspecFileContent(botName, platform string) string {
return Content("pubspec.yaml", platform+"-dart", botName, "")
}
func DartTemplate(botName, platform string) {
dartPath, err := looker.LookPath("dart")
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" dart is not installed"))
} else {
mainFile := os.WriteFile(filepath.Join(botName, "src", "main.dart"), []byte(MainDartContent(platform)), 0644)
pubspecFile := os.WriteFile(filepath.Join(botName, "pubspec.yaml"), []byte(PubspecFileContent(botName, platform)), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, "dart.dockerfile", platform)), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources(platform, "dart.md")), 0644)
if mainFile != nil {
log.Fatal(mainFile)
}
if pubspecFile != nil {
log.Fatal(pubspecFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
dartGet := dartPath + " pub get"
getCmd := exec.Command("bash", "-c", dartGet)
if runtime.GOOS == "windows" {
getCmd = exec.Command("powershell.exe", dartGet)
}
getCmd.Dir = botName
getCmd.Stdin = os.Stdin
getCmd.Stdout = os.Stdout
getCmd.Stderr = os.Stderr
err = getCmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, platform)
}
}