printer method updated
This commit is contained in:
parent
043a694d46
commit
09a581c129
21
realize.go
21
realize.go
|
@ -15,10 +15,11 @@ const (
|
||||||
version = "1.2.1"
|
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"
|
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"
|
config = "realize.yaml"
|
||||||
output = "outputs.log"
|
streams = "streams.log"
|
||||||
log = "logs.log"
|
errs = "errors.log"
|
||||||
|
logs = "logs.log"
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = 5000
|
port = 5001
|
||||||
server = true
|
server = true
|
||||||
open = false
|
open = false
|
||||||
)
|
)
|
||||||
|
@ -47,9 +48,10 @@ func init() {
|
||||||
Flimit: 0,
|
Flimit: 0,
|
||||||
},
|
},
|
||||||
Resources: c.Resources{
|
Resources: c.Resources{
|
||||||
Config: config,
|
Config: config,
|
||||||
Output: output,
|
Streams: streams,
|
||||||
Log: log,
|
Logs: logs,
|
||||||
|
Errors: errs,
|
||||||
},
|
},
|
||||||
Server: c.Server{
|
Server: c.Server{
|
||||||
Enabled: server,
|
Enabled: server,
|
||||||
|
@ -137,9 +139,10 @@ func main() {
|
||||||
Flimit: 0,
|
Flimit: 0,
|
||||||
},
|
},
|
||||||
Resources: c.Resources{
|
Resources: c.Resources{
|
||||||
Config: config,
|
Config: config,
|
||||||
Output: output,
|
Streams: streams,
|
||||||
Log: log,
|
Logs: logs,
|
||||||
|
Errors: errs,
|
||||||
},
|
},
|
||||||
Server: c.Server{
|
Server: c.Server{
|
||||||
Enabled: server,
|
Enabled: server,
|
||||||
|
|
|
@ -12,14 +12,19 @@ type Colors struct {
|
||||||
Magenta
|
Magenta
|
||||||
Green
|
Green
|
||||||
}
|
}
|
||||||
|
|
||||||
// Red color
|
// Red color
|
||||||
type Red struct{}
|
type Red struct{}
|
||||||
|
|
||||||
// Blue color
|
// Blue color
|
||||||
type Blue struct{}
|
type Blue struct{}
|
||||||
|
|
||||||
// Yellow color
|
// Yellow color
|
||||||
type Yellow struct{}
|
type Yellow struct{}
|
||||||
|
|
||||||
// Magenta color
|
// Magenta color
|
||||||
type Magenta struct{}
|
type Magenta struct{}
|
||||||
|
|
||||||
// Green color
|
// Green color
|
||||||
type Green struct{}
|
type Green struct{}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package settings
|
package settings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings defines a group of general settings
|
// Settings defines a group of general settings
|
||||||
|
@ -28,9 +28,10 @@ type Server struct {
|
||||||
|
|
||||||
// Resources defines the files generated by realize
|
// Resources defines the files generated by realize
|
||||||
type Resources struct {
|
type Resources struct {
|
||||||
Config string `yaml:"-" json:"-"`
|
Config string `yaml:"-" json:"-"`
|
||||||
Output string `yaml:"output" json:"output"`
|
Streams string `yaml:"streams" json:"output"`
|
||||||
Log string `yaml:"log" json:"log"`
|
Logs string `yaml:"logs" json:"log"`
|
||||||
|
Errors string `yaml:"errors" json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read from config file
|
// Read from config file
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -55,11 +56,9 @@ func (p *Project) watching() {
|
||||||
file := event.Name[:i] + ext
|
file := event.Name[:i] + ext
|
||||||
path := filepath.Dir(event.Name[:i])
|
path := filepath.Dir(event.Name[:i])
|
||||||
if event.Name[:i] != "" && inArray(ext, p.Watcher.Exts) {
|
if event.Name[:i] != "" && inArray(ext, p.Watcher.Exts) {
|
||||||
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file})
|
msg := fmt.Sprintln(p.pname(p.Name, 4), ":", p.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), p.Magenta.Bold(file))
|
||||||
go func() {
|
out := BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
|
||||||
p.parent.Sync <- "sync"
|
p.print("log", out, msg, "")
|
||||||
}()
|
|
||||||
log.Println(p.pname(p.Name, 4), ":", p.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), p.Magenta.Bold(file))
|
|
||||||
// stop and run again
|
// stop and run again
|
||||||
if p.Run {
|
if p.Run {
|
||||||
close(channel)
|
close(channel)
|
||||||
|
@ -94,10 +93,9 @@ func (p *Project) install() error {
|
||||||
p.print("error", out, msg, stream)
|
p.print("error", out, msg, stream)
|
||||||
} else {
|
} 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"))
|
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"}
|
out := BufferOut{Time: time.Now(), Text: "Installed after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
||||||
p.print("log", out, msg, stream)
|
p.print("log", out, msg, stream)
|
||||||
}
|
}
|
||||||
p.sync()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -114,7 +112,7 @@ func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
||||||
select {
|
select {
|
||||||
case <-runner:
|
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"))
|
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"}
|
out := BufferOut{Time: time.Now(), Text: "Has been run after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
||||||
p.print("log", out, msg, "")
|
p.print("log", out, msg, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -134,10 +132,9 @@ func (p *Project) build() error {
|
||||||
p.print("error", out, msg, stream)
|
p.print("error", out, msg, stream)
|
||||||
} else {
|
} else {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Builded")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
msg := fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Builded")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
out := BufferOut{Time: time.Now(), Text: "Builded"}
|
out := BufferOut{Time: time.Now(), Text: "Builded after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
||||||
p.print("log", out, msg, stream)
|
p.print("log", out, msg, stream)
|
||||||
}
|
}
|
||||||
p.sync()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -145,9 +142,6 @@ func (p *Project) build() error {
|
||||||
|
|
||||||
// Fmt calls an implementation of the "go fmt"
|
// Fmt calls an implementation of the "go fmt"
|
||||||
func (p *Project) fmt(path string) error {
|
func (p *Project) fmt(path string) error {
|
||||||
defer func() {
|
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
if p.Fmt {
|
if p.Fmt {
|
||||||
if stream, err := p.goTools(p.base, "gofmt", "-s", "-w", "-e", path); err != nil {
|
if stream, err := p.goTools(p.base, "gofmt", "-s", "-w", "-e", path); err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Fmt"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Fmt"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
|
||||||
|
@ -161,9 +155,6 @@ func (p *Project) fmt(path string) error {
|
||||||
|
|
||||||
// Generate calls an implementation of the "go generate"
|
// Generate calls an implementation of the "go generate"
|
||||||
func (p *Project) generate(path string) error {
|
func (p *Project) generate(path string) error {
|
||||||
defer func() {
|
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
if p.Generate {
|
if p.Generate {
|
||||||
if stream, err := p.goTools(path, "go", "generate"); err != nil {
|
if stream, err := p.goTools(path, "go", "generate"); err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Generate"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Generate"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
|
||||||
|
@ -177,9 +168,6 @@ func (p *Project) generate(path string) error {
|
||||||
|
|
||||||
// Test calls an implementation of the "go test"
|
// Test calls an implementation of the "go test"
|
||||||
func (p *Project) test(path string) error {
|
func (p *Project) test(path string) error {
|
||||||
defer func() {
|
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
if p.Test {
|
if p.Test {
|
||||||
if stream, err := p.goTools(path, "go", "test"); err != nil {
|
if stream, err := p.goTools(path, "go", "test"); err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Test"), p.Red.Regular("there are some errors in "), ":", p.Magenta.Bold(path))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Test"), p.Red.Regular("there are some errors in "), ":", p.Magenta.Bold(path))
|
||||||
|
@ -280,7 +268,9 @@ func (p *Project) walks(watcher *fsnotify.Watcher) error {
|
||||||
return errors.New(base + " path doesn't exist")
|
return errors.New(base + " path doesn't exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println(p.pname(p.Name, 1), ":", p.Blue.Bold("Watching"), p.Magenta.Bold(files), "file/s", p.Magenta.Bold(folders), "folder/s")
|
msg := fmt.Sprintln(p.pname(p.Name, 1), ":", p.Blue.Bold("Watching"), p.Magenta.Bold(files), "file/s", p.Magenta.Bold(folders), "folder/s")
|
||||||
|
out := BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(files, 10) + " files/s " + strconv.FormatInt(folders, 10) + " folder/s"}
|
||||||
|
p.print("log", out, msg, "")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +317,7 @@ func (p *Project) pname(name string, color int) string {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print on files
|
// Print on files, cli, ws
|
||||||
func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
||||||
switch t {
|
switch t {
|
||||||
case "out":
|
case "out":
|
||||||
|
@ -335,34 +325,51 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
|
||||||
if p.File.Streams {
|
if p.File.Streams {
|
||||||
f := p.Create(p.base, p.parent.Resources.Streams)
|
f := p.Create(p.base, p.parent.Resources.Streams)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + strings.ToUpper(" "+p.Name) + " : " + o.Text + "\r\n"); err != nil {
|
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
|
||||||
|
if _, err := f.WriteString(strings.Join(s, " ")); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if msg != "" && p.Cli.Streams {
|
||||||
|
log.Print(msg)
|
||||||
|
}
|
||||||
case "log":
|
case "log":
|
||||||
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
|
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
|
||||||
if p.File.Logs {
|
if p.File.Logs {
|
||||||
f := p.Create(p.base, p.parent.Resources.Logs)
|
f := p.Create(p.base, p.parent.Resources.Logs)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + strings.ToUpper(" "+p.Name) + " : " + o.Text + "\r\n"); err != nil {
|
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
|
||||||
|
if stream != "" {
|
||||||
|
s = []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n", stream}
|
||||||
|
}
|
||||||
|
if _, err := f.WriteString(strings.Join(s, " ")); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if msg != "" {
|
||||||
|
log.Print(msg)
|
||||||
|
}
|
||||||
case "error":
|
case "error":
|
||||||
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
|
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
|
||||||
if p.File.Errors {
|
if p.File.Errors {
|
||||||
f := p.Create(p.base, p.parent.Resources.Errors)
|
f := p.Create(p.base, p.parent.Resources.Errors)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + strings.ToUpper(" "+p.Name) + " : " + o.Text + "\r\n"); err != nil {
|
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Type, o.Text, o.Path, "\r\n"}
|
||||||
|
if stream != "" {
|
||||||
|
s = []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Type, o.Text, o.Path, "\r\n", stream}
|
||||||
|
}
|
||||||
|
if _, err := f.WriteString(strings.Join(s, " ")); err != nil {
|
||||||
p.Fatal(err, "")
|
p.Fatal(err, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if msg != "" {
|
||||||
}
|
log.Print(msg)
|
||||||
if msg != "" {
|
}
|
||||||
log.Print(msg)
|
|
||||||
}
|
}
|
||||||
if stream != "" {
|
if stream != "" {
|
||||||
fmt.Print(stream)
|
fmt.Print(stream)
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
|
p.parent.Sync <- "sync"
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue