Skip to content

Commit e986402

Browse files
committed
windows full support
1 parent 66431eb commit e986402

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

controllers/executables.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,36 @@ import (
55
"os/exec"
66
)
77

8-
func killProcess() {
9-
cmd := exec.Command("killall", "-9", "app-godemon-app-godemon-tmp-generated")
10-
cmd.Stdout = os.Stdout
11-
cmd.Stderr = os.Stderr
12-
err := cmd.Run()
13-
ErrorHandle(err)
8+
func killProcess(hOS string) {
9+
if hOS == "windows" {
10+
cmd := exec.Command("taskkill", "/IM", "app-godemon-app-godemon-tmp-generated.exe", "/F")
11+
cmd.Stdout = os.Stdout
12+
cmd.Stderr = os.Stderr
13+
err := cmd.Run()
14+
ErrorHandle(err)
15+
} else {
16+
cmd := exec.Command("killall", "-9", "app-godemon-app-godemon-tmp-generated")
17+
cmd.Stdout = os.Stdout
18+
cmd.Stderr = os.Stderr
19+
err := cmd.Run()
20+
ErrorHandle(err)
21+
}
1422
}
1523

16-
func execMOD() {
17-
cmd := exec.Command("./app-godemon-app-godemon-tmp-generated")
18-
cmd.Stdout = os.Stdout
19-
cmd.Stderr = os.Stderr
20-
err := cmd.Run()
21-
ErrorHandle(err)
24+
func execMOD(hOS string) {
25+
if hOS == "windows" {
26+
cmd := exec.Command("app-godemon-app-godemon-tmp-generated.exe")
27+
cmd.Stdout = os.Stdout
28+
cmd.Stderr = os.Stderr
29+
err := cmd.Run()
30+
ErrorHandle(err)
31+
} else {
32+
cmd := exec.Command("./app-godemon-app-godemon-tmp-generated")
33+
cmd.Stdout = os.Stdout
34+
cmd.Stderr = os.Stderr
35+
err := cmd.Run()
36+
ErrorHandle(err)
37+
}
2238
}
2339

2440
func execFile(filepath string) {

controllers/functions.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010
)
1111

12-
func ExecMOD() {
12+
func ExecMOD(hOS string) {
1313
jsonFile, err := os.Open("project.json")
1414
ErrorHandle(err)
1515
defer jsonFile.Close()
@@ -22,7 +22,7 @@ func ExecMOD() {
2222
err = os.Setenv(pr.Vars[i].Key, pr.Vars[i].Value)
2323
ErrorHandle(err)
2424
}
25-
execMOD()
25+
execMOD(hOS)
2626
}
2727

2828
func ExecFile(filepath string) {
@@ -33,13 +33,13 @@ func TimeLog() {
3333
timeLog()
3434
}
3535

36-
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string, init bool, name string, oso string, arch string) (string, string) {
36+
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string, init bool, name string, oso string, arch string, hOS string) (string, string) {
3737
if *cnf == "cmd" {
3838

3939
} else if *cnf == "cnf" {
4040
filepath, modOrFile = cnfFunc(command, "", "")
4141
} else if *cnf == "deploy" {
42-
deploy(oso, arch)
42+
deploy(oso, arch, hOS)
4343
} else if init == true {
4444
if arch == "" && oso == "" {
4545
fmt.Println("\nPlease specify OS architecture and OS platform")
@@ -61,7 +61,7 @@ func ProgramStarting(cnf *string, filepath string, modOrFile string, command str
6161
return filepath, modOrFile
6262
}
6363

64-
func WatchFiles(fileordirPath string) error {
64+
func WatchFiles(fileordirPath string, hOS string) error {
6565
initialStat, err := os.Stat(fileordirPath)
6666
if err != nil {
6767
return err
@@ -72,7 +72,7 @@ func WatchFiles(fileordirPath string) error {
7272
return err
7373
}
7474
if stat.Size() != initialStat.Size() || stat.ModTime() != initialStat.ModTime() {
75-
killProcess()
75+
killProcess(hOS)
7676
break
7777
}
7878
time.Sleep(1 * time.Second)

controllers/pv.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"os/exec"
1010
)
1111

12-
func deploy(oso string, archL string) {
12+
func deploy(oso string, archL string, hOS string) {
1313
var goos string
1414
var arch string
1515
pr := loadProjectInfo()
@@ -23,6 +23,9 @@ func deploy(oso string, archL string) {
2323
goos = "GOOS=" + pr.OS
2424
arch = "GOARCH=" + pr.Arch
2525
}
26+
if hOS == "windows" {
27+
name = name + ".exe"
28+
}
2629
cmd := exec.Command("env", goos, arch, "go", "build", "-o", name)
2730
cmd.Stdout = os.Stdout
2831
cmd.Stderr = os.Stderr

main.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,42 @@ package main
33
import (
44
"fmt"
55
"github.com/fatih/color"
6+
"go/build"
67
"godemon/controllers"
78
"os"
89
"os/exec"
910
)
1011

1112
func main() {
12-
//hostInfo := [2]string{build.Default.GOOS, build.Default.GOARCH}
13+
hostInfo := [2]string{build.Default.GOOS, build.Default.GOARCH}
1314
color.Blue("Godemon starting...")
14-
version := "2.2.2"
15+
version := "2.5.2"
1516
doneChan := make(chan bool)
1617
filepath, modOrFile, cnf, command, help, init, name, oso, arch := controllers.LoadCMD("", "")
17-
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch)
18+
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch, hostInfo[0])
1819
for true {
1920
go func(doneChan chan bool) {
2021
defer func() {
2122
doneChan <- true
2223
}()
23-
err := controllers.WatchFiles(filepath)
24+
err := controllers.WatchFiles(filepath, hostInfo[0])
2425
controllers.ErrorHandle(err)
2526
fmt.Println("File has been changed")
2627
if modOrFile == "mod" {
2728
err = os.Chdir(filepath)
2829
controllers.ErrorHandle(err)
2930
controllers.TimeLog()
30-
cmd := exec.Command("go", "build", "-o", "app-godemon-app-godemon-tmp-generated")
31+
var cmd *exec.Cmd
32+
if hostInfo[0] != "windows" {
33+
cmd = exec.Command("go", "build", "-o", "app-godemon-app-godemon-tmp-generated")
34+
} else {
35+
cmd = exec.Command("go", "build", "-o", "app-godemon-app-godemon-tmp-generated.exe")
36+
}
3137
cmd.Stdout = os.Stdout
3238
cmd.Stderr = os.Stderr
3339
err = cmd.Run()
3440
controllers.ErrorHandle(err)
35-
go controllers.ExecMOD()
41+
go controllers.ExecMOD(hostInfo[0])
3642
} else if modOrFile == "file" {
3743
controllers.TimeLog()
3844
go controllers.ExecFile(filepath)

0 commit comments

Comments
 (0)