            (System/exit 1))))
      requires)))
 
-;; All I can say is I'm sorry about this but, it seems to be the best
-;; way for me to reuse cljsbuild.
-
 ;; this is really deviating from cljsbuild at this point.
 ;; need to dig in and probably rewrite this
 
 ;; need to get rid of crossovers soon
 
-(defn run-compiler [project {:keys [crossover-path crossovers builds]} live-reload-options]
+(defn run-compiler [project {:keys [crossover-path crossovers builds]} figwheel-options]
   (println "Compiling ClojureScript.")
   ; If crossover-path does not exist before eval-in-project is called,
   ; the files it contains won't be classloadable, for some reason.


(defn output-dir-in-resources-root?
  "Check if the build output directory is in or below any of the configured resources directories."
  [{:keys [output-dir resource-paths http-server-root] :as opts}]
  (and output-dir
       (first (filter (fn [x] (.startsWith output-dir (str x "/" http-server-root)))
                      (relativize-resource-paths resource-paths)))))

    (vec (map (fn [[k v]] (assoc v :id (name k))) builds))
    builds))

(defn narrow-builds* 
  "Filters builds to the chosen build-ids or if no build-ids specified returns the first
   build with optimizations set to none."
  [builds build-ids]
  (let [builds (map-to-vec-builds builds)
        ;; ensure string ids
        builds (map #(update-in % [:id] name) builds)
        build-ids (set build-ids)]
    (vec
     (keep identity
           (if-not (empty? build-ids)
             (filter #(get build-ids (:id %)) builds)
             [(first (filter optimizations-none? builds))])))))

;; we are only going to work on one build
;; still need to narrow this to optimizations none
(defn narrow-builds
  "Filters builds to the chosen build-id or if no build id specified returns the first
   build with optimizations set to none."
  [project build-ids]
  (update-in project [:cljsbuild :builds] narrow-builds* build-ids))

(defn check-for-valid-options
  "Check for various configuration anomalies."
  [{:keys [http-server-root] :as opts} build']
  (let [build-options (:compiler build')
        opts? (and (not (nil? build-options)) (optimizations-none? build'))
        out-dir? (output-dir-in-resources-root? build-options opts)]
    (map
     #(str "Figwheel Config Error (in project.clj) - " %)
     (filter identity
             (list
              (when-not opts?
                "you have build :optimizations set to something other than :none")
              (when-not out-dir?
                (str
                 (if (:output-dir build-options)
                   "your build :output-dir is not in a resources directory."
                   "you have not configured an :output-dir in your build")
                 (str "\nIt should match this pattern: " (make-serve-from-display opts)))))))))

(defn check-config [figwheel-options builds]
  (if (empty? builds)
    (list
     (str "Figwheel: "
          "No cljsbuild specified. You may have mistyped the build "
          "id on the command line or failed to specify a build in "
          "the :cljsbuild section of your project.clj. You need to have "
          "at least one build with :optimizations set to :none."))
    (mapcat (partial check-for-valid-options figwheel-options) builds)))

(defn normalize-dir
  "If directory ends with '/' then truncate the trailing forward slash."
