add dry-run switch to raco pollen publish

pull/218/head
Matthew Butterick 5 years ago
parent 9f674a4e70
commit f13eec8459

@ -136,14 +136,14 @@ version print the version" (current-server-port) (make-publish-di
(define dirlist (directory-list dir)) (define dirlist (directory-list dir))
(define paths-to-render (define paths-to-render
(match (filter pagetree-source? dirlist) (match (filter pagetree-source? dirlist)
;; if there are no static pagetrees, use make-project-pagetree ;; if there are no static pagetrees, use make-project-pagetree
;; (which will synthesize a pagetree if needed, which includes all sources) ;; (which will synthesize a pagetree if needed, which includes all sources)
[(? null?) [(? null?)
(message (format "rendering generated pagetree for directory ~a" dir)) (message (format "rendering generated pagetree for directory ~a" dir))
(cdr (make-project-pagetree dir))] (cdr (make-project-pagetree dir))]
[pagetree-sources [pagetree-sources
(message (format "rendering preproc & pagetree files in directory ~a" dir)) (message (format "rendering preproc & pagetree files in directory ~a" dir))
(append (filter preproc-source? dirlist) pagetree-sources)])) (append (filter preproc-source? dirlist) pagetree-sources)]))
(handle-batch-render paths-to-render) (handle-batch-render paths-to-render)
(when (render-with-subdirs?) (when (render-with-subdirs?)
(for ([path (in-list dirlist)] (for ([path (in-list dirlist)]
@ -207,12 +207,14 @@ version print the version" (current-server-port) (make-publish-di
(define command-name ; either "publish" or "clone" (define command-name ; either "publish" or "clone"
(vector-ref (current-command-line-arguments) 0)) (vector-ref (current-command-line-arguments) 0))
(define force-target-overwrite? (make-parameter #true)) (define force-target-overwrite? (make-parameter #true))
(define dry-run? (make-parameter #false))
(define other-args (command-line (define other-args (command-line
;; drop command name ;; drop command name
#:argv (vector-drop (current-command-line-arguments) 1) #:argv (vector-drop (current-command-line-arguments) 1)
#:once-each #:once-each
[("-c" "--confirm") "Confirm overwrite of existing dest dir" [("-c" "--confirm") "Confirm overwrite of existing dest dir"
(force-target-overwrite? #f)] (force-target-overwrite? #f)]
[("-d" "--dry-run") "Check paths that would be published" (dry-run? #true)]
#:args other-args #:args other-args
other-args)) other-args))
;; other-args looks like (list [maybe-source-dir-arg] [maybe-dest-dir-arg]) ;; other-args looks like (list [maybe-source-dir-arg] [maybe-dest-dir-arg])
@ -235,7 +237,6 @@ version print the version" (current-server-port) (make-publish-di
(when (equal? dest-dir (current-directory)) (when (equal? dest-dir (current-directory))
(error 'publish "aborted because destination directory for publishing (~a) can't be the same as current directory (~a)" dest-dir (current-directory))) (error 'publish "aborted because destination directory for publishing (~a) can't be the same as current directory (~a)" dest-dir (current-directory)))
(message (string-append (format "publishing from ~a to ~a ..." source-dir dest-dir)))
(define do-publish-operation? (define do-publish-operation?
(or (not (directory-exists? dest-dir)) (or (not (directory-exists? dest-dir))
(force-target-overwrite?) (force-target-overwrite?)
@ -245,20 +246,34 @@ version print the version" (current-server-port) (make-publish-di
[(y yes) #true] [(y yes) #true]
[else #false])))) [else #false]))))
(cond (cond
[do-publish-operation? [dry-run?
(when (directory-exists? dest-dir) (message "publish: start dry run")
(delete-directory/files dest-dir)) (message (format "would publish from ~a to ~a" source-dir dest-dir))
(copy-directory/files source-dir dest-dir) (cond
;; if source-dir is provided, we want it to be treated as current-directory. [(directory-exists? dest-dir)
;; if no source-dir is provided, it is set to current-directory, (message (string-append (format "directory ~a exists (but can be overwritten)" dest-dir)))]
;; so the parameterize is a no-op. [(directory-exists? (simplify-path (build-path dest-dir "..")))
(parameterize* ([current-directory source-dir] (message (string-append (format "directory ~a does not exist (but can be created)" dest-dir)))]
[current-project-root (current-directory)]) [else
(define (delete-from-publish-dir? p) (raise-user-error 'publish "dry run failure: directory path ~a is defective (neither directory nor parent directory exists)" dest-dir)])
(and (omitted-path? p) (not (extra-path? p)))) (message "publish: end dry run")]
(for-each delete-it! (find-files delete-from-publish-dir? dest-dir))) [else
(message "publish completed")] (message (string-append (format "publishing from ~a to ~a ..." source-dir dest-dir)))
[else (message "publish aborted")])) (cond
[do-publish-operation?
(when (directory-exists? dest-dir)
(delete-directory/files dest-dir))
(copy-directory/files source-dir dest-dir)
;; if source-dir is provided, we want it to be treated as current-directory.
;; if no source-dir is provided, it is set to current-directory,
;; so the parameterize is a no-op.
(parameterize* ([current-directory source-dir]
[current-project-root (current-directory)])
(define (delete-from-publish-dir? p)
(and (omitted-path? p) (not (extra-path? p))))
(for-each delete-it! (find-files delete-from-publish-dir? dest-dir)))
(message "publish completed")]
[else (message "publish aborted")])]))
(define (handle-unknown command) (define (handle-unknown command)
(match command (match command

@ -1 +1 @@
1582236997 1582753630

@ -159,6 +159,7 @@ You can determine the default publishing destination for a project by overriding
Certain files and directories are automatically omitted from the published directory, including Racket and Pollen sources, Pollen caches, and source-control directories (like @tt{.git} and @tt{.svn}). You can omit other files by overriding @racket[default-omitted-path?]. You can override these omissions — that is, force a path to be published — by overriding @racket[default-extra-path?]. Certain files and directories are automatically omitted from the published directory, including Racket and Pollen sources, Pollen caches, and source-control directories (like @tt{.git} and @tt{.svn}). You can omit other files by overriding @racket[default-omitted-path?]. You can override these omissions — that is, force a path to be published — by overriding @racket[default-extra-path?].
The optional @exec{--dry-run} or @exec{-d} switch prints the source and destination directories for publishing without actually doing so. If the destination-directory path cannot be created, an error will arise.
@section{@exec{raco pollen setup}} @section{@exec{raco pollen setup}}

Loading…
Cancel
Save