Skip to content

Commit

Permalink
cli+runner: s/track/watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Oct 22, 2024
1 parent ecd1aa6 commit 8eeaa96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions koyo-lib/koyo/cli.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,25 @@
(string->path dynamic-module-path)
(infer-dynamic-module-path))))

(define track-file?-proc
(define watch-file?-proc
(if (and (null? watch-patterns)
(null? watch-excludes))
track-file?
watch-file?
(lambda (p)
(define track?
(define watch?
(and
(ormap (λ (re) (regexp-match? re p)) watch-patterns)
(not (ormap (λ (re) (regexp-match? re p)) watch-excludes))))
(begin0 track?
(when (and track? watch-verbose?)
(begin0 watch?
(when (and watch? watch-verbose?)
(let ([t (if (directory-exists? p) "directory" "file")])
(log-watcher-debug "tracking ~a ~a" t p)))))))
(log-watcher-debug "watching ~a ~a" t p)))))))

(run-forever
#:recompile? recompile?
#:errortrace? errortrace?
#:server-timeout server-timeout
#:track-file?-proc track-file?-proc
#:watch-file?-proc watch-file?-proc
(path->complete-path dynamic-module-path)))

(define ((handle-unknown command))
Expand Down
16 changes: 8 additions & 8 deletions koyo-lib/koyo/runner.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
[#:recompile? boolean?
#:errortrace? boolean?
#:server-timeout (and/c real? positive?)
#:track-file?-proc (-> (or/c path? path-string?) boolean?)]
#:watch-file?-proc (-> (or/c path? path-string?) boolean?)]
void?)]))

(define-logger runner)
(define-logger watcher)

(define (track-file? p)
(define (watch-file? p)
(if (directory-exists? p)
(match/values (split-path p)
[(_ (app path->string (regexp "^\\.")) _) #f]
Expand All @@ -37,9 +37,9 @@
[else #f])))

(module+ private
(provide log-watcher-debug track-file?))
(provide log-watcher-debug watch-file?))

(define (code-change-evt root-path track?)
(define (code-change-evt root-path watch?)
(let ([root-path (simplify-path root-path)])
(apply
choice-evt
Expand All @@ -49,7 +49,7 @@
(lambda (p)
(or
(equal? p root-path)
(track? p)))
(watch? p)))
root-path))]
#:when (file-exists? p))
(define chg
Expand All @@ -66,7 +66,7 @@
#:recompile? [recompile? #t]
#:errortrace? [errortrace? #t]
#:server-timeout [server-timeout 30]
#:track-file?-proc [track-file? track-file?]) ;; noqa
#:watch-file?-proc [watch-file? watch-file?]) ;; noqa
(file-stream-buffer-mode (current-output-port) 'line)
(file-stream-buffer-mode (current-error-port) 'line)
(maximize-fd-limit!
Expand Down Expand Up @@ -164,10 +164,10 @@
(lambda (status)
(when (eq? status 'done-error)
(log-runner-warning "application process failed; waiting for changes before reloading")
(sync (code-change-evt root-path track-file?)))
(sync (code-change-evt root-path watch-file?)))
(process-loop)))
(handle-evt
(code-change-evt root-path track-file?)
(code-change-evt root-path watch-file?)
(lambda (changed-path)
(reload changed-path)
(unless (symbol? (sync/timeout 0 stopped-evt))
Expand Down

0 comments on commit 8eeaa96

Please sign in to comment.