Skip to content

Commit 5c3b42c

Browse files
committed
feat(runner): add exclude_file (#39)
1 parent 3409634 commit 5c3b42c

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

air_example.conf

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ include_ext = ["go", "tpl", "tmpl", "html"]
1818
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
1919
# Watch these directories if you specified.
2020
include_dir = []
21+
# Exclude files.
22+
exclude_file = []
2123
# It's not necessary to trigger build each time file changes if it's too frequent.
2224
delay = 1000 # ms
2325
# Stop to run old binary when build errors occur.

runner/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type cfgBuild struct {
3232
IncludeExt []string `toml:"include_ext"`
3333
ExcludeDir []string `toml:"exclude_dir"`
3434
IncludeDir []string `toml:"include_dir"`
35+
ExcludeFile []string `toml:"exclude_file"`
3536
Delay int `toml:"delay"`
3637
StopOnError bool `toml:"stop_on_error"`
3738
}

runner/engine.go

+3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func (e *Engine) watchDir(path string) error {
151151
e.watchNewDir(ev.Name, removeEvent(ev))
152152
break
153153
}
154+
if e.isExcludeFile(ev.Name) {
155+
break
156+
}
154157
if !e.isIncludeExt(ev.Name) {
155158
break
156159
}

runner/util.go

+10
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ func (e *Engine) isIncludeExt(path string) bool {
113113
return false
114114
}
115115

116+
func (e *Engine) isExcludeFile(path string) bool {
117+
cleanName := cleanPath(e.config.rel(path))
118+
for _, d := range e.config.Build.ExcludeFile {
119+
if d == cleanName {
120+
return true
121+
}
122+
}
123+
return false
124+
}
125+
116126
func (e *Engine) writeBuildErrorLog(msg string) error {
117127
var err error
118128
f, err := os.OpenFile(e.config.buildLogPath(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

0 commit comments

Comments
 (0)