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

278 Views Asked by At

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.

2

There are 2 best solutions below

3
On

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.

0
On

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.