From 70b1008caa78158abb56a9cd1a094f60f68e75a2 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 14 Jun 2015 10:03:23 -0500 Subject: [PATCH] rename `clone` to `publish`; add stricter error checking (closes #56) --- command.rkt | 26 +++++++++++++++----------- raco.rkt | 2 +- scribblings/raco.scrbl | 10 +++++----- scribblings/tutorial-third.scrbl | 2 +- world.rkt | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/command.rkt b/command.rkt index 68ed396..ad4fc5e 100644 --- a/command.rkt +++ b/command.rkt @@ -10,13 +10,15 @@ (define (handle-help) `(displayln (format "Pollen commands: -help show this message -start [dir] [port] starts project server in dir (default is current dir) +help show this message +start [dir] [port] starts project server in dir (default is current dir) (default port is ~a) -render [dir] [dest] render project 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)))) +render filename render filename only (can be source or output name) +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) diff --git a/raco.rkt b/raco.rkt index 55480f9..cfdf3ec 100644 --- a/raco.rkt +++ b/raco.rkt @@ -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 diff --git a/scribblings/raco.scrbl b/scribblings/raco.scrbl index 0a02d72..9915f88 100644 --- a/scribblings/raco.scrbl +++ b/scribblings/raco.scrbl @@ -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]. diff --git a/scribblings/tutorial-third.scrbl b/scribblings/tutorial-third.scrbl index 75c6774..3b1af5f 100644 --- a/scribblings/tutorial-third.scrbl +++ b/scribblings/tutorial-third.scrbl @@ -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}} ] diff --git a/world.rkt b/world.rkt index 6f19b06..37f07b4 100644 --- a/world.rkt +++ b/world.rkt @@ -59,4 +59,4 @@ (define check-directory-requires-in-render? (make-parameter #t)) -(define clone-directory-name "clone") +(define publish-directory-name "publish")