Created
November 20, 2012 00:39
-
-
Save ninjudd/4115184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn extract-dependencies | |
"Extract all files proto depends on into dest." | |
[project proto-path protos dest] | |
(in-project (dissoc project :prep-tasks) | |
[proto-path (.getPath proto-path) | |
dest (.getPath dest) | |
protos protos] | |
(require '[clojure.java.io :as io])) | |
(letfn [(dependencies [proto-file] | |
(when (.exists proto-file) | |
(for [line (line-seq (io/reader proto-file)) | |
:when (.startsWith line "import")] | |
(second (re-matches #".*\"(.*)\".*" line)))))] | |
(loop [deps (mapcat #(dependencies (io/file proto-path %)) protos)] | |
(when-let [[dep & deps] (seq deps)] | |
(let [proto-file (io/file dest dep)] | |
(if (or (.exists (io/file proto-path dep)) | |
(.exists proto-file)) | |
(recur deps) | |
(do (.mkdirs (.getParentFile proto-file)) | |
(when-let [resource (io/resource (str "proto/" dep))] | |
(io/copy (io/reader resource) proto-file)) | |
(recur (concat deps (dependencies proto-file))))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment