2016-09-01 22:17:19 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2016-11-01 09:56:12 +00:00
|
|
|
c "github.com/tockins/realize/settings"
|
2016-09-01 22:17:19 +00:00
|
|
|
"log"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2016-12-25 17:08:22 +00:00
|
|
|
// Watcher interface used by polling/fsnotify watching
|
|
|
|
type watcher interface {
|
|
|
|
Add(path string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Polling watcher
|
|
|
|
type pollWatcher struct {
|
|
|
|
paths map[string]bool
|
|
|
|
}
|
|
|
|
|
2016-09-18 11:50:15 +00:00
|
|
|
// Log struct
|
2016-11-01 09:56:12 +00:00
|
|
|
type logWriter struct {
|
|
|
|
c.Colors
|
|
|
|
}
|
2016-09-18 11:50:15 +00:00
|
|
|
|
2016-12-17 10:43:27 +00:00
|
|
|
// Blueprint struct contains a projects list
|
2016-09-01 22:17:19 +00:00
|
|
|
type Blueprint struct {
|
2016-11-01 09:56:12 +00:00
|
|
|
*c.Settings `yaml:"-"`
|
2016-11-20 16:58:52 +00:00
|
|
|
Projects []Project `yaml:"projects,omitempty" json:"projects,omitempty"`
|
2016-11-01 09:56:12 +00:00
|
|
|
Sync chan string `yaml:"-"`
|
2016-09-01 22:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Project defines the informations of a single project
|
|
|
|
type Project struct {
|
2016-11-01 09:56:12 +00:00
|
|
|
c.Settings `yaml:"-"`
|
2016-11-20 16:58:52 +00:00
|
|
|
LastChangedOn time.Time `yaml:"-" json:"-"`
|
2016-09-22 22:41:42 +00:00
|
|
|
base string
|
2016-11-20 16:58:52 +00:00
|
|
|
Name string `yaml:"name" json:"name"`
|
|
|
|
Path string `yaml:"path" json:"path"`
|
|
|
|
Fmt bool `yaml:"fmt" json:"fmt"`
|
|
|
|
Test bool `yaml:"test" json:"test"`
|
2016-12-17 10:43:27 +00:00
|
|
|
Generate bool `yaml:"generate" json:"generate"`
|
|
|
|
Bin bool `yaml:"bin" json:"bin"`
|
|
|
|
Build bool `yaml:"build" json:"build"`
|
|
|
|
Run bool `yaml:"run" json:"run"`
|
2016-12-25 17:08:22 +00:00
|
|
|
Params []string `yaml:"params,omitempty" json:"params,omitempty"`
|
2016-11-20 16:58:52 +00:00
|
|
|
Watcher Watcher `yaml:"watcher" json:"watcher"`
|
2016-12-25 17:08:22 +00:00
|
|
|
Cli Cli `yaml:"cli,omitempty" json:"cli,omitempty"`
|
|
|
|
File File `yaml:"file,omitempty" json:"file,omitempty"`
|
2016-11-20 16:58:52 +00:00
|
|
|
Buffer Buffer `yaml:"-" json:"buffer"`
|
2016-09-22 22:41:42 +00:00
|
|
|
parent *Blueprint
|
2016-11-01 09:56:12 +00:00
|
|
|
path string
|
2016-09-01 22:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Watcher struct defines the livereload's logic
|
|
|
|
type Watcher struct {
|
2016-12-25 17:08:22 +00:00
|
|
|
Preview bool `yaml:"preview" json:"preview"`
|
|
|
|
Paths []string `yaml:"paths" json:"paths"`
|
|
|
|
Ignore []string `yaml:"ignore_paths" json:"ignore"`
|
|
|
|
Exts []string `yaml:"exts" json:"exts"`
|
|
|
|
Commands []Command `yaml:"commands,omitempty" json:"commands,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Command options
|
|
|
|
type Command struct {
|
|
|
|
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
|
|
|
Command string `yaml:"command,omitempty" json:"command,omitempty"`
|
|
|
|
Path string `yaml:"path,omitempty" json:"path,omitempty"`
|
2016-11-11 16:23:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 10:43:27 +00:00
|
|
|
// Cli output status, enables or disables
|
2016-11-11 16:23:17 +00:00
|
|
|
type Cli struct {
|
2016-11-20 16:58:52 +00:00
|
|
|
Streams bool `yaml:"streams" json:"streams"`
|
2016-11-11 16:23:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 10:43:27 +00:00
|
|
|
// File determinates the status of each log files (streams, logs, errors)
|
2016-11-11 16:23:17 +00:00
|
|
|
type File struct {
|
2016-12-25 17:08:22 +00:00
|
|
|
Streams bool `yaml:"streams,omitempty" json:"streams,omitempty"`
|
|
|
|
Logs bool `yaml:"logs,omitempty" json:"logs,omitempty"`
|
|
|
|
Errors bool `yaml:"errors,omitempty" json:"errors,omitempty"`
|
2016-09-01 22:17:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 10:43:27 +00:00
|
|
|
// Buffer define an array buffer for each log files
|
2016-09-17 14:46:26 +00:00
|
|
|
type Buffer struct {
|
2016-11-20 16:58:52 +00:00
|
|
|
StdOut []BufferOut `json:"stdOut"`
|
|
|
|
StdLog []BufferOut `json:"stdLog"`
|
|
|
|
StdErr []BufferOut `json:"stdErr"`
|
2016-10-14 08:47:43 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 10:43:27 +00:00
|
|
|
// BufferOut is used for exchange information between "realize cli" and "web realize"
|
2016-10-14 08:47:43 +00:00
|
|
|
type BufferOut struct {
|
2016-11-20 16:58:52 +00:00
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Stream string `json:"stream"`
|
|
|
|
Errors []string `json:"errors"`
|
2016-09-17 14:46:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 22:17:19 +00:00
|
|
|
// Initialize the application
|
|
|
|
func init() {
|
|
|
|
log.SetFlags(0)
|
|
|
|
log.SetOutput(new(logWriter))
|
|
|
|
}
|