Skip to content

Commit

Permalink
Merge pull request oxequa#157 from tockins/dev
Browse files Browse the repository at this point in the history
v2.0.1
  • Loading branch information
asoseil committed Jan 14, 2018
2 parents de37b00 + bfc49f7 commit 9d7dd6d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
43 changes: 23 additions & 20 deletions .realize.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
settings:
recovery:
events: true
tools: true
index: true # print files indexing
events: false # print each event
tools: false # print each tool
legacy:
force: false
interval: 0s
force: false # enable polling watcher
interval: 0s # polling interval
server:
status: false
open: true
port: 3000
host: localhost
status: false # web panel
open: true # open in default browser
port: 3000 # server port
host: localhost # server host
schema:
- name: realize
path: .
commands:
generate:
status: false
install:
- name: realize # project name
path: . # project path, '.' is for wdir path
commands: # all go commands supported
generate: # go generate
status: true
vet:
install: # go install
status: true
test:
vet: # go vet
status: true
fmt:
test: # go test
status: true
fmt: # go fmt
status: true
watcher:
paths:
paths: # paths watched
- /
extensions:
extensions: # extensions watched
- go
- html
- css
- js
ignored_paths:
ignored_paths: # paths ignored
- .git
- .realize
- .idea
- vendor
- realize/assets
- realize/bindata.go
32 changes: 19 additions & 13 deletions realize/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ type Project struct {
stop chan bool
files int64
folders int64
lastFile string
last last
paths []string
lastTime time.Time
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"`
Expand All @@ -64,6 +63,12 @@ type Project struct {
ErrorOutputPattern string `yaml:"errorOutputPattern,omitempty" json:"errorOutputPattern,omitempty"`
}

// Last is used to save info about last file changed
type last struct{
file string
time time.Time
}

// Response exec
type Response struct {
Name string
Expand Down Expand Up @@ -286,9 +291,9 @@ L:
select {
case event := <-p.watcher.Events():
if p.parent.Settings.Recovery.Events {
log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Now(), "LastTime:", p.lastTime)
log.Println("File:", event.Name, "LastFile:", p.last.file, "Time:", time.Now(), "LastTime:", p.last.time)
}
if time.Now().Truncate(time.Second).After(p.lastTime) || event.Name != p.lastFile {
if time.Now().Truncate(time.Second).After(p.last.time) {
// switch event type
switch event.Op {
case fsnotify.Chmod:
Expand All @@ -310,15 +315,13 @@ L:
if fi.IsDir() {
filepath.Walk(event.Name, p.walk)
} else {
if event.Op != fsnotify.Write || event.Name != p.lastFile {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload(event.Name, p.stop)
}
p.lastTime = time.Now().Truncate(time.Second)
p.lastFile = event.Name
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload(event.Name, p.stop)
p.last.time = time.Now().Truncate(time.Second)
p.last.file = event.Name
}
}
}
Expand Down Expand Up @@ -479,6 +482,9 @@ func (p *Project) walk(path string, info os.FileInfo, err error) error {
if p.Validate(path, true) {
result := p.watcher.Walk(path, p.init)
if result != "" {
if p.parent.Settings.Recovery.Index {
log.Println("Indexing",path)
}
if info.IsDir() {
// tools dir
p.tools(p.stop, path, info)
Expand Down
1 change: 1 addition & 0 deletions realize/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Settings struct {
}

type Recovery struct {
Index bool
Events bool
Tools bool
}
Expand Down

0 comments on commit 9d7dd6d

Please sign in to comment.