-
Notifications
You must be signed in to change notification settings - Fork 1
/
tailo.go
55 lines (43 loc) · 1.03 KB
/
tailo.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
// tailo is a wrapper for the Tailwind CSS CLI that
// facilitates the download and of the CLI and the
// config file.
package tailo
import (
"fmt"
"os"
"path/filepath"
"github.com/fsnotify/fsnotify"
)
type extensions []string
func (e extensions) Has(ext string) bool {
for _, v := range e {
if v == ext {
return true
}
}
return false
}
// Extensions to watch for changes.
var watchExtensions = extensions{".html", ".css"}
func buildWatcher() (*fsnotify.Watcher, error) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return watcher, fmt.Errorf("error creating watcher: %w", err)
}
// Add all files that need to be watched to the
// watcher so it notifies the errors that it needs to
// restart.
err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if !watchExtensions.Has(filepath.Ext(path)) {
return nil
}
return watcher.Add(path)
})
if err != nil {
return watcher, fmt.Errorf("error loading paths: %w", err)
}
return watcher, err
}