rename `clone` to `publish`; add stricter error checking (closes #56)

pull/58/head
Matthew Butterick 10 years ago
parent 9fd921d135
commit 70b1008caa

@ -16,7 +16,9 @@ start [dir] [port] starts project server in dir (default is current dir)
render [dir] [dest] render project in dir (default is current dir)
to dest (default is desktop)
render filename render filename only (can be source or output name)
clone copy project to desktop without source files" ,(world:current-server-port))))
publish copy project to desktop without source files
publish [dir] [dest] copy project in dir to dest without source files
(warning: overwrites existing dest dir)" ,(world:current-server-port))))
(define (handle-render path-args)
@ -59,10 +61,10 @@ clone copy project to desktop without source files" ,(world:curr
(start-server)))))
(define (handle-clone directory rest-args)
(define (handle-publish directory rest-args)
(define target-path (or
(and rest-args (not (null? rest-args)) (path->complete-path (string->path (car rest-args))))
(build-path (find-system-path 'desk-dir) (string->path world:clone-directory-name))))
(build-path (find-system-path 'desk-dir) (string->path world:publish-directory-name))))
`(begin
(require racket/file pollen/file racket/list)
@ -76,14 +78,16 @@ clone copy project to desktop without source files" ,(world:curr
(andmap equal? prefix (take xs (length prefix)))))
((explode-path possible-subdir) . has-prefix? . (explode-path possible-superdir)))
(define source-dir (simplify-path ,directory))
(when (not (directory-exists? source-dir)) (error 'clone (format "source directory ~a does not exist" source-dir)))
(when (not (directory-exists? source-dir)) (error 'publish (format "source directory ~a does not exist" source-dir)))
(define target-dir (simplify-path ,target-path))
(when (source-dir . contains-directory? . target-dir) (error 'clone "aborted because target directory for cloning (~a) can't be inside source directory (~a)" target-dir source-dir))
(displayln "Cloning ...")
(when (source-dir . contains-directory? . target-dir) (error 'publish "aborted because target directory for publishing (~a) can't be inside source directory (~a)" target-dir source-dir))
(when (target-dir . contains-directory? . source-dir) (error 'publish "aborted because target directory for publishing (~a) can't contain source directory (~a)" target-dir source-dir))
(when (equal? target-dir (current-directory)) (error 'publish "aborted because target directory for publishing (~a) can't be the same as current directory (~a)" target-dir (current-directory)))
(displayln "publishing ...")
(when (directory-exists? target-dir) (delete-directory/files target-dir))
(copy-directory/files source-dir target-dir)
(for-each delete-it (find-files pollen-related-file? target-dir))
(displayln (format "Completed to ~a" target-dir))))
(displayln (format "completed to ~a" target-dir))))
(define (handle-else command)
`(if (regexp-match #rx"(shit|fuck)" ,command)

@ -35,7 +35,7 @@
[(#f "help") (handle-help)]
[("start") (handle-start (path->directory-path first-arg-or-current-dir) port-arg)]
[("render") (handle-render (cons first-arg-or-current-dir (map very-nice-path (cdr (vector->list (current-command-line-arguments))))))]
[("clone") (handle-clone first-arg-or-current-dir rest-args)]
[("clone" "publish") (handle-publish first-arg-or-current-dir rest-args)]
[else (handle-else arg-command-name)]))))
(module+ main

@ -83,15 +83,15 @@ Alternatively, the command can take a variable number of path arguments. @racket
> raco pollen render *.html.pm}
@section{@racket[raco pollen clone]}
@section{@racket[raco pollen publish]}
Make a copy of the project directory on the desktop, and remove any source files or other Pollen-related files. (This function is pretty lame, and I invite suggestions for improvement.)
Make a copy of the project directory on the desktop, but without any source files or other Pollen-related files. (This function is pretty lame, and I invite suggestions for improvement.)
@racket[raco pollen clone _source-dir] will clone source from @racket[_source-dir] onto the desktop.
@racket[raco pollen publish _project-dir] will publish the project in @racket[_project-dir] onto the desktop in a folder called @racket[publish]. @bold{Warning}: if @racket[publish] already exists on the desktop, it will be overwritten.
@racket[raco pollen clone _source-dir _dest-dir] will clone source from @racket[_source-dir] to @racket[_dest-dir] rather than the desktop.
@racket[raco pollen publish _project-dir _dest-dir] will publish the project in @racket[_project-dir] to @racket[_dest-dir] rather than the desktop. @bold{Warning}: if @racket[_dest-dir] already exists, it will be overwritten by the newly published directory.
If you're already in the project directory and want to clone somewhere other than the desktop, use @racket[raco pollen clone _. _dest-dir].
If you're already in your project directory and want to publish somewhere other than the desktop, use @racket[raco pollen publish _. _dest-dir].

@ -22,7 +22,7 @@ Now you're getting to the good stuff. In this tutorial, you'll use Pollen to pub
@item{Using @racket[decode] with Pollen markup}
@;item{@exec{raco pollen render} and @exec{raco pollen clone}}
@;item{@exec{raco pollen render} and @exec{raco pollen publish}}
]

@ -59,4 +59,4 @@
(define check-directory-requires-in-render? (make-parameter #t))
(define clone-directory-name "clone")
(define publish-directory-name "publish")

Loading…
Cancel
Save