(defn emit-source-map [src dest sm-data opts]
(let [sm-file (io/file (str (.getPath ^File dest) ".map"))]
(if-let [smap (:source-map-asset-path opts)]
(emitln "\n//# sourceMappingURL=" smap
(string/replace (util/path sm-file)
(str (util/path (io/file (:output-dir opts))))
"")
(if (true? (:source-map-timestamp opts))
(str
(if-not (string/index-of smap "?") "?" "&")
"rel=" (System/currentTimeMillis))
""))
(emitln "\n//# sourceMappingURL="
(or (:source-map-url opts) (.getName sm-file))
(if (true? (:source-map-timestamp opts))
(str "?rel=" (System/currentTimeMillis))
"")))
(spit sm-file
(sm/encode {(url-path src) (:source-map sm-data)}
{:lines (+ (:gen-line sm-data) 2)
:file (url-path dest)
:source-map-path (:source-map-path opts)
:source-map-timestamp (:source-map-timestamp opts)
:source-map-pretty-print (:source-map-pretty-print opts)
:relpaths {(util/path src)
(util/ns->relpath (first (:provides opts)) (:ext opts))}}))))