fixed #31
This commit is contained in:
parent
249dca4dfb
commit
45bf555bd3
|
@ -16,21 +16,34 @@ import (
|
||||||
func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error {
|
func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error {
|
||||||
|
|
||||||
var build *exec.Cmd
|
var build *exec.Cmd
|
||||||
if len(p.Params) != 0 {
|
var params []string
|
||||||
var params []string
|
var path = ""
|
||||||
for _, param := range p.Params {
|
|
||||||
arr := strings.Fields(param)
|
for _, param := range p.Params {
|
||||||
params = append(params, arr...)
|
arr := strings.Fields(param)
|
||||||
}
|
params = append(params, arr...)
|
||||||
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)), params...)
|
}
|
||||||
} else {
|
if _, err := os.Stat(filepath.Join(p.base, p.path)); err == nil {
|
||||||
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)))
|
path = filepath.Join(p.base, p.path)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(p.base, p.path+".exe")); err == nil {
|
||||||
|
path = filepath.Join(p.base, p.path+".exe")
|
||||||
|
}
|
||||||
|
|
||||||
|
if path != "" {
|
||||||
|
build = exec.Command(path, params...)
|
||||||
|
} else {
|
||||||
|
if _, err := os.Stat(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))); err == nil {
|
||||||
|
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)), params...)
|
||||||
|
} else {
|
||||||
|
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"})
|
||||||
|
p.Fatal(err, "Can't run a not compiled project", ":")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
build.Dir = p.base
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := build.Process.Kill(); err != nil {
|
if err := build.Process.Kill(); err != nil {
|
||||||
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()})
|
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()})
|
||||||
p.Fatal("Failed to stop:", err)
|
p.Fatal(err, "Failed to stop", ":")
|
||||||
}
|
}
|
||||||
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Ended"})
|
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Ended"})
|
||||||
log.Println(p.pname(p.Name, 2), ":", p.Red.Regular("Ended"))
|
log.Println(p.pname(p.Name, 2), ":", p.Red.Regular("Ended"))
|
||||||
|
@ -72,7 +85,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
f := p.Create(path)
|
f := p.Create(path)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
|
||||||
p.Fatal("", err)
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,51 +84,47 @@ func (p *Project) watching() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install calls an implementation of the "go install"
|
// Install calls an implementation of the "go install"
|
||||||
func (p *Project) install(channel chan bool, wr *sync.WaitGroup) {
|
func (p *Project) install() {
|
||||||
defer func() {
|
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
if p.Bin {
|
if p.Bin {
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Installing..")
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
log.Println(p.pname(p.Name, 1), ":", "Installing..")
|
||||||
if stream, err := p.goInstall(); err != nil {
|
if stream, err := p.goInstall(); err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error()))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error()))
|
||||||
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream}
|
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream}
|
||||||
p.print("error", out, msg, stream)
|
p.print("error", out, msg, stream)
|
||||||
wr.Done()
|
|
||||||
} else {
|
} else {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
out := BufferOut{Time: time.Now(), Text: "Installed"}
|
out := BufferOut{Time: time.Now(), Text: "Installed"}
|
||||||
p.print("log", out, msg, stream)
|
p.print("log", out, msg, stream)
|
||||||
|
|
||||||
if p.Run {
|
|
||||||
runner := make(chan bool, 1)
|
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
|
||||||
start = time.Now()
|
|
||||||
go p.goRun(channel, runner, wr)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-runner:
|
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Has been run")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
|
||||||
out := BufferOut{Time: time.Now(), Text: "Has been run"}
|
|
||||||
p.print("log", out, msg, stream)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
p.sync()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
||||||
|
if p.Run {
|
||||||
|
start := time.Now()
|
||||||
|
runner := make(chan bool, 1)
|
||||||
|
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
||||||
|
go p.goRun(channel, runner, wr)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-runner:
|
||||||
|
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Has been run")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
|
out := BufferOut{Time: time.Now(), Text: "Has been run"}
|
||||||
|
p.print("log", out, msg, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build calls an implementation of the "go build"
|
// Build calls an implementation of the "go build"
|
||||||
func (p *Project) build() {
|
func (p *Project) build() {
|
||||||
defer func() {
|
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
if p.Build {
|
if p.Build {
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Building..")
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
log.Println(p.pname(p.Name, 1), ":", "Building..")
|
||||||
if stream, err := p.goBuild(); err != nil {
|
if stream, err := p.goBuild(); err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error()))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error()))
|
||||||
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream}
|
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream}
|
||||||
|
@ -138,6 +134,7 @@ func (p *Project) build() {
|
||||||
out := BufferOut{Time: time.Now(), Text: "Builded"}
|
out := BufferOut{Time: time.Now(), Text: "Builded"}
|
||||||
p.print("log", out, msg, stream)
|
p.print("log", out, msg, stream)
|
||||||
}
|
}
|
||||||
|
p.sync()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -281,9 +278,10 @@ func (p *Project) ignore(str string) bool {
|
||||||
|
|
||||||
// Routines launches the following methods: run, build, install
|
// Routines launches the following methods: run, build, install
|
||||||
func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) {
|
func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) {
|
||||||
|
p.install()
|
||||||
|
p.build()
|
||||||
wr.Add(1)
|
wr.Add(1)
|
||||||
go p.build()
|
go p.run(channel, wr)
|
||||||
go p.install(channel, wr)
|
|
||||||
wr.Wait()
|
wr.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +316,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
||||||
f := p.Create(path)
|
f := p.Create(path)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
||||||
p.Fatal("", err)
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "log":
|
case "log":
|
||||||
|
@ -328,7 +326,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
||||||
f := p.Create(path)
|
f := p.Create(path)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
||||||
p.Fatal("", err)
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "error":
|
case "error":
|
||||||
|
@ -338,7 +336,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
||||||
f := p.Create(path)
|
f := p.Create(path)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
|
||||||
p.Fatal("", err)
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue