Skip to content

Commit 11e3881

Browse files
committed
1 parent 17d8afc commit 11e3881

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

main.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,35 @@ func (w *Watcher) hashDir() (uint64, bool, error) {
6464

6565
err := filepath.Walk(w.dir, func(path string, info os.FileInfo, err error) error {
6666
if err != nil {
67-
return err
67+
log.Printf("Error accessing %s: %v", path, err)
68+
return nil
69+
}
70+
if info == nil {
71+
log.Printf("No info for %s", path)
72+
return nil
6873
}
74+
6975
relPath, _ := filepath.Rel(w.dir, path)
7076

7177
if info.IsDir() {
72-
if info.Name()[0] == '.' {
73-
return filepath.SkipDir
74-
}
75-
if !w.shouldProcess(relPath) {
78+
// Skip hidden subdirs, but not root
79+
if info.Name() != "." && info.Name()[0] == '.' {
7680
return filepath.SkipDir
7781
}
7882
return nil
7983
}
8084

81-
if info.Name()[0] == '.' {
82-
return nil
83-
}
85+
// Apply file excludes
8486
if !w.shouldProcess(relPath) {
8587
return nil
8688
}
8789

90+
// Include in hash
8891
h.Write([]byte(relPath))
8992
h.Write([]byte(fmt.Sprintf("%d", info.Size())))
9093
h.Write([]byte(info.ModTime().String()))
9194

95+
// Check dep file change
9296
if w.depFile != "" && filepath.Base(path) == filepath.Base(w.depFile) {
9397
if info.ModTime() != w.prevDepMTime {
9498
depChanged = true
@@ -121,7 +125,6 @@ func (w *Watcher) runBuild(depChanged bool) error {
121125
return err
122126
}
123127
}
124-
125128
log.Println("Running build command...")
126129
return w.runShell(w.buildCmd)
127130
}
@@ -185,16 +188,15 @@ func (w *Watcher) Run() {
185188
}
186189

187190
func printBanner() {
188-
fmt.Println("🚀 Poly Watcher — The universal build-run watcher for your projects. Change it. Build it. Run it. Repeat.")
191+
fmt.Println("🚀 poly-watcher — The universal build-run watcher for your projects. Change it. Build it. Run it. Repeat.")
189192
fmt.Println("Example:")
190-
fmt.Println(` poly-watcher --depfile=go.mod --depcommand="go mod tidy && go mod download" --build="go build -o myapp ." --run="./myapp" --include=.go --exclude=.git,.polycode`)
193+
fmt.Println(` poly-watcher --root=./myapp --depfile=go.mod --depcommand="go mod tidy && go mod download" --build="go build -o myapp ." --run="./myapp" --include=.go --exclude=.git,.polycode`)
191194
fmt.Println()
192195
}
193196

194197
func main() {
195198
printBanner()
196199

197-
dir := flag.String("dir", ".", "Working directory to watch")
198200
buildCmd := flag.String("build", "echo 'No build command specified'", "Build command to run on change")
199201
runCmd := flag.String("run", "echo 'No run command specified'", "Run command to execute built app")
200202
depFile := flag.String("depfile", "", "Dependency file to monitor for changes (e.g. go.mod, package.json)")
@@ -214,11 +216,7 @@ func main() {
214216
excludes = strings.Split(*excludeDirs, ",")
215217
}
216218

217-
if err := os.Chdir(*dir); err != nil {
218-
log.Fatalf("Failed to change directory: %v", err)
219-
}
220-
221219
watcher := NewWatcher(".", *interval, *buildCmd, *runCmd, *depFile, *depCmd, includes, excludes)
222-
log.Println("Starting watcher...")
220+
log.Println("Starting poly-watcher...")
223221
watcher.Run()
224222
}

0 commit comments

Comments
 (0)