Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns build
(:require [ :as b]
[shadow.cljs.devtools.api :as shadow.api]
[shadow.cljs.devtools.server :as shadow.server]
[cheshire.core :as json]
[ :as io]
[clojure.string :as string])
(:import (org.apache.commons.compress.archivers ArchiveStreamFactory)
( GZIPInputStream CheckedInputStream Adler32)
( MessageDigest DigestInputStream)
(java.util Formatter)))
(defn ^MessageDigest message-digest-instance
(MessageDigest/getInstance (first (string/split integrity #"-" 2))))
(defn md-integrity
[^MessageDigest md]
(let [formatter (Formatter.)
hash (.digest md)]
(doseq [i hash]
(.format formatter "%02x" (into-array [i])))
(str formatter)))
(set! *warn-on-reflection* true)
(defn x []
(let [{:strs [packages]} (json/parse-stream (io/reader "package-lock.json"))
packages (remove #(get % "dev")
(dissoc packages ""))]
(doseq [[target {:strs [resolved integrity]}] packages
:let [targetf (io/file target)
md (message-digest-instance integrity)
in (DigestInputStream. (io/input-stream resolved) md)
tar (.createArchiveInputStream (ArchiveStreamFactory.) "tar"
(GZIPInputStream. in))]]
(loop []
(when-let [tar-entry (some-> tar .getNextEntry)]
(let [entry-target (io/file targetf (string/replace (.getName tar-entry)
(io/make-parents entry-target)
(io/copy tar entry-target)
(prn [integrity (md-integrity md)]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment