简体   繁体   中英

boot-clj: task to extract only certain folder from fileset + rename it

Consider a Clojure project with a resources folder, which contains some files and another folder called "public" holding some web-content.

I'm looking for a boot task, that compiles ClojureScript, then moves just the public directory to another directory in the global filesystem. Finally the folder should be renamed to "project- version ".

The following does not work since move-files does only work for files and not for directories. However, I think it clarifies the idea:

(def project-name "My")
(def project-version "0.1.0")

(deftask store-web-dir []
  (let [dir-name (format "%s-%s" project-name project-version)]
    (comp
     (cljs :optimizations :advanced)
     (move-files :files {"public" dir-name})  ;; should rename the dir public to ..
     (copy :output-dir "/some/path/web_dirs"
           :matching #{(re-pattern (str "^" dir-name  "$"))}))))

After this, there should be a folder /some/path/web_dirs/My-0.1.0 , which contains the compiled version of all public files of the project.

sift and target might help you ( boot sift -h ).

I do something similar to what you describe here: https://github.com/timothypratley/voterx/blob/master/build.boot

(sift :invert true :include #{#"js/devcards.out" #"js/app\.out" #"\S+\.cljs\.edn"})
(target :dir #{"public"})

target places the files in a specific output directory, I'm sure you could change it based on version. Something like (str "public" +version+)

In summary, doing it outside of the cljs build itself is probably the ticket.

Inspired by comments and answers, I'll post the way I took here:

(deftask only-public []
  (comp 
   (sift :include #{#"^public"})
   (sift :move {#"^public/(.*)$" "$1"})))


(deftask store-web-dir []
  (comp
   (cljs :optimizations :advanced)
   (only-public)
   (target :dir #{(format "/some/path/web_dirs/%s-%s"
                          project-name project-version)})))

The functions move-files and copy , the ones I tried to use before, come from community tasks(boot-copy & boot-files), however it looks like the built-in sift , combined with target is much more general and perfect for this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM