add --force option to raco pollen render

dev-nonsettable
Matthew Butterick 5 years ago
parent 0f7a3f4721
commit d2f7905a3d

@ -104,6 +104,7 @@ version print the version" (current-server-port) (make-publish-di
(define render-with-subdirs? (make-parameter #f))
(define render-parallel? (make-parameter #f))
(define special-output? (make-parameter #f))
(define force-render? (make-parameter #f))
(define parsed-args
(command-line #:program "raco pollen render"
#: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"
(render-with-subdirs? 'recursive)]
[("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)]
[("-f" "--force") "Force render" (force-render? #true)]
#:once-any
[("-d" "--dry-run") "Print paths that would be rendered" (special-output? 'dry-run)]
[("-n" "--null") "Suppress file output" (special-output? 'null)]
@ -123,7 +125,9 @@ version print the version" (current-server-port) (make-publish-di
other-args))
(define (handle-batch-render paths)
(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?)
#:force (force-render?)))
(parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases
(let loop ([args parsed-args])

@ -1 +1 @@
1588261516
1588447067

@ -161,8 +161,10 @@
(define current-null-output? (make-parameter #f))
(define+provide/contract (render-batch #:parallel [wants-parallel-render? #false]
#:special [special-output #false] . paths-in)
((#:parallel any/c) (#:special (or/c boolean? symbol?)) #:rest (listof pathish?) . ->* . void?)
#:special [special-output #false]
#:force [force-render? #false]. paths-in)
((#:parallel any/c) (#:special (or/c boolean? symbol?)
#:force boolean?) #:rest (listof pathish?) . ->* . void?)
;; Why not just (for-each render ...)?
;; Because certain files will pass through multiple times (e.g., templates)
;; And with render, they would be rendered repeatedly.
@ -183,10 +185,10 @@
[(null? expanded-source-paths) (message "[no paths to render]")]
[(eq? special-output 'dry-run) (for-each message expanded-source-paths)]
[else (parameterize ([current-null-output? (eq? special-output 'null)])
(for-each render-to-file-if-needed
(for-each (λ (sp) (render-to-file-if-needed sp #:force force-render?))
(match wants-parallel-render?
;; returns crashed jobs for serial rendering
[#false expanded-source-paths]
;; `parallel-render` returns crashed jobs for serial rendering
[jobs-arg (parallel-render expanded-source-paths jobs-arg)])))]))
(define (pagetree->paths pagetree-or-path)
@ -238,7 +240,7 @@
(define render-thunk (or maybe-render-thunk (λ () (render source-path template-path output-path)))) ; returns either string or bytes
(define render-result
(cond
[render-cache-activated?
[(and render-cache-activated? (not force?))
(define key (paths->key 'output source-path template-path output-path))
(hash-ref! ram-cache
;; within a session, this will prevent repeat players like "template.html.p"
@ -258,9 +260,9 @@
#:exists 'replace
#:mode (if (string? render-result) 'text 'binary)))))
(define+provide/contract (render-to-file-if-needed source-path [maybe-template-path #f] [maybe-output-path #f] [maybe-render-thunk #f])
((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?) (or/c #f procedure?)) . ->* . void?)
(render-to-file-base 'render-to-file-if-needed #f source-path maybe-output-path maybe-template-path maybe-render-thunk))
(define+provide/contract (render-to-file-if-needed source-path [maybe-template-path #f] [maybe-output-path #f] [maybe-render-thunk #f] #:force [force-render? #false])
((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?) (or/c #f procedure?) #:force boolean?) . ->* . void?)
(render-to-file-base 'render-to-file-if-needed force-render? source-path maybe-output-path maybe-template-path maybe-render-thunk))
(define+provide/contract (render-to-file source-path [maybe-template-path #f] [maybe-output-path #f] [maybe-render-thunk #f])
((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?) (or/c #f procedure?)) . ->* . void?)

@ -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{--force} or @exec{-f} switch forces a fresh render from source, even if the file is already cached.
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