Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created March 3, 2016 05:42
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 alandipert/b100723aa2efb3502f59 to your computer and use it in GitHub Desktop.
Save alandipert/b100723aa2efb3502f59 to your computer and use it in GitHub Desktop.
(require '[boot.pod :as pod]
'[boot.core :as core]
'[boot.from.digest :as digest]
'[boot.util :as util]
'[clojure.java.io :as io])
(core/deftask webjars
"Unpack all webjars into the fileset."
[]
(let [webjars (->> (pod/resolve-dependencies (core/get-env))
(filter #(#{"org.webjars" "org.webjars.bower"} (namespace (first (:dep %)))))
(map :jar))]
(util/info "Adding %d Webjars to the fileset...\n" (count webjars))
(with-pre-wrap [fs]
(reduce #(core/add-cached-resource
%1
(digest/md5 %2)
(partial pod/unpack-jar %2)
:include [#"^META-INF/resources/webjars.*$"]
:mergers pod/standard-jar-mergers)
fs
webjars))))
(core/deftask move-webjars
"Moves webjars from their default location to /bower_components. Strips versions from the path."
[]
(with-pre-wrap [fs]
(let [path-lib #(second (re-find #"^META-INF/resources/webjars/([^/]*)/.*$" %))
path-rel #(second (re-find #"^META-INF/resources/webjars/[^/]*/[^/]*/(.*)$" %))
bower? (fn [libs lib]
(when-let [tmp (->> (get libs lib)
(map (juxt (comp path-rel core/tmp-path) identity))
(filter #(= (first %) "bower.json"))
(map second)
first)]
(println (slurp (.getAbsolutePath (tmp-file tmp))))
(core/tmp-file tmp)))
libs (->> (core/input-files fs)
(core/by-re [#"^META-INF/resources/webjars.*$"])
(group-by (comp path-lib core/tmp-path)))
bower-libs (reduce (fn [m lib]
(if-let [bowerfile (bower? libs lib)]
(assoc m lib (core/json-parse (slurp bowerfile)))
m))
{}
(keys libs))
tmpd (core/tmp-dir!)]
(println libs)
(println bower-libs)
fs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment