From 0cc05cff1f8f97c81be5d470a238d844583fd343 Mon Sep 17 00:00:00 2001 From: asoseil Date: Wed, 7 Feb 2018 14:24:47 +0100 Subject: [PATCH 01/11] fixed error with build nil --- realize/projects.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/realize/projects.go b/realize/projects.go index 3ee3ff3..ff5fb66 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -547,7 +547,9 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err defer func() { // https://github.com/golang/go/issues/5615 // https://github.com/golang/go/issues/6720 - build.Process.Signal(os.Interrupt) + if build != nil { + build.Process.Signal(os.Interrupt) + } }() // custom error pattern From e1ec6e46c4502da4a92039b50af7c4f1e6418c5a Mon Sep 17 00:00:00 2001 From: asoseil Date: Thu, 8 Feb 2018 13:55:08 +0100 Subject: [PATCH 02/11] #160 fixed --- realize.go | 5 +++++ realize/cli.go | 2 +- realize/notify.go | 10 +++++----- realize/projects.go | 2 +- realize/projects_test.go | 4 +++- realize/settings.go | 11 +++++++++++ 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/realize.go b/realize.go index 0fdd581..2ec4f41 100644 --- a/realize.go +++ b/realize.go @@ -38,6 +38,7 @@ func main() { &cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"}, &cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"}, &cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"}, + &cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Legacy watch by polling instead fsnotify"}, &cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing config and doesn't create a new one"}, }, Action: func(c *cli.Context) error { @@ -1117,6 +1118,10 @@ func setup(c *cli.Context) (err error) { // Start realize workflow func start(c *cli.Context) (err error) { r.Server = realize.Server{Parent: &r, Status: false, Open: false, Port: realize.Port, Host: realize.Host} + // set legacy watcher + if c.Bool("legacy"){ + r.Settings.Legacy.Set(1) + } // check no-config and read if !c.Bool("no-config") { // read a config if exist diff --git a/realize/cli.go b/realize/cli.go index 28a36b5..6e20511 100644 --- a/realize/cli.go +++ b/realize/cli.go @@ -18,7 +18,7 @@ var ( // RPrefix tool name RPrefix = "realize" // RVersion current version - RVersion = "2.0.1" + RVersion = "2.1" // RExt file extension RExt = ".yaml" // RFile config file name diff --git a/realize/notify.go b/realize/notify.go index 01b254c..03c6006 100644 --- a/realize/notify.go +++ b/realize/notify.go @@ -2,7 +2,7 @@ package realize // this code is imported from moby, unfortunately i can't import it directly as dependencies from its repo, // cause there was a problem between moby vendor and fsnotify -// i have just added only walk methods and some little changes to polling interval, originally set as static. +// i have just added only the walk methods and some little changes to polling interval, originally set as static. import ( "errors" @@ -57,7 +57,7 @@ type ( // PollingWatcher returns a poll-based file watcher func PollingWatcher(interval time.Duration) FileWatcher { if interval == 0 { - interval = 100 * time.Millisecond + interval = time.Duration(1) * time.Second } return &filePoller{ interval: interval, @@ -67,13 +67,13 @@ func PollingWatcher(interval time.Duration) FileWatcher { } // NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error -func NewFileWatcher(force bool, interval time.Duration) (FileWatcher, error) { - if !force { +func NewFileWatcher(l Legacy) (FileWatcher, error) { + if !l.Force { if w, err := EventWatcher(); err == nil { return w, nil } } - return PollingWatcher(interval), nil + return PollingWatcher(l.Interval), nil } // EventWatcher returns an fs-event based file watcher diff --git a/realize/projects.go b/realize/projects.go index ff5fb66..6772ec3 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -274,7 +274,7 @@ func (p *Project) Watch(wg *sync.WaitGroup) { // change channel p.stop = make(chan bool) // init a new watcher - p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy.Force, p.parent.Settings.Legacy.Interval) + p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy) if err != nil { log.Fatal(err) } diff --git a/realize/projects_test.go b/realize/projects_test.go index 7aef1df..bdba2e1 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -100,7 +100,9 @@ func TestProject_Reload(t *testing.T) { parent: &r, }) input := "test/path" - r.Projects[0].watcher, _ = NewFileWatcher(false, 0) + r.Settings.Legacy.Force = false + r.Settings.Legacy.Interval = 0 + r.Projects[0].watcher, _ = NewFileWatcher(r.Settings.Legacy) r.Reload = func(context Context) { log.Println(context.Path) } diff --git a/realize/settings.go b/realize/settings.go index d30db6c..783cb2a 100644 --- a/realize/settings.go +++ b/realize/settings.go @@ -61,6 +61,17 @@ type Resource struct { Name string } +// Set legacy watcher with an interval +func (l *Legacy) Set(interval int){ + l.Force = true + l.Interval = time.Duration(interval) * time.Second +} + +// Unset legacy watcher +func (l *Legacy) Unset(){ + l.Force = false +} + // Remove realize folder func (s *Settings) Remove(d string) error { _, err := os.Stat(d) From 9146347ec9370f86a45f5371eafb6a0d0c4f0556 Mon Sep 17 00:00:00 2001 From: asoseil Date: Thu, 8 Feb 2018 14:42:59 +0100 Subject: [PATCH 03/11] web server init improved --- realize.go | 31 ++++++------ realize/server.go | 120 ++++++++++++++++++++++++-------------------- realize/settings.go | 7 +-- 3 files changed, 83 insertions(+), 75 deletions(-) diff --git a/realize.go b/realize.go index 2ec4f41..d44ceb8 100644 --- a/realize.go +++ b/realize.go @@ -1117,10 +1117,13 @@ func setup(c *cli.Context) (err error) { // Start realize workflow func start(c *cli.Context) (err error) { - r.Server = realize.Server{Parent: &r, Status: false, Open: false, Port: realize.Port, Host: realize.Host} // set legacy watcher if c.Bool("legacy"){ - r.Settings.Legacy.Set(1) + r.Settings.Legacy.Set(c.Bool("legacy"),1) + } + // set server + if c.Bool("server"){ + r.Server.Set(c.Bool("server"), c.Bool("open"),realize.Port,realize.Host) } // check no-config and read if !c.Bool("no-config") { @@ -1138,18 +1141,6 @@ func start(c *cli.Context) (err error) { } } - // config and start server - if c.Bool("server") || r.Server.Status { - r.Server.Status = true - if c.Bool("open") || r.Server.Open { - r.Server.Open = true - r.Server.OpenURL() - } - err = r.Server.Start() - if err != nil { - return err - } - } // check project list length if len(r.Schema.Projects) <= 0 { // create a new project based on given params @@ -1164,6 +1155,18 @@ func start(c *cli.Context) (err error) { } } } + // Start web server + if r.Server.Status { + r.Server.Parent = &r + err = r.Server.Start() + if err != nil { + return err + } + err = r.Server.OpenURL() + if err != nil { + return err + } + } // start workflow return r.Start() } diff --git a/realize/server.go b/realize/server.go index ae30627..571763d 100644 --- a/realize/server.go +++ b/realize/server.go @@ -9,12 +9,12 @@ import ( "github.com/labstack/echo" "github.com/labstack/echo/middleware" "golang.org/x/net/websocket" - "io" "log" "net/http" "os/exec" "runtime" "strconv" + "github.com/go-siris/siris/core/errors" ) // Dafault host and port @@ -98,65 +98,75 @@ func (s *Server) render(c echo.Context, path string, mime int) error { return nil } +func (s *Server) Set(status bool, open bool, port int, host string) { + s.Open = open + s.Port = port + s.Host = host + s.Status = status +} + // Start the web server func (s *Server) Start() (err error) { - e := echo.New() - e.Use(middleware.GzipWithConfig(middleware.GzipConfig{ - Level: 2, - })) - e.Use(middleware.Recover()) + println(s.Status,"start") + if s.Status { + e := echo.New() + e.Use(middleware.GzipWithConfig(middleware.GzipConfig{ + Level: 2, + })) + e.Use(middleware.Recover()) - // web panel - e.GET("/", func(c echo.Context) error { - return s.render(c, "assets/index.html", 1) - }) - e.GET("/assets/js/all.min.js", func(c echo.Context) error { - return s.render(c, "assets/assets/js/all.min.js", 2) - }) - e.GET("/assets/css/app.css", func(c echo.Context) error { - return s.render(c, "assets/assets/css/app.css", 3) - }) - e.GET("/app/components/settings/index.html", func(c echo.Context) error { - return s.render(c, "assets/app/components/settings/index.html", 1) - }) - e.GET("/app/components/project/index.html", func(c echo.Context) error { - return s.render(c, "assets/app/components/project/index.html", 1) - }) - e.GET("/app/components/index.html", func(c echo.Context) error { - return s.render(c, "assets/app/components/index.html", 1) - }) - e.GET("/assets/img/logo.png", func(c echo.Context) error { - return s.render(c, "assets/assets/img/logo.png", 5) - }) - e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error { - return s.render(c, "assets/assets/img/svg/github-logo.svg", 4) - }) - e.GET("/assets/img/svg/ic_arrow_back_black_48px.svg", func(c echo.Context) error { - return s.render(c, "assets/assets/img/svg/ic_arrow_back_black_48px.svg", 4) - }) - e.GET("/assets/img/svg/ic_clear_white_48px.svg", func(c echo.Context) error { - return s.render(c, "assets/assets/img/svg/ic_clear_white_48px.svg", 4) - }) - e.GET("/assets/img/svg/ic_menu_white_48px.svg", func(c echo.Context) error { - return s.render(c, "assets/assets/img/svg/ic_menu_white_48px.svg", 4) - }) - e.GET("/assets/img/svg/ic_settings_black_48px.svg", func(c echo.Context) error { - return s.render(c, "assets/assets/img/svg/ic_settings_black_48px.svg", 4) - }) + // web panel + e.GET("/", func(c echo.Context) error { + return s.render(c, "assets/index.html", 1) + }) + e.GET("/assets/js/all.min.js", func(c echo.Context) error { + return s.render(c, "assets/assets/js/all.min.js", 2) + }) + e.GET("/assets/css/app.css", func(c echo.Context) error { + return s.render(c, "assets/assets/css/app.css", 3) + }) + e.GET("/app/components/settings/index.html", func(c echo.Context) error { + return s.render(c, "assets/app/components/settings/index.html", 1) + }) + e.GET("/app/components/project/index.html", func(c echo.Context) error { + return s.render(c, "assets/app/components/project/index.html", 1) + }) + e.GET("/app/components/index.html", func(c echo.Context) error { + return s.render(c, "assets/app/components/index.html", 1) + }) + e.GET("/assets/img/logo.png", func(c echo.Context) error { + return s.render(c, "assets/assets/img/logo.png", 5) + }) + e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error { + return s.render(c, "assets/assets/img/svg/github-logo.svg", 4) + }) + e.GET("/assets/img/svg/ic_arrow_back_black_48px.svg", func(c echo.Context) error { + return s.render(c, "assets/assets/img/svg/ic_arrow_back_black_48px.svg", 4) + }) + e.GET("/assets/img/svg/ic_clear_white_48px.svg", func(c echo.Context) error { + return s.render(c, "assets/assets/img/svg/ic_clear_white_48px.svg", 4) + }) + e.GET("/assets/img/svg/ic_menu_white_48px.svg", func(c echo.Context) error { + return s.render(c, "assets/assets/img/svg/ic_menu_white_48px.svg", 4) + }) + e.GET("/assets/img/svg/ic_settings_black_48px.svg", func(c echo.Context) error { + return s.render(c, "assets/assets/img/svg/ic_settings_black_48px.svg", 4) + }) - //websocket - e.GET("/ws", s.projects) - e.HideBanner = true - e.Debug = false - go func() { - log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port))) - e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port)) - }() + //websocket + e.GET("/ws", s.projects) + e.HideBanner = true + e.Debug = false + go func() { + log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port))) + e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port)) + }() + } return nil } // OpenURL in a new tab of default browser -func (s *Server) OpenURL() (io.Writer, error) { +func (s *Server) OpenURL() error { url := "http://" + string(s.Parent.Server.Host) + ":" + strconv.Itoa(s.Parent.Server.Port) stderr := bytes.Buffer{} cmd := map[string]string{ @@ -167,13 +177,13 @@ func (s *Server) OpenURL() (io.Writer, error) { if s.Open { open, err := cmd[runtime.GOOS] if !err { - return nil, fmt.Errorf("operating system %q is not supported", runtime.GOOS) + return fmt.Errorf("operating system %q is not supported", runtime.GOOS) } cmd := exec.Command(open, url) cmd.Stderr = &stderr if err := cmd.Run(); err != nil { - return cmd.Stderr, err + return errors.New(stderr.String()) } } - return nil, nil + return nil } diff --git a/realize/settings.go b/realize/settings.go index 783cb2a..6859801 100644 --- a/realize/settings.go +++ b/realize/settings.go @@ -62,16 +62,11 @@ type Resource struct { } // Set legacy watcher with an interval -func (l *Legacy) Set(interval int){ +func (l *Legacy) Set(status bool, interval int){ l.Force = true l.Interval = time.Duration(interval) * time.Second } -// Unset legacy watcher -func (l *Legacy) Unset(){ - l.Force = false -} - // Remove realize folder func (s *Settings) Remove(d string) error { _, err := os.Stat(d) From 14ea484ce252e6027323af8b86a1209d8166c1e2 Mon Sep 17 00:00:00 2001 From: asoseil Date: Thu, 8 Feb 2018 15:20:26 +0100 Subject: [PATCH 04/11] print removed --- realize/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/realize/server.go b/realize/server.go index 571763d..250f118 100644 --- a/realize/server.go +++ b/realize/server.go @@ -107,7 +107,6 @@ func (s *Server) Set(status bool, open bool, port int, host string) { // Start the web server func (s *Server) Start() (err error) { - println(s.Status,"start") if s.Status { e := echo.New() e.Use(middleware.GzipWithConfig(middleware.GzipConfig{ From 21ce614026c3cacf7c5368bdf60f667554882d0a Mon Sep 17 00:00:00 2001 From: asoseil Date: Thu, 8 Feb 2018 20:57:08 +0100 Subject: [PATCH 05/11] #156 fixed --- realize.go | 10 +++++++--- realize/projects.go | 21 ++++++++++++++++----- realize/projects_test.go | 3 ++- realize/schema.go | 2 +- realize/utils.go | 10 ---------- realize/utils_test.go | 10 ---------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/realize.go b/realize.go index d44ceb8..76b06ca 100644 --- a/realize.go +++ b/realize.go @@ -795,7 +795,7 @@ func setup(c *cli.Context) (err error) { Resolve: func(d interact.Context) bool { val, _ := d.Ans().Bool() if val { - r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore)-1] + r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths)-1] } return val }, @@ -815,7 +815,7 @@ func setup(c *cli.Context) (err error) { if err != nil { return d.Err() } - r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore, val) + r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths, val) d.Reload() return nil }, @@ -1128,7 +1128,10 @@ func start(c *cli.Context) (err error) { // check no-config and read if !c.Bool("no-config") { // read a config if exist - r.Settings.Read(&r) + err := r.Settings.Read(&r) + if err != nil{ + return err + } if c.String("name") != "" { // filter by name flag if exist r.Schema.Projects = r.Schema.Filter("Name", c.String("name")) @@ -1143,6 +1146,7 @@ func start(c *cli.Context) (err error) { } // check project list length if len(r.Schema.Projects) <= 0 { + println("len",r.Schema.Projects) // create a new project based on given params project := r.Schema.New(c) // Add to projects list diff --git a/realize/projects.go b/realize/projects.go index 6772ec3..144a83e 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -28,7 +28,8 @@ var ( type Watch struct { Paths []string `yaml:"paths" json:"paths"` Exts []string `yaml:"extensions" json:"extensions"` - Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` + IgnoredExts []string `yaml:"ignored_extensions,omitempty" json:"ignored_extensions,omitempty"` + IgnoredPaths []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Hidden bool `yaml:"skip_hidden,omitempty" json:"skip_hidden,omitempty"` } @@ -347,14 +348,24 @@ func (p *Project) Validate(path string, fcheck bool) bool { } // check for a valid ext or path if e := ext(path); e != "" { - // supported exts - if !array(e, p.Watcher.Exts) { - return false + for _, v := range p.Watcher.IgnoredExts { + if v == e { + return false + } + } + // supported extensions + for index, v := range p.Watcher.Exts{ + if e == v { + break + } + if index == len(p.Watcher.Exts)-1{ + return false + } } } separator := string(os.PathSeparator) // supported paths - for _, v := range p.Watcher.Ignore { + for _, v := range p.Watcher.IgnoredPaths { s := append([]string{p.Path}, strings.Split(v, separator)...) abs, _ := filepath.Abs(filepath.Join(s...)) if path == abs || strings.HasPrefix(path, abs+separator) { diff --git a/realize/projects_test.go b/realize/projects_test.go index bdba2e1..763fd06 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -128,7 +128,8 @@ func TestProject_Validate(t *testing.T) { r.Projects = append(r.Projects, Project{ parent: &r, Watcher: Watch{ - Ignore: []string{"/test/ignore"}, + Exts: []string{"go","html"}, + IgnoredPaths: []string{"/test/ignore"}, }, }) for i, v := range data { diff --git a/realize/schema.go b/realize/schema.go index 36cedf1..38974f0 100644 --- a/realize/schema.go +++ b/realize/schema.go @@ -68,7 +68,7 @@ func (s *Schema) New(c *cli.Context) Project { Args: params(c), Watcher: Watch{ Paths: []string{"/"}, - Ignore: []string{".git", ".realize", "vendor"}, + IgnoredPaths: []string{".git", ".realize", "vendor"}, Exts: []string{"go"}, }, } diff --git a/realize/utils.go b/realize/utils.go index 72da59e..30ed600 100644 --- a/realize/utils.go +++ b/realize/utils.go @@ -8,16 +8,6 @@ import ( "strings" ) -// Array check if a string is in given array -func array(str string, list []string) bool { - for _, v := range list { - if v == str { - return true - } - } - return false -} - // Params parse one by one the given argumentes func params(params *cli.Context) []string { argsN := params.NArg() diff --git a/realize/utils_test.go b/realize/utils_test.go index b0d2b07..0018295 100644 --- a/realize/utils_test.go +++ b/realize/utils_test.go @@ -43,16 +43,6 @@ func TestDuplicates(t *testing.T) { } -func TestArray(t *testing.T) { - arr := []string{"a", "b", "c"} - if !array(arr[0], arr) { - t.Fatal("Unexpected", arr[0], "should be in", arr) - } - if array("d", arr) { - t.Fatal("Unexpected", "d", "shouldn't be in", arr) - } -} - func TestWdir(t *testing.T) { expected, err := os.Getwd() if err != nil { From 83134f9b8d3e134c88579c16a911b464de504f90 Mon Sep 17 00:00:00 2001 From: asoseil Date: Fri, 9 Feb 2018 00:17:02 +0100 Subject: [PATCH 06/11] #156 bug fix --- realize/projects.go | 5 +++++ realize/projects_test.go | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index 144a83e..8d25a42 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -348,6 +348,10 @@ func (p *Project) Validate(path string, fcheck bool) bool { } // check for a valid ext or path if e := ext(path); e != "" { + if len(p.Watcher.Exts) == 0{ + return false + } + // check ignored for _, v := range p.Watcher.IgnoredExts { if v == e { return false @@ -355,6 +359,7 @@ func (p *Project) Validate(path string, fcheck bool) bool { } // supported extensions for index, v := range p.Watcher.Exts{ + println(v) if e == v { break } diff --git a/realize/projects_test.go b/realize/projects_test.go index 763fd06..ca50386 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -128,13 +128,14 @@ func TestProject_Validate(t *testing.T) { r.Projects = append(r.Projects, Project{ parent: &r, Watcher: Watch{ - Exts: []string{"go","html"}, + Exts: []string{}, IgnoredPaths: []string{"/test/ignore"}, }, }) for i, v := range data { - if r.Projects[0].Validate(i, false) != v { - t.Error("Unexpected error", i, "expected", v) + result := r.Projects[0].Validate(i, false) + if result != v { + t.Error("Unexpected error", i, "expected", v, result) } } } From 13beb532f9a0810a3d8ff2653c96c004f903c4db Mon Sep 17 00:00:00 2001 From: asoseil Date: Fri, 9 Feb 2018 17:50:31 +0100 Subject: [PATCH 07/11] check broken symbolic --- realize/projects.go | 46 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index 8d25a42..c1b2c04 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -26,18 +26,22 @@ var ( // Watch info type Watch struct { + Exts []string `yaml:"exts" json:"exts"` Paths []string `yaml:"paths" json:"paths"` - Exts []string `yaml:"extensions" json:"extensions"` - IgnoredExts []string `yaml:"ignored_extensions,omitempty" json:"ignored_extensions,omitempty"` - IgnoredPaths []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` - Hidden bool `yaml:"skip_hidden,omitempty" json:"skip_hidden,omitempty"` + Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"` + Ignore Ignore `yaml:"ignore,omitempty" json:"ignore,omitempty"` +} + +type Ignore struct{ + Exts []string `yaml:"exts,omitempty" json:"exts,omitempty"` + Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"` } // Command fields type Command struct { + Cmd string `yaml:"cmd" json:"cmd"` Type string `yaml:"type" json:"type"` - Cmd string `yaml:"command" json:"command"` Path string `yaml:"path,omitempty" json:"path,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"` Output bool `yaml:"output,omitempty" json:"output,omitempty"` @@ -47,21 +51,21 @@ type Command struct { type Project struct { parent *Realize watcher FileWatcher - init bool - exit chan os.Signal stop chan bool + exit chan os.Signal + paths []string + last last files int64 folders int64 - last last - paths []string + init bool Name string `yaml:"name" json:"name"` Path string `yaml:"path" json:"path"` - Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"` - Tools Tools `yaml:"commands" json:"commands"` + Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"` + Tools Tools `yaml:"tools" json:"tools"` Watcher Watch `yaml:"watcher" json:"watcher"` Buffer Buffer `yaml:"-" json:"buffer"` - ErrorOutputPattern string `yaml:"errorOutputPattern,omitempty" json:"errorOutputPattern,omitempty"` + ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` } // Last is used to save info about last file changed @@ -112,7 +116,7 @@ func (p *Project) Before() { // setup go tools p.Tools.Setup() // set env const - for key, item := range p.Environment { + for key, item := range p.Env { if err := os.Setenv(key, item); err != nil { p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""}) } @@ -352,14 +356,13 @@ func (p *Project) Validate(path string, fcheck bool) bool { return false } // check ignored - for _, v := range p.Watcher.IgnoredExts { + for _, v := range p.Watcher.Ignore.Exts { if v == e { return false } } // supported extensions for index, v := range p.Watcher.Exts{ - println(v) if e == v { break } @@ -370,7 +373,7 @@ func (p *Project) Validate(path string, fcheck bool) bool { } separator := string(os.PathSeparator) // supported paths - for _, v := range p.Watcher.IgnoredPaths { + for _, v := range p.Watcher.Ignore.Paths { s := append([]string{p.Path}, strings.Split(v, separator)...) abs, _ := filepath.Abs(filepath.Join(s...)) if path == abs || strings.HasPrefix(path, abs+separator) { @@ -380,16 +383,9 @@ func (p *Project) Validate(path string, fcheck bool) bool { // file check if fcheck { fi, err := os.Stat(path) - if err != nil { + if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0{ return false } - if !fi.IsDir() && ext(path) == "" { - return false - } - if fi.Size() > 0 { - return true - } - return false } return true @@ -572,7 +568,7 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err isErrorText := func(string) bool { return false } - errRegexp, err := regexp.Compile(p.ErrorOutputPattern) + errRegexp, err := regexp.Compile(p.ErrPattern) if err != nil { r.Err = err stream <- r From dff147f801c151034fd5ca665f318367ad5298ce Mon Sep 17 00:00:00 2001 From: asoseil Date: Fri, 9 Feb 2018 17:51:11 +0100 Subject: [PATCH 08/11] struct names fixed --- realize/cli.go | 2 +- realize/projects_test.go | 6 ++++-- realize/schema.go | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/realize/cli.go b/realize/cli.go index 6e20511..cc899d2 100644 --- a/realize/cli.go +++ b/realize/cli.go @@ -34,7 +34,7 @@ type ( // Realize main struct Realize struct { Settings Settings `yaml:"settings" json:"settings"` - Server Server `yaml:"server" json:"server"` + Server Server `yaml:"server,omitempty" json:"server,omitempty"` Schema `yaml:",inline" json:",inline"` Sync chan string `yaml:"-" json:"-"` Err Func `yaml:"-" json:"-"` diff --git a/realize/projects_test.go b/realize/projects_test.go index ca50386..d1e5b6d 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -48,7 +48,7 @@ func TestProject_Before(t *testing.T) { r = Realize{} r.Projects = append(r.Projects, Project{ parent: &r, - Environment: map[string]string{ + Env: map[string]string{ input: input, }, }) @@ -129,7 +129,9 @@ func TestProject_Validate(t *testing.T) { parent: &r, Watcher: Watch{ Exts: []string{}, - IgnoredPaths: []string{"/test/ignore"}, + Ignore: Ignore{ + Paths:[]string{"/test/ignore"}, + }, }, }) for i, v := range data { diff --git a/realize/schema.go b/realize/schema.go index 38974f0..37a1c71 100644 --- a/realize/schema.go +++ b/realize/schema.go @@ -68,7 +68,9 @@ func (s *Schema) New(c *cli.Context) Project { Args: params(c), Watcher: Watch{ Paths: []string{"/"}, - IgnoredPaths: []string{".git", ".realize", "vendor"}, + Ignore: Ignore{ + Paths:[]string{".git", ".realize", "vendor"}, + }, Exts: []string{"go"}, }, } From 153ea7defacf0cd33fadd62e314d8ed785de5cec Mon Sep 17 00:00:00 2001 From: asoseil Date: Fri, 9 Feb 2018 17:58:58 +0100 Subject: [PATCH 09/11] Struct names fixed --- realize.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/realize.go b/realize.go index 76b06ca..d365854 100644 --- a/realize.go +++ b/realize.go @@ -795,7 +795,7 @@ func setup(c *cli.Context) (err error) { Resolve: func(d interact.Context) bool { val, _ := d.Ans().Bool() if val { - r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths)-1] + r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths = r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths[:len(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths)-1] } return val }, @@ -815,7 +815,7 @@ func setup(c *cli.Context) (err error) { if err != nil { return d.Err() } - r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.IgnoredPaths, val) + r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths = append(r.Schema.Projects[len(r.Schema.Projects)-1].Watcher.Ignore.Paths, val) d.Reload() return nil }, @@ -1081,7 +1081,7 @@ func setup(c *cli.Context) (err error) { if err != nil { return d.Err() } - r.Schema.Projects[len(r.Schema.Projects)-1].ErrorOutputPattern = val + r.Schema.Projects[len(r.Schema.Projects)-1].ErrPattern = val return nil }, }, From 600b1ac467926429d7859ecef6a173cce33888de Mon Sep 17 00:00:00 2001 From: asoseil Date: Sun, 18 Feb 2018 19:36:50 +0100 Subject: [PATCH 10/11] start fixed with no config --- realize.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/realize.go b/realize.go index d365854..2b20c98 100644 --- a/realize.go +++ b/realize.go @@ -1118,20 +1118,17 @@ func setup(c *cli.Context) (err error) { // Start realize workflow func start(c *cli.Context) (err error) { // set legacy watcher - if c.Bool("legacy"){ - r.Settings.Legacy.Set(c.Bool("legacy"),1) + if c.Bool("legacy") { + r.Settings.Legacy.Set(c.Bool("legacy"), 1) } // set server - if c.Bool("server"){ - r.Server.Set(c.Bool("server"), c.Bool("open"),realize.Port,realize.Host) + if c.Bool("server") { + r.Server.Set(c.Bool("server"), c.Bool("open"), realize.Port, realize.Host) } // check no-config and read if !c.Bool("no-config") { // read a config if exist - err := r.Settings.Read(&r) - if err != nil{ - return err - } + r.Settings.Read(&r) if c.String("name") != "" { // filter by name flag if exist r.Schema.Projects = r.Schema.Filter("Name", c.String("name")) @@ -1146,7 +1143,7 @@ func start(c *cli.Context) (err error) { } // check project list length if len(r.Schema.Projects) <= 0 { - println("len",r.Schema.Projects) + println("len", r.Schema.Projects) // create a new project based on given params project := r.Schema.New(c) // Add to projects list From f0e28d1602e76cbaad89ba33d2d4f0b607dbefdd Mon Sep 17 00:00:00 2001 From: asoseil Date: Sat, 14 Apr 2018 16:15:03 +0200 Subject: [PATCH 11/11] #175 fixed --- realize.go | 4 ++-- realize/projects.go | 16 ++++++++-------- realize/tools.go | 11 ++++++++--- realize_test.go | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/realize.go b/realize.go index 2b20c98..0b886ea 100644 --- a/realize.go +++ b/realize.go @@ -1,8 +1,8 @@ package main import ( - "github.com/tockins/interact" - "github.com/tockins/realize/realize" + "github.com/oxequa/interact" + "github.com/oxequa/realize/realize" "gopkg.in/urfave/cli.v2" "log" "os" diff --git a/realize/projects.go b/realize/projects.go index c1b2c04..967bb41 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -26,7 +26,7 @@ var ( // Watch info type Watch struct { - Exts []string `yaml:"exts" json:"exts"` + Exts []string `yaml:"extensions" json:"extensions"` Paths []string `yaml:"paths" json:"paths"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"` @@ -40,7 +40,7 @@ type Ignore struct{ // Command fields type Command struct { - Cmd string `yaml:"cmd" json:"cmd"` + Cmd string `yaml:"command" json:"command"` Type string `yaml:"type" json:"type"` Path string `yaml:"path,omitempty" json:"path,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"` @@ -62,7 +62,7 @@ type Project struct { Path string `yaml:"path" json:"path"` Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"` - Tools Tools `yaml:"tools" json:"tools"` + Tools Tools `yaml:"commands" json:"commands"` Watcher Watch `yaml:"watcher" json:"watcher"` Buffer Buffer `yaml:"-" json:"buffer"` ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` @@ -196,7 +196,7 @@ func (p *Project) Reload(path string, stop <-chan bool) { } // Go supported tools if len(path) > 0 { - fi, err := os.Stat(filepath.Dir(path)) + fi, err := os.Stat(path) if filepath.Ext(path) == "" { fi, err = os.Stat(path) } @@ -477,8 +477,8 @@ func (p *Project) cmd(stop <-chan bool, flag string, global bool) { case <-done: return case r := <-result: - msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\"")) - if r.Err != nil { + msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\"")) + if r.Err != nil { out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: flag} p.stamp("error", out, msg, fmt.Sprint(Red.Regular(r.Err.Error()))) } else { @@ -497,9 +497,9 @@ func (p *Project) walk(path string, info os.FileInfo, err error) error { if p.parent.Settings.Recovery.Index { log.Println("Indexing",path) } + p.tools(p.stop, path, info) if info.IsDir() { // tools dir - p.tools(p.stop, path, info) p.folders++ } else { // tools files @@ -544,7 +544,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { log.Print(msg) } if stream != "" { - fmt.Fprint(Output, stream) + fmt.Fprintln(Output, stream) } go func() { p.parent.Sync <- "sync" diff --git a/realize/tools.go b/realize/tools.go index 1e51279..3d9bde1 100644 --- a/realize/tools.go +++ b/realize/tools.go @@ -43,7 +43,7 @@ func (t *Tools) Setup() { if t.Clean.Status { t.Clean.name = "Clean" t.Clean.isTool = true - t.Clean.cmd = replace([]string{"go clean"}, t.Clean.Method) + t.Clean.cmd = replace([]string{"go", "clean"}, t.Clean.Method) t.Clean.Args = split([]string{}, t.Clean.Args) } // go generate @@ -134,7 +134,12 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) { cmd.Stdout = &out cmd.Stderr = &stderr // Start command - cmd.Start() + err := cmd.Start() + if err != nil{ + response.Name = t.name + response.Err = err + return + } go func() { done <- cmd.Wait() }() // Wait a result select { @@ -145,7 +150,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) { // Command completed response.Name = t.name if err != nil { - response.Err = errors.New(stderr.String() + out.String()) + response.Err = errors.New(stderr.String() + out.String() + err.Error()) } else { if t.Output { response.Out = out.String() diff --git a/realize_test.go b/realize_test.go index 981590b..caf17fd 100644 --- a/realize_test.go +++ b/realize_test.go @@ -3,7 +3,7 @@ package main import ( "bytes" "errors" - "github.com/tockins/realize/realize" + "github.com/oxequa/realize/realize" "log" "strings" "testing"