decreased routines complexity
This commit is contained in:
parent
4664efe735
commit
989c898dbf
36
watcher.go
36
watcher.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -465,7 +466,6 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
|
||||||
// Routines launches the toolchain run, build, install
|
// Routines launches the toolchain run, build, install
|
||||||
func (p *Project) routines(stop <-chan bool, watcher FileWatcher, path string) {
|
func (p *Project) routines(stop <-chan bool, watcher FileWatcher, path string) {
|
||||||
var done bool
|
var done bool
|
||||||
var install, build error
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -475,28 +475,17 @@ func (p *Project) routines(stop <-chan bool, watcher FileWatcher, path string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if !done {
|
invoke(done,p.cmd,stop,"before",false)
|
||||||
// before command
|
invoke(done,p.tool,stop,path)
|
||||||
p.cmd(stop, "before", false)
|
// prevent init error on walk
|
||||||
}
|
|
||||||
if !done {
|
|
||||||
// Go supported tools
|
|
||||||
p.tool(stop, path)
|
|
||||||
// Prevent fake events on polling startup
|
|
||||||
p.init = true
|
p.init = true
|
||||||
}
|
|
||||||
// prevent errors using realize without config with only run flag
|
// prevent errors using realize without config with only run flag
|
||||||
if p.Cmds.Run && !p.Cmds.Install.Status && !p.Cmds.Build.Status {
|
if p.Cmds.Run && !p.Cmds.Install.Status && !p.Cmds.Build.Status {
|
||||||
p.Cmds.Install.Status = true
|
p.Cmds.Install.Status = true
|
||||||
}
|
}
|
||||||
if !done {
|
invoke(done,p.compile,stop,p.Cmds.Install)
|
||||||
install = p.compile(stop, p.Cmds.Install)
|
invoke(done,p.compile,stop,p.Cmds.Build)
|
||||||
}
|
if !done && p.Cmds.Run {
|
||||||
if !done {
|
|
||||||
build = p.compile(stop, p.Cmds.Build)
|
|
||||||
}
|
|
||||||
if !done && (install == nil && build == nil) {
|
|
||||||
if p.Cmds.Run {
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
runner := make(chan bool, 1)
|
runner := make(chan bool, 1)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -512,8 +501,17 @@ func (p *Project) routines(stop <-chan bool, watcher FileWatcher, path string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
invoke(done,p.cmd,stop,"after",false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke is used to exec func from routines and check done
|
||||||
|
func invoke(done bool, fn interface{}, args ...interface{}) {
|
||||||
if !done {
|
if !done {
|
||||||
p.cmd(stop, "after", false)
|
v := reflect.ValueOf(fn)
|
||||||
|
rargs := make([]reflect.Value, len(args))
|
||||||
|
for i, a := range args {
|
||||||
|
rargs[i] = reflect.ValueOf(a)
|
||||||
|
}
|
||||||
|
v.Call(rargs)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue