Skip to content

Instantly share code, notes, and snippets.

@micha
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save micha/11e0232fbaa12566770c to your computer and use it in GitHub Desktop.

Select an option

Save micha/11e0232fbaa12566770c to your computer and use it in GitHub Desktop.
(ns boot-cljsjs
(:require
[clojure.java.io :as io]
[boot.core :as core]
[boot.util :as util]
[boot.task.built-in :as task]))
(defn path-seq
[path]
(->> path
io/file
(iterate (memfn getParentFile))
(take-while identity)
(map (memfn getName))
reverse))
(defn base-dir
[path]
(let [[base & segs] (path-seq path)]
(when (seq segs) base)))
(defn by-base-dir
[base tmpfiles]
(->> tmpfiles (filter #(= base (base-dir (core/tmppath %))))))
(defmacro with-env
[[& kvs] & body]
`(let [env# (core/get-env)]
(core/set-env! ~@kvs)
(let [result# (do ~@body)]
(apply core/set-env! (mapcat identity env#))
result#)))
(core/deftask cljsjs
[p project SYM sym "The maven group-id/artifact-id."
v version VER str "The base version string."]
(let [tmp (core/temp-dir!)
out (core/temp-dir!)]
(core/with-pre-wrap fileset
(let [tgtpath (core/get-env :target-path)
outdirs (core/output-dirs fileset)
outfiles (core/output-files fileset)
subdirs (->> fileset core/output-files
(keep (comp base-dir core/tmppath)))]
(apply core/sync! tmp outdirs)
(doseq [sub subdirs]
(let [outdir (io/file out sub)
p project
v (str version "-" sub)]
(with-env [:source-paths #{}
:resource-paths #{(.getPath (io/file tmp sub))}
:target-path (.getPath outdir)]
(core/boot (task/pom :project p :version v) (task/jar)))))
(-> fileset (core/rm outfiles) (core/add-resource out) core/commit!)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment