(ns less4clj.webjars
  (:import [java.io File]
           [org.webjars WebJarAssetLocator]))

(def ^:private webjars-pattern
  #"META-INF/resources/webjars/([^/]+)/([^/]+)/(.*)")

(defn- asset-path [resource]
  (let [[_ name version path] (re-matches webjars-pattern resource)]
    (str name File/separator path)))

(defn asset-map
  "Create map of asset path to classpath resource url. Asset path is
  the resource url without webjars part."
  []
  (->> (.listAssets (WebJarAssetLocator.) "")
       (map (juxt asset-path identity))
       (into {})))

(comment
  (time (asset-map)))

(ns less4clj.webjars
  (:import [java.io File]
           [org.webjars WebJarAssetLocator]))

(def ^:private webjars-pattern
  #"META-INF/resources/webjars/([^/]+)/([^/]+)/(.*)")

(defn- asset-path [resource]
  (let [[_ name version path] (re-matches webjars-pattern resource)]
    (str name File/separator path)))

(defn asset-map
  "Create map of asset path to classpath resource url. Asset path is
  the resource url without webjars part."
  []
  (->> (vals (.getFullPathIndex (WebJarAssetLocator.)))
       (map (juxt asset-path identity))
       (into {})))

(comment
  (time (asset-map)))

Use getFullPathIndex to list wejars assets
Use getFullPathIndex to list wejars assets

listAssets calls getFullPathIndex and filters the values. Calling
getFullPathIndex directly avoids filtering.

Deraen/less4clj