Skip to content

Instantly share code, notes, and snippets.

@mobileink
Created February 16, 2016 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mobileink/67cefbe1a3ed5f32d2ad to your computer and use it in GitHub Desktop.
Save mobileink/67cefbe1a3ed5f32d2ad to your computer and use it in GitHub Desktop.
copy assets task
(core/deftask assets
"copy assets to build-dir"
[v verbose bool "Print trace messages"]
(core/with-pre-wrap [fs]
(let [tgt (core/tmp-dir!)
in-files (->> fs
core/output-files
(core/not-by-ext [".clj"])
(map (juxt core/tmp-path core/tmp-file)))]
(doseq [[rel-path in-file] in-files]
(let [out-file (doto (io/file tgt (str rel-path "/foo")) io/make-parents)]
(println " in-file: " in-file)
(println "tmp out-file: " out-file)
(core/cp fs in-file out-file)))
(core/add-asset fs tgt)
(core/commit! fs))))
@micha
Copy link

micha commented Feb 16, 2016

(core/deftask assets
  "copy assets to build-dir"
  [v verbose bool "Print trace messages"]
  (core/with-pre-wrap [fs]
    (let [tgt (core/tmp-dir!)
          in-files (->> fs
                        core/output-files
                        (core/not-by-ext [".clj"])
                        (map (juxt core/tmp-path core/tmp-file)))]
      (doseq [[rel-path in-file] in-files]
        (let [out-file (doto (io/file tgt rel-path "foo") io/make-parents)]
          (println "     in-file: " in-file)
          (println "tmp out-file: " out-file)
          (clojure.java.io/copy in-file out-file))) ;; use regular io/copy here
      (-> fs (core/add-asset tgt) core/commit!)))) ;; fs is an immutable value, operations return a new immutable fs, commit! mutates the filesystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment