Added logs info on WebSocket API
This commit is contained in:
parent
c785adb415
commit
434fe5f43e
|
@ -46,7 +46,7 @@ type realize struct {
|
|||
Blueprint c.Blueprint
|
||||
Server s.Server
|
||||
Files map[string]string
|
||||
Sync chan string
|
||||
Sync chan string
|
||||
}
|
||||
|
||||
// Application initialization
|
||||
|
@ -64,12 +64,12 @@ func init() {
|
|||
}
|
||||
r.Blueprint = c.Blueprint{
|
||||
Files: r.Files,
|
||||
Sync: r.Sync,
|
||||
Sync: r.Sync,
|
||||
}
|
||||
r.Server = s.Server{
|
||||
Blueprint: &r.Blueprint,
|
||||
Files: r.Files,
|
||||
Sync: r.Sync,
|
||||
Sync: r.Sync,
|
||||
}
|
||||
r.Increase()
|
||||
R = &r
|
||||
|
|
|
@ -16,6 +16,10 @@ import (
|
|||
// GoRun is an implementation of the bin execution
|
||||
func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error {
|
||||
|
||||
sync := func() {
|
||||
p.parent.Sync <- "sync"
|
||||
}
|
||||
|
||||
var build *exec.Cmd
|
||||
if len(p.Params) != 0 {
|
||||
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...)
|
||||
|
@ -25,9 +29,12 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
|||
build.Dir = p.base
|
||||
defer func() {
|
||||
if err := build.Process.Kill(); err != nil {
|
||||
p.Buffer.StdLog = append(p.Buffer.StdLog, "Failed to stop: "+err.Error())
|
||||
log.Fatal(Red("Failed to stop: "), Red(err))
|
||||
}
|
||||
p.Buffer.StdLog = append(p.Buffer.StdLog, "Ended")
|
||||
log.Println(pname(p.Name, 2), ":", RedS("Ended"))
|
||||
go sync()
|
||||
wr.Done()
|
||||
}()
|
||||
|
||||
|
@ -56,7 +63,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
|||
} else {
|
||||
p.Buffer.StdOut = append(p.Buffer.StdOut, output.Text())
|
||||
}
|
||||
go func() { p.parent.Sync <- "sync" }()
|
||||
go sync()
|
||||
|
||||
if p.Watcher.Output["cli"] {
|
||||
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
|
||||
|
|
26
cli/main.go
26
cli/main.go
|
@ -31,19 +31,19 @@ type Blueprint struct {
|
|||
|
||||
// Project defines the informations of a single project
|
||||
type Project struct {
|
||||
reload time.Time
|
||||
base string
|
||||
Name string `yaml:"app_name,omitempty"`
|
||||
Path string `yaml:"app_path,omitempty"`
|
||||
Run bool `yaml:"app_run,omitempty"`
|
||||
Bin bool `yaml:"app_bin,omitempty"`
|
||||
Build bool `yaml:"app_build,omitempty"`
|
||||
Fmt bool `yaml:"app_fmt,omitempty"`
|
||||
Test bool `yaml:"app_test,omitempty"`
|
||||
Params []string `yaml:"app_params,omitempty"`
|
||||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
||||
Buffer Buffer `yaml:"-"`
|
||||
parent *Blueprint
|
||||
LastChangedOn time.Time
|
||||
base string
|
||||
Name string `yaml:"app_name,omitempty"`
|
||||
Path string `yaml:"app_path,omitempty"`
|
||||
Run bool `yaml:"app_run,omitempty"`
|
||||
Bin bool `yaml:"app_bin,omitempty"`
|
||||
Build bool `yaml:"app_build,omitempty"`
|
||||
Fmt bool `yaml:"app_fmt,omitempty"`
|
||||
Test bool `yaml:"app_test,omitempty"`
|
||||
Params []string `yaml:"app_params,omitempty"`
|
||||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
||||
Buffer Buffer `yaml:"-"`
|
||||
parent *Blueprint
|
||||
}
|
||||
|
||||
// Watcher struct defines the livereload's logic
|
||||
|
|
|
@ -43,13 +43,13 @@ func (p *Project) watching() {
|
|||
}
|
||||
|
||||
go p.routines(channel, &wr)
|
||||
p.reload = time.Now().Truncate(time.Second)
|
||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
||||
|
||||
// waiting for an event
|
||||
for {
|
||||
select {
|
||||
case event := <-watcher.Events:
|
||||
if time.Now().Truncate(time.Second).After(p.reload) {
|
||||
if time.Now().Truncate(time.Second).After(p.LastChangedOn) {
|
||||
if event.Op&fsnotify.Chmod == fsnotify.Chmod {
|
||||
continue
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func (p *Project) watching() {
|
|||
log.Fatal(Red(err))
|
||||
} else {
|
||||
go p.routines(channel, &wr)
|
||||
p.reload = time.Now().Truncate(time.Second)
|
||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,9 @@ func (s *Server) Start() {
|
|||
e := echo.New()
|
||||
e.Use(middleware.Gzip())
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.JSON(200, s.Blueprint.Projects)
|
||||
//return render(c, "server/assets/index.html")
|
||||
})
|
||||
|
||||
e.GET("/projects", standard.WrapHandler(s.projects()))
|
||||
e.GET("/", standard.WrapHandler(s.projects()))
|
||||
go e.Run(standard.New(":5000"))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue