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