Skip to content

Instantly share code, notes, and snippets.

@Izzimach
Created November 8, 2016 21:52
Show Gist options
  • Save Izzimach/555c80143fef3588500bf78c0e3ed3ae to your computer and use it in GitHub Desktop.
Save Izzimach/555c80143fef3588500bf78c0e3ed3ae to your computer and use it in GitHub Desktop.
cljsjs boot task with multiple providers
(boot/deftask deps-cljs-multi-provides
"Creates a deps.cljs file based on information in the fileset and
what's passed as options.
The first .inc.js file is passed as :file, similarily .min.inc.js
is passed as :file-min. Files ending in .ext.js are passed as :externs.
:requires can be specified through the :requires option.
:provides is determined by what's passed to :names"
[n names NAME [str] "Names for provided foreign lib"
R requires REQ [str] "Modules required by this lib"
E no-externs bool "No externs are provided"]
(let [tmp (boot/tmp-dir!)
deps-file (io/file tmp "deps.cljs")
write-deps-cljs! #(spit deps-file (pr-str %))]
(boot/with-pre-wrap fileset
(let [in-files (boot/input-files fileset)
regular (first (boot/by-ext [".inc.js"] (boot/not-by-ext [".min.inc.js"] in-files)))
minified (first (boot/by-ext [".min.inc.js"] in-files))
externs (boot/by-ext [".ext.js"] in-files)]
(assert regular "No .inc.js file found!")
(if-not no-externs
(assert (first externs) "No .ext.js file(s) found!"))
(util/info "Writing deps.cljs\n")
(let [base-lib {:file (boot/tmp-path regular)
:provides names}
lib (cond-> base-lib
requires (merge base-lib {:requires requires})
minified (merge base-lib {:file-min (boot/tmp-path minified)}))]
(write-deps-cljs! (merge {:foreign-libs [lib]}
(if-not (empty? externs) {:externs (mapv boot/tmp-path externs)})))
(-> fileset
(boot/add-resource tmp)
boot/commit!))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment