 (defn prep-builds [builds]
   (-> builds
       map-to-vec-builds
-      (->> (mapv #(dissoc % :warning-handlers)))
-      fix-builds
-      prep-builds-for-figwheel-client
-      ensure-output-dirs
-      no-seqs))
+      (->> (mapv prep-build))))
 
 (defn prep-options
   "Normalize various configuration input."

    (apply-to-key namify-module-entries :modules)
    (apply-to-key name :main)))

(defn ensure-id [opts]
  (if (nil? (:id opts))
    (assoc opts :id (name (gensym "build_needs_id_")))
    (assoc opts :id (name (:id opts)))))

(defn move-compiler-to-build-options [build]
  (if (and (not (:build-options build))
           (:compiler build))
    (-> build
      (assoc :build-options (:compiler build))
      (dissoc :compiler))
    build))

(defn fix-build [build]
  (-> build
    ensure-id
    move-compiler-to-build-options
    (update-in [:build-options] fix-build-options)))

(defn fix-builds [builds]
  (mapv fix-build builds))

(defn no-seqs [b]
  (walk/postwalk #(if (seq? %) (vec %) %) b))

(defn ensure-output-dirs [builds]
  (mapv ensure-output-dirs* builds)
  builds)

(defn figwheel-client-options [{:keys [figwheel]}]
  (if figwheel
    (if-not (map? figwheel) {} figwheel)
    {}))

(comment
  (figwheel-client-options {:figwheel {:hey 1}})

  (figwheel-client-options {:figwheel true})
  
  )

(defn fix-figwheel-symbol-keys [figwheel]
  (into {} (map (fn [[k v]] [k (if (symbol? v) (name v) v)]) figwheel)))

(defn append-build-id [figwheel build]
  (if (:id build)
    (assoc figwheel :build-id (:id build))
    figwheel))

(defn forward-devcard-option [{:keys [figwheel] :as build}]
  (if (and figwheel (:devcards figwheel))
    (assoc-in build [:build-options :devcards] true)
    build))

(defn prep-build-for-figwheel-client [{:keys [figwheel] :as build}]
  (if figwheel
    (assoc build :figwheel
           (-> (figwheel-client-options build)
             (append-build-id build)
             (fix-figwheel-symbol-keys)))
    build))

(defn prep-builds-for-figwheel-client [builds]
  (mapv (comp prep-build-for-figwheel-client forward-devcard-option) builds))

(defn figwheel-build? [build]
  (and (= (get-in build [:build-options :optimizations]) :none)
       (:figwheel build)))

(defn update-figwheel-connect-options [figwheel-server build]
  (if (figwheel-build? build)

                  module-map))
    module-map))

;; TODO this is a hack! need to check all the places that I'm checking for
;; :optimizations :none and check for nil? or :none
(defn default-optimizations-to-none [build-options]
  (if (optimizations-none? build-options)
    (assoc build-options :optimizations :none)
    build-options))

