From c781c912bfdd51f528cb0f8ba62e56bd4e196f54 Mon Sep 17 00:00:00 2001 From: alessio Date: Sun, 4 Dec 2016 19:55:35 +0100 Subject: [PATCH 01/11] features upadeted --- README.md | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 33b358e..81ebdee 100644 --- a/README.md +++ b/README.md @@ -16,25 +16,15 @@ A Go build system with file watchers, output streams and live reload. Run, build #### What's new -##### v1.2 -- [x] Windows support -- [x] Go generate support -- [x] Bugs fix -- [x] Web panel errors log improved -- [x] Refactoring -- [x] Web panel edit settings, partial - #### Features -- Build, Install, Test, Fmt and Run at the same time -- Live reload on file changes (re-build, re-install and re-run) -- Watch custom paths -- Watch specific file extensions -- Multiple projects support -- Output streams -- Execution times - Highly customizable -- Fast run +- Build, Install, Test, Fmt, Generate and Run at the same time +- Live reload on file changes (re-build, re-install...) +- Watch custom paths and specific file extensions +- Support for multiple projects +- Output streams and error logs (Watch them in console or save them on a file) +- Web Panel (Watch all projects, edit the config settings, download each type of log) #### Installation and usage @@ -188,8 +178,9 @@ A Go build system with file watchers, output streams and live reload. Run, build #### Next release -##### v1.3 -- [ ] Web panel edit settings, full support +- [ ] Web panel - edit settings (full support) +- [ ] Web Panel - logs download +- [ ] Scheduling - reload a project after a specific time - [ ] Tests #### Contacts From e8267d975776d1b0540a368654a4b805859873ee Mon Sep 17 00:00:00 2001 From: alessio Date: Sun, 4 Dec 2016 20:04:45 +0100 Subject: [PATCH 02/11] next release features --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81ebdee..a0857a4 100644 --- a/README.md +++ b/README.md @@ -176,13 +176,15 @@ A Go build system with file watchers, output streams and live reload. Run, build errors: false // saves the errors of the project in a file ``` -#### Next release +#### Next release, in progress... - [ ] Web panel - edit settings (full support) - [ ] Web Panel - logs download -- [ ] Scheduling - reload a project after a specific time +- [ ] Scheduler - reload a project after a specific time +- [ ] Easy dependencies - automatically resolve the project dependencies - [ ] Tests + #### Contacts - Chat with us [Gitter](https://gitter.im/tockins/realize) From b13b91a5e598588531a2d2605f49b47e7fb43f72 Mon Sep 17 00:00:00 2001 From: alessio Date: Sun, 4 Dec 2016 20:05:40 +0100 Subject: [PATCH 03/11] removed a section --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a0857a4..de311fc 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ A Go build system with file watchers, output streams and live reload. Run, build ![Preview](http://i.imgur.com/dJbNZjt.gif) -#### What's new - #### Features - Highly customizable From c85ef3c8a03281f443470c7cd48ebc40aa466281 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 15 Dec 2016 07:06:24 +0100 Subject: [PATCH 04/11] Store configuration in a .relaize subdirecotry --- settings/settings.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/settings/settings.go b/settings/settings.go index d956e21..68691d9 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,6 +1,8 @@ package settings import ( + "os" + "gopkg.in/yaml.v2" ) @@ -30,7 +32,11 @@ type Resources struct { // Read from the configuration file func (s *Settings) Read(out interface{}) error { - content, err := s.Stream(s.Resources.Config) + localConfigPath := s.Resources.Config + if _, err := os.Stat(".realize/"); err == nil { + localConfigPath = ".realize/" + s.Resources.Config + } + content, err := s.Stream(localConfigPath) if err == nil { err = yaml.Unmarshal(content, out) return err @@ -39,10 +45,13 @@ func (s *Settings) Read(out interface{}) error { } // Record create and unmarshal the yaml config file -func (h *Settings) Record(out interface{}) error { +func (s *Settings) Record(out interface{}) error { y, err := yaml.Marshal(out) if err != nil { return err } - return h.Write(h.Resources.Config, y) + if _, err := os.Stat(".realize/"); os.IsNotExist(err) { + os.Mkdir(".realize", 0770) + } + return s.Write(".realize/"+s.Resources.Config, y) } From b60885c42928304fba36c5f534dc72474f80448d Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 15 Dec 2016 07:11:20 +0100 Subject: [PATCH 05/11] Checking for full path of new config file location --- settings/settings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/settings.go b/settings/settings.go index 68691d9..7b2e2e3 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -33,7 +33,7 @@ type Resources struct { // Read from the configuration file func (s *Settings) Read(out interface{}) error { localConfigPath := s.Resources.Config - if _, err := os.Stat(".realize/"); err == nil { + if _, err := os.Stat(".realize/" + s.Resources.Config); err == nil { localConfigPath = ".realize/" + s.Resources.Config } content, err := s.Stream(localConfigPath) From 249dca4dfba91893312f375ebbe1ceadd8f9be89 Mon Sep 17 00:00:00 2001 From: alessio Date: Fri, 16 Dec 2016 23:53:27 +0100 Subject: [PATCH 06/11] variadic for fatal method --- settings/flimit.go | 3 +-- settings/utils.go | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/settings/flimit.go b/settings/flimit.go index 4aa15d5..f1ccfbf 100644 --- a/settings/flimit.go +++ b/settings/flimit.go @@ -1,4 +1,3 @@ - // +build !windows package settings @@ -12,6 +11,6 @@ func (s *Settings) Flimit() { rLimit.Cur = s.Config.Flimit err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) if err != nil { - s.Fatal("Error Setting Rlimit", err) + s.Fatal(err, "Error setting rlimit") } } diff --git a/settings/utils.go b/settings/utils.go index a030559..e67c502 100644 --- a/settings/utils.go +++ b/settings/utils.go @@ -14,14 +14,14 @@ func (s Settings) Wdir() string { func (s Settings) Validate(err error) error { if err != nil { - s.Fatal("", err) + s.Fatal(err, "") } return nil } -func (s Settings) Fatal(msg string, err error) { - if msg != "" { - log.Fatal(s.Red.Regular(msg), err.Error()) +func (s Settings) Fatal(err error, msg ...interface{}) { + if len(msg) > 0 { + log.Fatalln(s.Red.Regular(msg...), err.Error()) } - log.Fatal(err.Error()) + log.Fatalln(err.Error()) } From 45bf555bd335e04de92e04633b1faea5555596af Mon Sep 17 00:00:00 2001 From: alessio Date: Fri, 16 Dec 2016 23:54:07 +0100 Subject: [PATCH 07/11] fixed #31 --- watcher/exec.go | 37 ++++++++++++++++++---------- watcher/watcher.go | 60 ++++++++++++++++++++++------------------------ 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/watcher/exec.go b/watcher/exec.go index bf489fa..283b276 100644 --- a/watcher/exec.go +++ b/watcher/exec.go @@ -16,21 +16,34 @@ import ( func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error { var build *exec.Cmd - if len(p.Params) != 0 { - var params []string - for _, param := range p.Params { - arr := strings.Fields(param) - params = append(params, arr...) - } - build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)), params...) - } else { - build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))) + var params []string + var path = "" + + for _, param := range p.Params { + arr := strings.Fields(param) + params = append(params, arr...) + } + if _, err := os.Stat(filepath.Join(p.base, p.path)); err == nil { + path = filepath.Join(p.base, p.path) + } + if _, err := os.Stat(filepath.Join(p.base, p.path+".exe")); err == nil { + path = filepath.Join(p.base, p.path+".exe") + } + + if path != "" { + build = exec.Command(path, params...) + } else { + if _, err := os.Stat(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))); err == nil { + build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)), params...) + } else { + p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"}) + p.Fatal(err, "Can't run a not compiled project", ":") + } } - build.Dir = p.base defer func() { if err := build.Process.Kill(); err != nil { p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()}) - p.Fatal("Failed to stop:", err) + p.Fatal(err, "Failed to stop", ":") } p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Ended"}) log.Println(p.pname(p.Name, 2), ":", p.Red.Regular("Ended")) @@ -72,7 +85,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) f := p.Create(path) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil { - p.Fatal("", err) + p.Fatal(err, "") } } } diff --git a/watcher/watcher.go b/watcher/watcher.go index 468f303..774fea4 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -84,51 +84,47 @@ func (p *Project) watching() { } // Install calls an implementation of the "go install" -func (p *Project) install(channel chan bool, wr *sync.WaitGroup) { - defer func() { - p.sync() - }() +func (p *Project) install() { if p.Bin { - log.Println(p.pname(p.Name, 1), ":", "Installing..") start := time.Now() + log.Println(p.pname(p.Name, 1), ":", "Installing..") if stream, err := p.goInstall(); err != nil { msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error())) out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream} p.print("error", out, msg, stream) - wr.Done() } else { msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) out := BufferOut{Time: time.Now(), Text: "Installed"} p.print("log", out, msg, stream) - - if p.Run { - runner := make(chan bool, 1) - log.Println(p.pname(p.Name, 1), ":", "Running..") - start = time.Now() - go p.goRun(channel, runner, wr) - for { - select { - case <-runner: - msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Has been run")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) - out := BufferOut{Time: time.Now(), Text: "Has been run"} - p.print("log", out, msg, stream) - return - } - } - } } + p.sync() } return } +func (p *Project) run(channel chan bool, wr *sync.WaitGroup) { + if p.Run { + start := time.Now() + runner := make(chan bool, 1) + log.Println(p.pname(p.Name, 1), ":", "Running..") + go p.goRun(channel, runner, wr) + for { + select { + case <-runner: + msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Has been run")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) + out := BufferOut{Time: time.Now(), Text: "Has been run"} + p.print("log", out, msg, "") + return + } + } + } +} + // Build calls an implementation of the "go build" func (p *Project) build() { - defer func() { - p.sync() - }() if p.Build { - log.Println(p.pname(p.Name, 1), ":", "Building..") start := time.Now() + log.Println(p.pname(p.Name, 1), ":", "Building..") if stream, err := p.goBuild(); err != nil { msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error())) out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream} @@ -138,6 +134,7 @@ func (p *Project) build() { out := BufferOut{Time: time.Now(), Text: "Builded"} p.print("log", out, msg, stream) } + p.sync() } return } @@ -281,9 +278,10 @@ func (p *Project) ignore(str string) bool { // Routines launches the following methods: run, build, install func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) { + p.install() + p.build() wr.Add(1) - go p.build() - go p.install(channel, wr) + go p.run(channel, wr) wr.Wait() } @@ -318,7 +316,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { f := p.Create(path) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { - p.Fatal("", err) + p.Fatal(err, "") } } case "log": @@ -328,7 +326,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { f := p.Create(path) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { - p.Fatal("", err) + p.Fatal(err, "") } } case "error": @@ -338,7 +336,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { f := p.Create(path) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { - p.Fatal("", err) + p.Fatal(err, "") } } From ee4f342db1187d0f5ed21392095e7a75ea61f9f7 Mon Sep 17 00:00:00 2001 From: alessio Date: Fri, 16 Dec 2016 23:54:57 +0100 Subject: [PATCH 08/11] updated --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de311fc..db26e91 100644 --- a/README.md +++ b/README.md @@ -174,12 +174,13 @@ A Go build system with file watchers, output streams and live reload. Run, build errors: false // saves the errors of the project in a file ``` -#### Next release, in progress... +#### Next features, in progress... - [ ] Web panel - edit settings (full support) -- [ ] Web Panel - logs download -- [ ] Scheduler - reload a project after a specific time +- [ ] Web panel - logs download +- [ ] Schedule - reload a project after a specific time - [ ] Easy dependencies - automatically resolve the project dependencies +- [ ] Import license - retrieve the license for each imported library - [ ] Tests From e6c821ada460f09d1fb459b7ad4a650a7488a212 Mon Sep 17 00:00:00 2001 From: alessio Date: Fri, 16 Dec 2016 23:58:16 +0100 Subject: [PATCH 09/11] description updated --- settings/settings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/settings.go b/settings/settings.go index 7b2e2e3..c44fca2 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -30,7 +30,7 @@ type Resources struct { Log string `yaml:"log" json:"log"` } -// Read from the configuration file +// Read from config file func (s *Settings) Read(out interface{}) error { localConfigPath := s.Resources.Config if _, err := os.Stat(".realize/" + s.Resources.Config); err == nil { From 1148047438f46bbbb7ff08816c655c2bfdd1e243 Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 17 Dec 2016 01:48:04 +0100 Subject: [PATCH 10/11] realize files moved in .realize hidden dir --- realize.go | 1 - settings/io.go | 9 ++++++++- settings/settings.go | 7 ++++--- watcher/exec.go | 3 +-- watcher/watcher.go | 10 +++------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/realize.go b/realize.go index 221a91b..4a148b2 100644 --- a/realize.go +++ b/realize.go @@ -17,7 +17,6 @@ const ( config = "realize.yaml" output = "outputs.log" log = "logs.log" - err = "errors.log" host = "localhost" port = 5000 server = true diff --git a/settings/io.go b/settings/io.go index 02b9e6d..9619aea 100644 --- a/settings/io.go +++ b/settings/io.go @@ -3,6 +3,7 @@ package settings import ( "io/ioutil" "os" + "path/filepath" ) // Scan return a byte stream of a given file @@ -23,7 +24,13 @@ func (s Settings) Write(name string, data []byte) error { } // Create a new file and return its pointer -func (s Settings) Create(file string) *os.File { +func (s Settings) Create(path string, name string) *os.File { + var file string + if _, err := os.Stat(".realize/"); err == nil { + file = filepath.Join(path, ".realize/", name) + } else { + file = filepath.Join(path, name) + } out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0655) s.Validate(err) return out diff --git a/settings/settings.go b/settings/settings.go index c44fca2..57f671e 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,9 +1,8 @@ package settings import ( - "os" - "gopkg.in/yaml.v2" + "os" ) type Settings struct { @@ -51,7 +50,9 @@ func (s *Settings) Record(out interface{}) error { return err } if _, err := os.Stat(".realize/"); os.IsNotExist(err) { - os.Mkdir(".realize", 0770) + if err = os.Mkdir(".realize/", 0770); err != nil { + return s.Write(s.Resources.Config, y) + } } return s.Write(".realize/"+s.Resources.Config, y) } diff --git a/watcher/exec.go b/watcher/exec.go index 283b276..4523819 100644 --- a/watcher/exec.go +++ b/watcher/exec.go @@ -81,8 +81,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text())) } if p.File.Streams { - path := filepath.Join(p.base, p.Resources.Output) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Output) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil { p.Fatal(err, "") diff --git a/watcher/watcher.go b/watcher/watcher.go index 774fea4..b9d3103 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -25,7 +25,6 @@ func (p *Project) watching() { defer func() { wg.Done() }() - if err != nil { log.Fatalln(p.pname(p.Name, 2), ":", p.Red.Bold(err.Error())) return @@ -312,8 +311,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { case "out": p.Buffer.StdOut = append(p.Buffer.StdOut, o) if p.File.Streams { - path := filepath.Join(p.base, p.Resources.Output) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Output) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { p.Fatal(err, "") @@ -322,8 +320,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { case "log": p.Buffer.StdLog = append(p.Buffer.StdLog, o) if p.File.Logs { - path := filepath.Join(p.base, p.Resources.Log) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Log) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { p.Fatal(err, "") @@ -332,8 +329,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { case "error": p.Buffer.StdErr = append(p.Buffer.StdErr, o) if p.File.Errors { - path := filepath.Join(p.base, p.Resources.Log) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Log) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { p.Fatal(err, "") From b896136af9e6f771036ab73936acfa7ad834004f Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 17 Dec 2016 01:50:43 +0100 Subject: [PATCH 11/11] realize version updated --- realize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realize.go b/realize.go index 4a148b2..364f86e 100644 --- a/realize.go +++ b/realize.go @@ -12,7 +12,7 @@ import ( const ( name = "Realize" - version = "1.2" + version = "1.2.1" description = "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths" config = "realize.yaml" output = "outputs.log"