2017-04-13 12:48:48 +00:00
|
|
|
package watcher
|
2016-09-01 22:17:19 +00:00
|
|
|
|
|
|
|
import (
|
2017-04-16 10:04:40 +00:00
|
|
|
"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
|
2017-04-16 10:04:40 +00:00
|
|
|
type logWriter struct{}
|
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 {
|
2017-04-13 12:48:48 +00:00
|
|
|
*settings.Settings `yaml:"-"`
|
|
|
|
Projects []Project `yaml:"projects,omitempty" json:"projects,omitempty"`
|
|
|
|
Sync chan string `yaml:"-"`
|
2016-09-01 22:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Project defines the informations of a single project
|
|
|
|
type Project struct {
|
2017-06-16 09:15:56 +00:00
|
|
|
settings.Settings `yaml:"-"`
|
|
|
|
LastChangedOn time.Time `yaml:"-" json:"-"`
|
|
|
|
base string
|
2017-08-07 21:01:02 +00:00
|
|
|
Name string `yaml:"name" json:"name"`
|
|
|
|
Path string `yaml:"path" json:"path"`
|
2017-08-07 21:14:59 +00:00
|
|
|
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"`
|
2017-08-07 21:01:02 +00:00
|
|
|
Cmds Cmds `yaml:"commands" json:"commands"`
|
|
|
|
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
|
|
|
|
Watcher Watcher `yaml:"watcher" json:"watcher"`
|
|
|
|
Buffer Buffer `yaml:"-" json:"buffer"`
|
|
|
|
ErrorOutputPattern string `yaml:"errorOutputPattern,omitempty" json:"errorOutputPattern,omitempty"`
|
2017-06-16 09:15:56 +00:00
|
|
|
parent *Blueprint
|
|
|
|
path string
|
|
|
|
tools tools
|
2017-04-16 10:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type tools struct {
|
|
|
|
Fmt, Test, Generate, Vet tool
|
|
|
|
}
|
|
|
|
|
|
|
|
type tool struct {
|
|
|
|
status *bool
|
|
|
|
cmd string
|
|
|
|
options []string
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2017-08-11 20:24:18 +00:00
|
|
|
// Cmds go supported
|
2017-04-16 10:04:40 +00:00
|
|
|
type Cmds struct {
|
2017-08-31 07:43:11 +00:00
|
|
|
Vet bool `yaml:"vet,omitempty" json:"vet,omitempty"`
|
2017-09-03 18:00:40 +00:00
|
|
|
Fmt Cmd `yaml:"fmt,omitempty" json:"fmt,omitempty"`
|
|
|
|
Test Cmd `yaml:"test,omitempty" json:"test,omitempty"`
|
|
|
|
Generate Cmd `yaml:"generate,omitempty" json:"generate,omitempty"`
|
2017-09-05 17:39:52 +00:00
|
|
|
Install Cmd `yaml:"install" json:"install"`
|
2017-08-31 07:43:11 +00:00
|
|
|
Build Cmd `yaml:"build,omitempty" json:"build,omitempty"`
|
|
|
|
Run bool `yaml:"run,omitempty" json:"run,omitempty"`
|
2017-04-16 10:04:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 20:24:18 +00:00
|
|
|
// Cmd buildmode options
|
2017-04-16 10:04:40 +00:00
|
|
|
type Cmd struct {
|
2017-08-31 07:43:11 +00:00
|
|
|
Status bool `yaml:"status,omitempty" json:"status,omitempty"`
|
2017-04-16 10:04:40 +00:00
|
|
|
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
|
2016-09-01 22:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Watcher struct defines the livereload's logic
|
|
|
|
type Watcher struct {
|
2016-12-26 23:14:29 +00:00
|
|
|
Paths []string `yaml:"paths" json:"paths"`
|
2017-09-05 17:39:52 +00:00
|
|
|
Exts []string `yaml:"extensions" json:"extensions"`
|
|
|
|
Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"`
|
|
|
|
Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"`
|
2016-12-26 23:14:29 +00:00
|
|
|
Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"`
|
2016-12-25 17:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Command options
|
|
|
|
type Command struct {
|
2016-12-26 23:14:29 +00:00
|
|
|
Type string `yaml:"type" json:"type"`
|
|
|
|
Command string `yaml:"command" json:"command"`
|
2017-06-19 10:08:51 +00:00
|
|
|
Path string `yaml:"path,omitempty" json:"path,omitempty"`
|
2017-08-31 07:43:11 +00:00
|
|
|
Global bool `yaml:"global,omitempty" json:"global,omitempty"`
|
2017-09-03 18:00:40 +00:00
|
|
|
Output bool `yaml:"output,omitempty" json:"output,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))
|
|
|
|
}
|