Skip to content

Commit

Permalink
Add support for lein checkouts
Browse files Browse the repository at this point in the history
- Add checkouts source directories to the classpath
- Add checkouts source directories to :source-paths

This follows roughly the same pattern as cljsbuild in
emezeske/lein-cljsbuild#374

Fixes #9
  • Loading branch information
danielcompton committed Dec 17, 2017
1 parent 8f936b6 commit c75836f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
53 changes: 40 additions & 13 deletions plugin/src/leiningen/figwheel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
(:require
#_[clojure.pprint :as pp]
[leiningen.core.eval :as leval]
[leiningen.core.project :as lproject]
[leiningen.clean :as clean]
[leiningen.core.main :as main]
[clojure.java.io :as io]
[clojure.set :refer [intersection]]
[leiningen.figwheel.fuzzy :as fuz]
[simple-lein-profile-merge.core :as lm]))
[simple-lein-profile-merge.core :as lm])
(:import (java.io File)
(java.nio.file Path)))

(def _figwheel-version_ "0.5.15-SNAPSHOT")

Expand Down Expand Up @@ -284,6 +287,17 @@
(when (every? not-empty args)
(not-empty (apply intersection (map set args)))))

(defn checkout-source-paths
"Get source paths for all of the lein projects that are in the checkouts directory."
[project]
(let [checkout-projects (lproject/read-checkouts project)
checkout-sources (for [co-project checkout-projects
build (conj (get-in co-project [:cljsbuild :builds]) co-project) ;; Use the :source-paths of the project too.
source-path (:source-paths build)]
(str (.relativize (.toPath (io/file (:root project)))
(.toPath (io/file source-path)))))]
(distinct checkout-sources)))

(defn source-paths-for-classpath [{:keys [figwheel-options all-builds build-ids] :as data}]
(if-not (and all-builds (not-empty all-builds))
[]
Expand Down Expand Up @@ -396,23 +410,36 @@
(fuzzy-config-from-project project)
{:no-start-option true}))

(defn add-checkouts [project]
(let [checkout-paths (checkout-source-paths project)]
(update-in
project
[:cljsbuild :builds]
(fn [builds]
(into {}
(map (fn [[k build]]
[k (update build :source-paths concat checkout-paths)])
builds))))))

(defn build-once [project build-ids]
(when-not (report-if-bad-build-ids project build-ids)
(run-build-once
project
(fuzzy-config-from-project project)
(source-paths-for-classpath
(normalize-data project build-ids))
(vec build-ids))))
(let [project (add-checkouts project)]
(run-build-once
project
(fuzzy-config-from-project project)
(source-paths-for-classpath
(normalize-data project build-ids))
(vec build-ids)))))

(defn figwheel-main [project build-ids]
(when-not (report-if-bad-build-ids project build-ids)
(run-figwheel
project
(fuzzy-config-from-project project)
(source-paths-for-classpath
(normalize-data project build-ids))
(vec build-ids))))
(let [project (add-checkouts project)]
(run-figwheel
project
(-> project fuzzy-config-from-project)
(source-paths-for-classpath
(normalize-data project build-ids))
(vec build-ids)))))

(defmulti fig-dispatch (fn [command _ _] command))

Expand Down
10 changes: 10 additions & 0 deletions plugin/test/leiningen/figwheel_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@




(deftest add-checkouts-test
(is (= ["src" "../../src" "checkouts/abc/src"]
(get-in
(f/add-checkouts
{:client {:source-paths ["src" "../../src"], :compiler {:output-dir "resources/public/js", :output-to "resources/public/js/client.js", :asset-path "js", :optimizations :none, :source-map true, :source-map-timestamp true, :main "todomvc.core", :closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}, :preloads ['day8.re-frame.trace.preload]}, :figwheel {:on-jsload "todomvc.core/main"}}
:dev {:source-paths ["src" "../../src"], :compiler {:output-dir "resources/public/js1", :output-to "resources/public/js1/client.js"}}}
["checkouts/abc/src"])
[:client :source-paths])
)))

0 comments on commit c75836f

Please sign in to comment.