Merge pull request #72 from tockins/dev

Dev v1.4.1
This commit is contained in:
Alessio Pracchia 2017-08-09 00:11:55 +02:00 committed by GitHub
commit 87918aed27
9 changed files with 364 additions and 143 deletions

View File

@ -7,47 +7,53 @@
[![Join the chat at https://gitter.im/tockins/realize](https://badges.gitter.im/tockins/realize.svg)](https://gitter.im/tockins/realize?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Go Report Card](https://goreportcard.com/badge/github.com/tockins/realize)](https://goreportcard.com/report/github.com/tockins/realize)
<p align="center">
<img src="http://i.imgur.com/pkMDtrl.png" width="350px">
</p>
![Logo](http://i.imgur.com/8nr2s1b.jpg)
#### Realize is a Go tool that is focused to speed up and improve the developers workflow.
A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths
Automate your work pipeline, integrate additional tools of third party, define custom cli commands and reload projects at each changed without stop to write code.
<p align="center">
<img src="http://i.imgur.com/KpMSLnE.png">
</p>
![Preview](http://i.imgur.com/dJbNZjt.gif)
#### Features
- Highly customizable
- Config your project Step by Step
- 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
- Watch by FsNotify or by polling
- Setup step by step
- Live reload
- Support for multiple projects
- Output streams and error logs (support for save on a file)
- Web Panel (projects list, config settings, logs)
- Save logs on files
- Web panel for a smart view
- Build, install, run, test, fmt, generate, vet and much more
- Watch custom paths and specific file extensions
- Multiple watching methods (Polling, File watcher)
- Docker support
v 1.5
- [ ] Watch dependencies options
- [ ] Watch gopath dependencies
- [ ] Web panel, download logs
- [ ] Multiple configurations (dev, production)
- [ ] Support to ignore paths and files in gititnore
- [ ] Input redirection (wait for an input and redirect)
- [ ] Web panel full support
- [ ] Multiple configurations
- [ ] GoMobile support ?
- [ ] Ignore path and files in gititnore ?
#### Wiki
- [Getting Started](#installation-and-usage)
- [Getting Started](#installation)
- [Run cmd](#run) - Run a project
- [Add cmd](#add) - Add a new project
- [Init cmd](#init) - Make a custom config step by step
- [Remove cmd](#remove) - Remove a project
- [List cmd](#list) - List the projects
- [Config sample](#config-sample)
- [Support](#support)
- [Config sample](#config-sample) - Sample config file
- [Support](#support-us-and-suggest-an-improvement)
- ##### Installation
#### Installation
Run this to get/install:
```
$ go get github.com/tockins/realize
@ -60,7 +66,7 @@ $ go get github.com/tockins/realize
$ realize run
```
It will create a realize.yaml file if it doesn't exist already, adds the working directory as project and run the pipeline.
It will create a realize.yaml file if it doesn't exist already, add the working directory as project and run the pipeline.
The Run command supports the following custom parameters:
@ -75,6 +81,7 @@ $ go get github.com/tockins/realize
--legacy -> Enable legacy watch instead of Fsnotify watch
--generate -> Enable go generate
--test -> Enable go test
--open -> Open in default browser
```
Examples:
@ -154,6 +161,9 @@ $ go get github.com/tockins/realize
projects:
- name: coin
path: coin // project path
environment: // env variables
test: test
myvar: value
commands:
vet: true
fmt: true
@ -190,10 +200,6 @@ $ go get github.com/tockins/realize
file_log: false
file_err: false
```
###### Support us and suggest an improvement
- Start the project
#### Support us and suggest an improvement
- Chat with us [Gitter](https://gitter.im/tockins/realize)
- Suggest a new [Feature](https://github.com/tockins/realize/issues/new)

View File

@ -16,13 +16,13 @@ import (
)
const (
appVersion = "1.3"
appVersion = "1.4.1"
config = "realize.yaml"
outputs = "outputs.log"
errs = "errors.log"
logs = "logs.log"
host = "localhost"
port = 5001
port = 3001
interval = 200
)
@ -44,7 +44,6 @@ func main() {
if gopath == "" {
return errors.New("$GOPATH isn't set properly")
}
r = realize{
Sync: make(chan string),
Settings: settings.Settings{
@ -116,19 +115,12 @@ func main() {
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build."},
&cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Watch by polling instead of Watch by fsnotify."},
&cli.BoolFlag{Name: "server", Aliases: []string{"s"}, Value: false, Usage: "Enable server and open into the default browser."},
&cli.BoolFlag{Name: "open", Aliases: []string{"o"}, Value: false, Usage: "Open server directly in the default browser."},
&cli.BoolFlag{Name: "no-run", Aliases: []string{"nr"}, Value: false, Usage: "Disable go run"},
&cli.BoolFlag{Name: "no-install", Aliases: []string{"ni"}, Value: false, Usage: "Disable go install"},
&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing configurations."},
},
Action: func(p *cli.Context) error {
c := r
if p.String("name") != ""{
for index, project := range r.Blueprint.Projects{
if project.Name == p.String("name"){
c.Blueprint.Projects = []watcher.Project{r.Blueprint.Projects[index]}
}
}
}
if p.Bool("legacy") {
r.Config.Legacy = settings.Legacy{
Status: p.Bool("legacy"),
@ -144,15 +136,17 @@ func main() {
return err
}
}
if err := c.Server.Start(p); err != nil {
if err := r.Server.Start(p); err != nil {
return err
}
if err := c.Blueprint.Run(p); err != nil {
if err := r.Blueprint.Run(p); err != nil {
return err
}
if err := r.Record(c); err != nil {
if !p.Bool("no-config") {
if err := r.Record(r); err != nil {
return err
}
}
return nil
},
Before: before,

File diff suppressed because one or more lines are too long

View File

@ -41,6 +41,9 @@ func render(c echo.Context, path string, mime int) error {
case 4:
rs.Header().Set(echo.HeaderContentType, "image/svg+xml")
break
case 5:
rs.Header().Set(echo.HeaderContentType, "image/png")
break
}
rs.WriteHeader(http.StatusOK)
rs.Write(data)
@ -49,7 +52,14 @@ func render(c echo.Context, path string, mime int) error {
// Start the web server
func (s *Server) Start(p *cli.Context) (err error) {
if s.Server.Status || p.Bool("server") {
if p.Bool("server") {
s.Server.Status = p.Bool("server")
}
if p.Bool("open") {
s.Server.Open = p.Bool("open")
}
if s.Server.Status {
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 2,
@ -66,8 +76,8 @@ func (s *Server) Start(p *cli.Context) (err error) {
e.GET("/assets/css/app.css", func(c echo.Context) error {
return render(c, "assets/assets/css/app.css", 3)
})
e.GET("/app/components/projects/index.html", func(c echo.Context) error {
return render(c, "assets/app/components/projects/index.html", 1)
e.GET("/app/components/settings/index.html", func(c echo.Context) error {
return render(c, "assets/app/components/settings/index.html", 1)
})
e.GET("/app/components/project/index.html", func(c echo.Context) error {
return render(c, "assets/app/components/project/index.html", 1)
@ -75,12 +85,30 @@ func (s *Server) Start(p *cli.Context) (err error) {
e.GET("/app/components/index.html", func(c echo.Context) error {
return render(c, "assets/app/components/index.html", 1)
})
e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/github-logo.svg", 4)
e.GET("/assets/img/svg/ic_settings_black_24px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_settings_black_24px.svg", 4)
})
e.GET("/assets/img/svg/ic_fullscreen_black_24px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_fullscreen_black_24px.svg", 4)
})
e.GET("/assets/img/svg/ic_add_black_24px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_add_black_24px.svg", 4)
})
e.GET("/assets/img/svg/ic_keyboard_backspace_black_24px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_keyboard_backspace_black_24px.svg", 4)
})
e.GET("/assets/img/svg/ic_error_black_48px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_error_black_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_remove_black_24px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_remove_black_24px.svg", 4)
})
e.GET("/assets/img/svg/logo.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/logo.svg", 4)
})
e.GET("/assets/img/favicon-32x32.png", func(c echo.Context) error {
return render(c, "assets/assets/img/favicon-32x32.png", 5)
})
e.GET("/assets/img/svg/ic_swap_vertical_circle_black_48px.svg", func(c echo.Context) error {
return render(c, "assets/assets/img/svg/ic_swap_vertical_circle_black_48px.svg", 4)
})
@ -89,7 +117,7 @@ func (s *Server) Start(p *cli.Context) (err error) {
e.GET("/ws", s.projects)
go e.Start(string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
if s.Open || p.Bool("open") {
if s.Open {
_, err = Open("http://" + string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
if err != nil {
return err

View File

@ -1,9 +1,9 @@
package settings
import (
yaml "gopkg.in/yaml.v2"
"os"
"time"
yaml "gopkg.in/yaml.v2"
)
var Dir = ".realize/"

View File

@ -5,7 +5,9 @@ import (
"fmt"
"github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2"
"os"
"strings"
"time"
)
// Run launches the toolchain for each project
@ -16,7 +18,7 @@ func (h *Blueprint) Run(p *cli.Context) error {
wg.Add(len(h.Projects))
for k, element := range h.Projects {
tools := tools{}
if element.Cmds.Fmt{
if element.Cmds.Fmt {
tools.Fmt = tool{
status: &h.Projects[k].Cmds.Fmt,
cmd: "gofmt",
@ -24,7 +26,7 @@ func (h *Blueprint) Run(p *cli.Context) error {
name: "Go Fmt",
}
}
if element.Cmds.Generate{
if element.Cmds.Generate {
tools.Generate = tool{
status: &h.Projects[k].Cmds.Generate,
cmd: "go",
@ -32,7 +34,7 @@ func (h *Blueprint) Run(p *cli.Context) error {
name: "Go Generate",
}
}
if element.Cmds.Test{
if element.Cmds.Test {
tools.Test = tool{
status: &h.Projects[k].Cmds.Test,
cmd: "go",
@ -51,6 +53,14 @@ func (h *Blueprint) Run(p *cli.Context) error {
h.Projects[k].tools = tools
h.Projects[k].parent = h
h.Projects[k].path = h.Projects[k].Path
// env variables
for key, item := range h.Projects[k].Environment {
if err := os.Setenv(key, item); err != nil {
h.Projects[k].Buffer.StdErr = append(h.Projects[k].Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""})
}
}
if h.Legacy.Status {
go h.Projects[k].watchByPolling()
} else {
@ -69,7 +79,6 @@ func (h *Blueprint) Add(p *cli.Context) error {
Name: h.Name(p.String("name"), p.String("path")),
Path: h.Path(p.String("path")),
Cmds: Cmds{
Vet: p.Bool("vet"),
Fmt: !p.Bool("no-fmt"),
Test: p.Bool("test"),
@ -178,5 +187,5 @@ func (h *Blueprint) check() error {
h.Clean()
return nil
}
return errors.New("there are no projects")
return errors.New("There are no projects")
}

View File

@ -85,11 +85,11 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
for output.Scan() {
text := output.Text()
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(text))
if isError || isErrorText(text) {
if isError && !isErrorText(text) {
out := BufferOut{Time: time.Now(), Text: text, Type: "Go Run"}
p.print("error", out, msg, "")
} else {
out := BufferOut{Time: time.Now(), Text: text}
out := BufferOut{Time: time.Now(), Text: text, Type: "Go Run"}
p.print("out", out, msg, "")
}
}

View File

@ -36,6 +36,7 @@ type Project struct {
base string
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"`
Cmds Cmds `yaml:"commands" json:"commands"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Watcher Watcher `yaml:"watcher" json:"watcher"`

View File

@ -286,10 +286,10 @@ func (p *Project) tool(path string, tool tool) error {
// Cmd calls an wrapper for execute the commands after/before
func (p *Project) cmd(flag string, changed bool) {
for _, cmd := range p.Watcher.Scripts {
if strings.ToLower(cmd.Type) == flag{
if strings.ToLower(cmd.Type) == flag {
if changed && cmd.Changed || !changed && cmd.Startup {
errors, logs := p.command(cmd)
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Bold("Command"), style.Green.Bold("\"") + cmd.Command + style.Green.Bold("\""))
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Bold("Command"), style.Green.Bold("\"")+cmd.Command+style.Green.Bold("\""))
out = BufferOut{Time: time.Now(), Text: cmd.Command, Type: flag}
if logs != "" {
p.print("log", out, msg, "")
@ -323,7 +323,7 @@ func (p *Project) ignore(str string) bool {
}
// Routines launches the toolchain run, build, install
func (p *Project) routines(wr *sync.WaitGroup,channel chan bool, watcher watcher, file string) {
func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watcher, file string) {
if len(file) > 0 {
p.cmd("before", true)
path := filepath.Dir(file)
@ -396,9 +396,6 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
p.Fatal(err, "")
}
}
if msg != "" {
log.Print(msg)
}
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.Streams.FileErr {
@ -412,10 +409,10 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
p.Fatal(err, "")
}
}
}
if msg != "" {
log.Print(msg)
}
}
if stream != "" {
fmt.Print(stream)
}