diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41abc6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +target/ +node_modules/ +checkouts/ +pom.xml +pom.xml.asc +*.iml +*.jar +*.js.map +*.class +.cpcache +.cljs-cache +.shadow-cljs +.cljs-repl +.cljs_node_repl +.idea +.lein-* +.nrepl-* +/tmp +.DS_Store +yarn.lock +package-lock.json +/package.json +*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..ae40cb0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +This is a utility used by `shadow-cljs` to resolve/download dependencies. + +https://github.com/thheller/shadow-cljs diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..e55d787 --- /dev/null +++ b/project.clj @@ -0,0 +1,15 @@ +(defproject shadow-cljs/launcher "1.2.0" + :description "CLJS development tools" + :url "https://github.com/thheller/shadow-cljs" + :dependencies + [[org.clojure/clojure "1.9.0"] + [com.cemerick/pomegranate "1.0.0"] + [org.slf4j/slf4j-nop "1.7.25"]] + + :source-paths + ["src/main"] + + :profiles + {:uberjar + {:aot [shadow.cljs.launcher.deps] + :main shadow.cljs.launcher.deps}}) diff --git a/src/main/shadow/cljs/launcher/deps.clj b/src/main/shadow/cljs/launcher/deps.clj new file mode 100644 index 0000000..be8a4c4 --- /dev/null +++ b/src/main/shadow/cljs/launcher/deps.clj @@ -0,0 +1,71 @@ +(ns shadow.cljs.launcher.deps + "lightweight launcher that just downloads jars and builds a classpath" + (:gen-class) + (:require + [clojure.java.io :as io] + [cemerick.pomegranate.aether :as aether])) + +(defn transfer-listener + [{:keys [type error resource] :as info}] + (let [{:keys [name repository]} resource] + (binding [*out* *err*] + (case type + :started (println "Retrieving" name "from" repository) + ;; :progressed + ;; :succeeded + :corrupted (when error (println (.getMessage error))) + nil)))) + +(defn -main [] + (try + (let [{:keys [cache-root repositories proxy local-repo dependencies mirrors version] + :or {dependencies [] + repositories {} + cache-root ".shadow-cljs"} + :as config} + (read *in*)] + + (println "shadow-cljs - updating dependencies") + + ;; FIXME: resolve conflicts? + (let [resolve-args + (-> {:coordinates + dependencies + :repositories + (merge aether/maven-central {"clojars" "https://clojars.org/repo"} repositories) + :transfer-listener + transfer-listener} + (cond-> + mirrors + (assoc :mirrors mirrors) + proxy + (assoc :proxy proxy) + local-repo + (assoc :local-repo local-repo) + )) + + deps + (apply aether/resolve-dependencies (into [] (mapcat identity) resolve-args)) + + files + (into [] (map #(.getAbsolutePath %)) (aether/dependency-files deps)) + + result + {:dependencies dependencies + :version version + :files files + :deps deps} + + classpath-file + (io/file cache-root "classpath.edn")] + + (io/make-parents classpath-file) + + (spit classpath-file (pr-str result))) + + (println "shadow-cljs - dependencies updated")) + + (catch Exception e + (println "shadow-cljs - dependency update failed -" (.getMessage e)) + (System/exit 1) + ))) \ No newline at end of file