bug fix
This commit is contained in:
parent
989c898dbf
commit
a18fb33cd5
14
cmd.go
14
cmd.go
@ -9,9 +9,9 @@ import (
|
|||||||
|
|
||||||
// Tool options customizable, should be moved in Cmd
|
// Tool options customizable, should be moved in Cmd
|
||||||
type tool struct {
|
type tool struct {
|
||||||
dir, status bool
|
name, err string
|
||||||
name, err string
|
cmd, options []string
|
||||||
cmd, options []string
|
dir, status bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cmds list of go commands
|
// Cmds list of go commands
|
||||||
@ -29,11 +29,11 @@ type Cmds struct {
|
|||||||
|
|
||||||
// Cmd single command fields and options
|
// Cmd single command fields and options
|
||||||
type Cmd struct {
|
type Cmd struct {
|
||||||
Status bool `yaml:"status,omitempty" json:"status,omitempty"`
|
|
||||||
Method string `yaml:"method,omitempty" json:"method,omitempty"`
|
Method string `yaml:"method,omitempty" json:"method,omitempty"`
|
||||||
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
|
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
|
||||||
method []string
|
Status bool `yaml:"status,omitempty" json:"status,omitempty"`
|
||||||
tool bool
|
tool bool
|
||||||
|
method []string
|
||||||
name, startTxt, endTxt string
|
name, startTxt, endTxt string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ func (r *realize) clean() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a new project
|
// Add a new project
|
||||||
func (r *realize) add(p *cli.Context) (err error) {
|
func (r *realize) add(p *cli.Context) (err error) {
|
||||||
var path string
|
var path string
|
||||||
// #118 get relative and if not exist try to get abs
|
// #118 get relative and if not exist try to get abs
|
||||||
if _, err = os.Stat(p.String("path")); os.IsNotExist(err) {
|
if _, err = os.Stat(p.String("path")); os.IsNotExist(err) {
|
||||||
@ -62,7 +62,7 @@ func (r *realize) add(p *cli.Context) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
path = filepath.Clean(p.String("path"))
|
path = filepath.Clean(p.String("path"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
exec.go
4
exec.go
@ -206,7 +206,7 @@ func (p *Project) goTool(wg *sync.WaitGroup, stop <-chan bool, result chan<- too
|
|||||||
case <-stop:
|
case <-stop:
|
||||||
// Stop running command
|
// Stop running command
|
||||||
cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
break
|
return
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
// Command completed
|
// Command completed
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,7 +214,7 @@ func (p *Project) goTool(wg *sync.WaitGroup, stop <-chan bool, result chan<- too
|
|||||||
// send command result
|
// send command result
|
||||||
result <- tool
|
result <- tool
|
||||||
}
|
}
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,8 @@ func (w *fsNotifyWatcher) Walk(path string, init bool) string {
|
|||||||
// All watches are stopped, removed, and the poller cannot be added to
|
// All watches are stopped, removed, and the poller cannot be added to
|
||||||
func (w *filePoller) Close() error {
|
func (w *filePoller) Close() error {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
|
||||||
|
|
||||||
if w.closed {
|
if w.closed {
|
||||||
|
w.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +117,7 @@ func (w *filePoller) Close() error {
|
|||||||
w.remove(name)
|
w.remove(name)
|
||||||
delete(w.watches, name)
|
delete(w.watches, name)
|
||||||
}
|
}
|
||||||
|
w.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ type realize struct {
|
|||||||
// Cli commands
|
// Cli commands
|
||||||
func main() {
|
func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "Realize",
|
Name: "Realize",
|
||||||
Version: version,
|
Version: version,
|
||||||
Description: "Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths",
|
Description: "Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths",
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
{
|
{
|
||||||
@ -162,7 +162,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return d.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Settings.FileLimit = int8(val)
|
r.Settings.FileLimit = int32(val)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
10
server.go
10
server.go
@ -26,16 +26,15 @@ type Server struct {
|
|||||||
parent *realize
|
parent *realize
|
||||||
Status bool `yaml:"status" json:"status"`
|
Status bool `yaml:"status" json:"status"`
|
||||||
Open bool `yaml:"open" json:"open"`
|
Open bool `yaml:"open" json:"open"`
|
||||||
Host string `yaml:"host" json:"host"`
|
|
||||||
Port int `yaml:"port" json:"port"`
|
Port int `yaml:"port" json:"port"`
|
||||||
|
Host string `yaml:"host" json:"host"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Websocket projects
|
// Websocket projects
|
||||||
func (s *Server) projects(c echo.Context) error {
|
func (s *Server) projects(c echo.Context) (err error) {
|
||||||
websocket.Handler(func(ws *websocket.Conn) {
|
websocket.Handler(func(ws *websocket.Conn) {
|
||||||
defer ws.Close()
|
|
||||||
msg, _ := json.Marshal(s.parent)
|
msg, _ := json.Marshal(s.parent)
|
||||||
err := websocket.Message.Send(ws, string(msg))
|
err = websocket.Message.Send(ws, string(msg))
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -51,7 +50,7 @@ func (s *Server) projects(c echo.Context) error {
|
|||||||
for {
|
for {
|
||||||
// Read
|
// Read
|
||||||
text := ""
|
text := ""
|
||||||
err := websocket.Message.Receive(ws, &text)
|
err = websocket.Message.Receive(ws, &text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
@ -62,6 +61,7 @@ func (s *Server) projects(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ws.Close()
|
||||||
}).ServeHTTP(c.Response(), c.Request())
|
}).ServeHTTP(c.Response(), c.Request())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ const (
|
|||||||
type Settings struct {
|
type Settings struct {
|
||||||
file string
|
file string
|
||||||
Files `yaml:"files,omitempty" json:"files,omitempty"`
|
Files `yaml:"files,omitempty" json:"files,omitempty"`
|
||||||
FileLimit int8 `yaml:"flimit,omitempty" json:"flimit,omitempty"`
|
|
||||||
Legacy Legacy `yaml:"legacy" json:"legacy"`
|
Legacy Legacy `yaml:"legacy" json:"legacy"`
|
||||||
|
FileLimit int32 `yaml:"flimit,omitempty" json:"flimit,omitempty"`
|
||||||
Recovery bool `yaml:"recovery,omitempty" json:"recovery,omitempty"`
|
Recovery bool `yaml:"recovery,omitempty" json:"recovery,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
79
watcher.go
79
watcher.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
@ -12,9 +13,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -55,12 +53,12 @@ type Project struct {
|
|||||||
parent *realize
|
parent *realize
|
||||||
watcher FileWatcher
|
watcher FileWatcher
|
||||||
init bool
|
init bool
|
||||||
|
Settings `yaml:"-" json:"-"`
|
||||||
files, folders int64
|
files, folders int64
|
||||||
name, lastFile string
|
name, lastFile string
|
||||||
tools []tool
|
tools []tool
|
||||||
paths []string
|
paths []string
|
||||||
lastTime time.Time
|
lastTime time.Time
|
||||||
Settings `yaml:"-" json:"-"`
|
|
||||||
Name string `yaml:"name" json:"name"`
|
Name string `yaml:"name" json:"name"`
|
||||||
Path string `yaml:"path" json:"path"`
|
Path string `yaml:"path" json:"path"`
|
||||||
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"`
|
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"`
|
||||||
@ -350,10 +348,12 @@ func (p *Project) tool(stop <-chan bool, path string) error {
|
|||||||
result := make(chan tool)
|
result := make(chan tool)
|
||||||
go func() {
|
go func() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(p.tools))
|
|
||||||
for _, element := range p.tools {
|
for _, element := range p.tools {
|
||||||
// no need a sequence, these commands can be asynchronous
|
// no need a sequence, these commands can be asynchronous
|
||||||
go p.goTool(&wg, stop, result, path, element)
|
if element.status {
|
||||||
|
wg.Add(1)
|
||||||
|
go p.goTool(&wg, stop, result, path, element)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
close(done)
|
close(done)
|
||||||
@ -466,6 +466,7 @@ 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,43 +476,45 @@ func (p *Project) routines(stop <-chan bool, watcher FileWatcher, path string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
invoke(done,p.cmd,stop,"before",false)
|
if !done {
|
||||||
invoke(done,p.tool,stop,path)
|
// before command
|
||||||
// prevent init error on walk
|
p.cmd(stop, "before", false)
|
||||||
p.init = true
|
}
|
||||||
|
if !done {
|
||||||
|
// Go supported tools
|
||||||
|
p.tool(stop, path)
|
||||||
|
// Prevent fake events on polling startup
|
||||||
|
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
|
||||||
}
|
}
|
||||||
invoke(done,p.compile,stop,p.Cmds.Install)
|
|
||||||
invoke(done,p.compile,stop,p.Cmds.Build)
|
|
||||||
if !done && p.Cmds.Run {
|
|
||||||
start := time.Now()
|
|
||||||
runner := make(chan bool, 1)
|
|
||||||
go func() {
|
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
|
||||||
p.goRun(stop, runner)
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-runner:
|
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", green.regular("Started"), "in", magenta.regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
|
||||||
out = BufferOut{Time: time.Now(), Text: "Started in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
|
||||||
p.stamp("log", out, msg, "")
|
|
||||||
case <-stop:
|
|
||||||
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 {
|
||||||
v := reflect.ValueOf(fn)
|
install = p.compile(stop, p.Cmds.Install)
|
||||||
rargs := make([]reflect.Value, len(args))
|
}
|
||||||
for i, a := range args {
|
if !done {
|
||||||
rargs[i] = reflect.ValueOf(a)
|
build = p.compile(stop, p.Cmds.Build)
|
||||||
|
}
|
||||||
|
if !done && (install == nil && build == nil) {
|
||||||
|
if p.Cmds.Run {
|
||||||
|
start := time.Now()
|
||||||
|
runner := make(chan bool, 1)
|
||||||
|
go func() {
|
||||||
|
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
||||||
|
p.goRun(stop, runner)
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-runner:
|
||||||
|
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", green.regular("Started"), "in", magenta.regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
|
out = BufferOut{Time: time.Now(), Text: "Started in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
||||||
|
p.stamp("log", out, msg, "")
|
||||||
|
case <-stop:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
v.Call(rargs)
|
}
|
||||||
|
if !done {
|
||||||
|
p.cmd(stop, "after", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user