-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.go
36 lines (33 loc) · 1.13 KB
/
watch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"github.com/crispgm/go-van/caravan"
"github.com/crispgm/go-van/deploy"
"github.com/rjeczalik/notify"
)
func watch(conf *caravan.Conf, deployer deploy.Deployer) {
caravan.PrintNotice("Starting to watch...")
caravan.Watch(*conf, func(ei notify.EventInfo) error {
f := caravan.NewFilter(conf.Exclude)
match, err := f.Exclude(ei.Path())
if err != nil {
caravan.PrintError("Exclude failed:", err)
return nil
}
if match {
caravan.PrintLog("IGNORE", ei.Path())
return nil
}
eventCtrl.FireEvent(caravan.NewEvent(caravan.HookOnChange, "", ei.Path(), caravan.GetFileName(ei.Path())))
return handleDeploy(*conf, deployer, ei)
})
}
func handleDeploy(conf caravan.Conf, deployer deploy.Deployer, ei notify.EventInfo) error {
output, err := deployer.Run(conf.Source, conf.Destination, conf.ExtraArgs)
if err != nil {
caravan.WarningSound()
caravan.PrintError(string(output))
eventCtrl.FireEvent(caravan.NewEvent(caravan.HookOnError, "", ei.Path(), caravan.GetFileName(ei.Path())))
}
eventCtrl.FireEvent(caravan.NewEvent(caravan.HookOnDeploy, "", ei.Path(), caravan.GetFileName(ei.Path())))
return err
}