Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active August 29, 2015 14:12
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 Deraen/ea38f5ccfed31d34971f to your computer and use it in GitHub Desktop.
Save Deraen/ea38f5ccfed31d34971f to your computer and use it in GitHub Desktop.
Cljsjs
(set-env!
:resource-paths #{"resources"}
:dependencies '[[adzerk/bootlaces "0.1.8" :scope "test"]])
(require '[adzerk.bootlaces :refer :all])
(def +version+ "2.6.0-0")
(bootlaces! +version+)
(task-options!
pom {:project 'cljsjs/moment
:version +version+
:description "A javascript date library for parsing, validating, manipulating, and formatting dates."
:url "http://momentjs.com/"
:license {:name "MIT" :url "http://opensource.org/licenses/MIT"}
:scm {:url "https://github.com/cljsjs/packages"}})
(require '[boot.core :refer :all]
'[boot.util :as util]
'[clojure.java.io :as io]
'[clojure.string :as string])
(import '[java.security DigestInputStream MessageDigest]
'[javax.xml.bind DatatypeConverter]
'[java.util.zip ZipFile])
(deftask check-checksum
[s sum FILENAME=CHECKSUM {str str} "Check the md5 checksum of given file against given md5"]
(with-pre-wrap fileset
(doseq [f (ls fileset)
:let [path (tmppath f)]]
(when-let [checksum (some-> (get sum path) string/upper-case)]
(with-open [is (io/input-stream (tmpfile f))]
(let [md (MessageDigest/getInstance "MD5")
dis (DigestInputStream. is md)
; Read the whole file, we don't need output but to realize the digest
_ (slurp dis)
dig (.digest (.getMessageDigest dis))
real-checksum (DatatypeConverter/printHexBinary dig)]
(if (not= checksum real-checksum)
(throw (IllegalStateException. (format "Checksum of file %s in not %s but %s" path checksum real-checksum))))))))
fileset))
(deftask download
[u url URL str "The url to download"
n name NAME str "Optional name for target file"
c checksum CHECKSUM str "Md5 checksum for dowloaded file"]
(let [tmp (temp-dir!)
fname (or name (last (string/split url #"/")))]
(cond->
(with-pre-wrap fileset
(let [target (io/file tmp fname)]
(util/info "Downloading %s\n" fname)
(io/copy (io/input-stream url) target))
(-> fileset (add-resource tmp) commit!))
checksum (comp (check-checksum :sum {fname checksum})))))
(deftask unzip
[p paths PATH #{str} "Path in fileset to unzip"]
(let [tmp (temp-dir!)]
(with-pre-wrap fileset
(let [archives (filter (comp paths tmppath) (ls fileset))]
(doseq [archive archives
:let [zipfile (ZipFile. (tmpfile archive))
entries (enumeration-seq (.entries zipfile))]]
(util/info "Extracting %d entries\n" (count entries))
(doseq [entry entries
:when (not (.isDirectory entry))
:let [target (io/file tmp (.getName entry))]]
(io/make-parents target)
(io/copy (.getInputStream zipfile entry) target)))
(-> fileset (rm archives) (add-resource tmp) commit!)))))
(deftask package []
(comp
(download :url "https://github.com/moment/moment/archive/2.6.0.zip"
:checksum "0f9b226ff824066a2040056a4abfa0f6")
; (check-checksum :sum {"2.6.0.zip" "0f9b226ff824066a2040056a4abfa0f6"})
(unzip :paths #{"2.6.0.zip"})
(sift :move {#".*/moment.js" "cljsjs/development/moment.inc.js"
#".*/min/moment.min.js" "cljsjs/production/moment.min.inc.js"})
(sift :include #{#"^cljsjs"})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment