add --force option to raco pollen render, take 2

dev-nonsettable
Matthew Butterick 5 years ago
parent d61aea60ee
commit 1de0eff38d

@ -1,4 +1,4 @@
#lang racket/base #lang debug racket/base
(require racket/file (require racket/file
racket/path racket/path
racket/vector racket/vector
@ -104,6 +104,7 @@ version print the version" (current-server-port) (make-publish-di
(define render-with-subdirs? (make-parameter #f)) (define render-with-subdirs? (make-parameter #f))
(define render-parallel? (make-parameter #f)) (define render-parallel? (make-parameter #f))
(define special-output? (make-parameter #f)) (define special-output? (make-parameter #f))
(define force-render? (make-parameter #f))
(define parsed-args (define parsed-args
(command-line #:program "raco pollen render" (command-line #:program "raco pollen render"
#:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front #:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front
@ -113,6 +114,7 @@ version print the version" (current-server-port) (make-publish-di
[("-r" "--recursive") "Render subdirectories recursively" [("-r" "--recursive") "Render subdirectories recursively"
(render-with-subdirs? 'recursive)] (render-with-subdirs? 'recursive)]
[("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)] [("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)]
[("-f" "--force") "Force render" (force-render? #true)]
#:once-any #:once-any
[("-d" "--dry-run") "Print paths that would be rendered" (special-output? 'dry-run)] [("-d" "--dry-run") "Print paths that would be rendered" (special-output? 'dry-run)]
[("-n" "--null") "Suppress file output" (special-output? 'null)] [("-n" "--null") "Suppress file output" (special-output? 'null)]
@ -122,7 +124,15 @@ version print the version" (current-server-port) (make-publish-di
#:args other-args #:args other-args
other-args)) other-args))
(define timestamp (current-seconds)) ; keeps timestamp consistent through whole render
(define (handle-batch-render paths) (define (handle-batch-render paths)
(when (force-render?)
;; forcing works like `touch`: updates the mod date of the files,
;; which invalidates any cached results.
(for* ([path (in-list paths)]
[sp (in-value (get-source path))]
#:when sp)
(file-or-directory-modify-seconds sp timestamp)))
(apply render-batch (map very-nice-path paths) #:parallel (render-parallel?) #:special (special-output?))) (apply render-batch (map very-nice-path paths) #:parallel (render-parallel?) #:special (special-output?)))
(parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases (parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases

@ -1 +1 @@
1588261516 1588526073

@ -83,6 +83,8 @@ This command can be invoked two ways: in source mode or directory mode.
In both modes, the optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be rendered by this command without actually doing so. In both modes, the optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be rendered by this command without actually doing so.
In both modes, the optional @exec{--force} or @exec{-f} switch forces a fresh render from source, even if the file is already cached, by updating the modification date of the file (à la @exec{touch}). Thus, if modification dates are important to you, don't use this option.
In both modes, the optional @exec{--null} or @exec{-n} switch renders as usual, but doesn't write any files. (Convenient if you're arranging special render behavior, for instance writing to a database or network server.) In both modes, the optional @exec{--null} or @exec{-n} switch renders as usual, but doesn't write any files. (Convenient if you're arranging special render behavior, for instance writing to a database or network server.)

Loading…
Cancel
Save