-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
84 lines (69 loc) · 1.99 KB
/
app.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package autofresh
import (
"fmt"
"log"
"path/filepath"
"github.com/devpkg/autofresh/config"
"github.com/devpkg/autofresh/watcher"
"github.com/devpkg/autofresh/watchman"
)
const logo = `
___ __ ______ __
/ | __ __/ /_____ / ____/_______ _____/ /_
/ /| |/ / / / __/ __ \/ /_ / ___/ _ \/ ___/ __ \
/ ___ / /_/ / /_/ /_/ / __/ / / / __(__ ) / / /
/_/ |_\__,_/\__/\____/_/ /_/ \___/____/_/ /_/
`
const (
subscriptionName = "test_autofresh"
)
var (
startChannel chan bool
stopChannel chan bool
watchmanCommand string
buildCommand string
runCommand string
suffixes []string
)
// Start application. Will check if watchman exists at that path,
// retrieve the socket name, instantiate a connection to watchman using Unix
// Sockets, subscribe to the directory, and begin reading the subscription
// messages and building the executable.
func Start(conf config.Config) {
if !conf.Hidebanner {
fmt.Println(logo)
}
startChannel = make(chan bool)
stopChannel = make(chan bool)
buildCommand = conf.Build
runCommand = conf.Run
watchmanCommand = conf.Watchman
suffixes = conf.Suffixes
// isRunning := false
// watchman.NewWatchman(watchmanCommand,
directory, err := filepath.Abs("./")
if err != nil {
log.Fatalf("Directory absolute file path cannot be found. Error: %s\n", err.Error())
}
wm := watchman.NewWatchman(watchmanCommand, directory, subscriptionName)
defer wm.Close()
builder := watcher.NewBuilder(wm, buildCommand, runCommand)
wm.Subscribe(directory, suffixes)
builder.Refresh()
// go read(conn, startChannel) // read in separate goroutine
}
// func read(c net.Conn, startChannel chan bool) {
// d := json.NewDecoder(c)
// m := make(map[string]interface{})
// var start = true
// for {
// if err := d.Decode(&m); err != nil {
// if err != io.EOF {
// log.Fatalf("Error decoding, error: %s\n", err.Error())
// }
// }
// fmt.Println(m)
// startChannel <- start
// start = !start
// }
// }