realize files moved in .realize hidden dir

This commit is contained in:
alessio 2016-12-17 01:48:04 +01:00
parent e6c821ada4
commit 1148047438
5 changed files with 16 additions and 14 deletions

View File

@ -17,7 +17,6 @@ const (
config = "realize.yaml" config = "realize.yaml"
output = "outputs.log" output = "outputs.log"
log = "logs.log" log = "logs.log"
err = "errors.log"
host = "localhost" host = "localhost"
port = 5000 port = 5000
server = true server = true

View File

@ -3,6 +3,7 @@ package settings
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
) )
// Scan return a byte stream of a given file // 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 // 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) out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0655)
s.Validate(err) s.Validate(err)
return out return out

View File

@ -1,9 +1,8 @@
package settings package settings
import ( import (
"os"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"os"
) )
type Settings struct { type Settings struct {
@ -51,7 +50,9 @@ func (s *Settings) Record(out interface{}) error {
return err return err
} }
if _, err := os.Stat(".realize/"); os.IsNotExist(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) return s.Write(".realize/"+s.Resources.Config, y)
} }

View File

@ -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())) log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text()))
} }
if p.File.Streams { if p.File.Streams {
path := filepath.Join(p.base, p.Resources.Output) f := p.Create(p.base, p.parent.Resources.Output)
f := p.Create(path)
t := time.Now() t := time.Now()
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil { if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
p.Fatal(err, "") p.Fatal(err, "")

View File

@ -25,7 +25,6 @@ func (p *Project) watching() {
defer func() { defer func() {
wg.Done() wg.Done()
}() }()
if err != nil { if err != nil {
log.Fatalln(p.pname(p.Name, 2), ":", p.Red.Bold(err.Error())) log.Fatalln(p.pname(p.Name, 2), ":", p.Red.Bold(err.Error()))
return return
@ -312,8 +311,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
case "out": case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o) p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.File.Streams { if p.File.Streams {
path := filepath.Join(p.base, p.Resources.Output) f := p.Create(p.base, p.parent.Resources.Output)
f := p.Create(path)
t := time.Now() t := time.Now()
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
p.Fatal(err, "") p.Fatal(err, "")
@ -322,8 +320,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
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 {
path := filepath.Join(p.base, p.Resources.Log) f := p.Create(p.base, p.parent.Resources.Log)
f := p.Create(path)
t := time.Now() t := time.Now()
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
p.Fatal(err, "") p.Fatal(err, "")
@ -332,8 +329,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) {
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 {
path := filepath.Join(p.base, p.Resources.Log) f := p.Create(p.base, p.parent.Resources.Log)
f := p.Create(path)
t := time.Now() t := time.Now()
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil {
p.Fatal(err, "") p.Fatal(err, "")