Skip to content

Commit

Permalink
fix: watcher cleanup, sub process for watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Jul 10, 2023
1 parent 0c0f0c0 commit bfdb936
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func main() {
fmt.Println(cs.Blue(logPrefix).Green("Compiled ").Cyan("\"" + basePath + "\"").Green(" to ").Cyan("\"" + outPath + "\"").String())

if *serveFlag {
watcher.StartWatching()
go watcher.StartWatching()
runServer(*portFlag)
}

Expand Down Expand Up @@ -907,12 +907,6 @@ func (w *Watcher) RebuildFile(filePath string) {

func (w *Watcher) StartWatching() {

recompilingText := &color.ColorString{}
recompilingText.Blue(logPrefix).Gray("Recompiling...").Reset(" ")

recompiledText := &color.ColorString{}
recompiledText.Blue(logPrefix).Green("Recompiled!").Reset(" ")

go func() {
for {
select {
Expand All @@ -929,7 +923,9 @@ func (w *Watcher) StartWatching() {
onDebug(func() {
debugInfo("File Changed")
})
fmt.Println(recompilingText.String())

recompiledText := &color.ColorString{}
recompiledText.Blue(logPrefix).Green("Recompiled!").Reset(" ")

_, err := os.Stat(event.Name)
// Do nothing if the file doesn't exit, just continue
Expand All @@ -941,13 +937,20 @@ func (w *Watcher) StartWatching() {
// just rebuilt the whole folder since it could
// be a file from the public folder or the _layout file
if w.alvu.IsAlvuFile(event.Name) {
recompilingText := &color.ColorString{}
recompilingText.Blue(logPrefix).Cyan("Recompiling: ").Gray(event.Name).Reset(" ")
fmt.Println(recompilingText.String())
w.RebuildFile(event.Name)
} else {
recompilingText := &color.ColorString{}
recompilingText.Blue(logPrefix).Cyan("Recompiling: ").Gray("All").Reset(" ")
fmt.Println(recompilingText.String())
w.RebuildAlvu()
}

_clientNotifyReload()
fmt.Println(recompiledText.String())
continue
}
case err, ok := <-w.notify.Errors:
if !ok {
Expand Down

0 comments on commit bfdb936

Please sign in to comment.