diff --git a/exec.go b/exec.go index eadaab4..9a99878 100644 --- a/exec.go +++ b/exec.go @@ -39,7 +39,7 @@ func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (s case <-stop: // Stop running command cmd.Process.Kill() - return "killed", nil + return msgStop, nil case err := <-done: // Command completed if err != nil { @@ -77,14 +77,14 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) { if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))); err == nil { build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)), args...) - } else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)) + ".exe"); err == nil { - build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+".exe", args...) + } else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)) + extWindows); err == nil { + build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+extWindows, args...) } else { path := filepath.Join(p.base, filepath.Base(p.path)) if _, err = os.Stat(path); err == nil { build = exec.Command(path, args...) - } else if _, err = os.Stat(path + ".exe"); err == nil { - build = exec.Command(path+".exe", args...) + } else if _, err = os.Stat(path + extWindows); err == nil { + build = exec.Command(path+extWindows, args...) } else { p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"}) p.fatal(nil, "Can't run a not compiled project", ":") diff --git a/exec_test.go b/exec_test.go index 6a511cc..8599c4f 100644 --- a/exec_test.go +++ b/exec_test.go @@ -20,7 +20,7 @@ func TestProject_GoCompile(t *testing.T) { close(stop) select { case v := <-response: - if v != "killed" { + if v != msgStop { t.Error("Unexpected result", response) } case <-time.After(2 * time.Second): diff --git a/watcher.go b/watcher.go index 305f0a3..aab8193 100644 --- a/watcher.go +++ b/watcher.go @@ -21,6 +21,11 @@ var ( wg sync.WaitGroup ) +const ( + msgStop = "killed" + extWindows = extWindows +) + // Watch struct defines options for livereload type Watch struct { Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"` @@ -215,7 +220,7 @@ func (p *Project) compile(stop <-chan bool, cmd Cmd) error { go func() { log.Println(p.pname(p.Name, 1), ":", cmd.startTxt) stream, err := p.goCompile(stop, cmd.method, cmd.Args) - if stream != "killed" { + if stream != msgStop { channel <- Result{stream, err} } }()