Skip to content

Commit

Permalink
getting compile messages back
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Hauman committed Dec 15, 2014
1 parent 8312390 commit 4e5c1ed
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
* cljs.closure.api

* do I use the :root param? It shouldn't be needed
* :unique-id param
* handle notify command stuff
* make sure plugin tests pass

* add assert?
* resource paths? better way to handle it eh?
* start compile message

* look at cljs.test plugin for client
Expand Down
2 changes: 1 addition & 1 deletion example/src/example/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
})

(m/log (+ 1 2 2 3 ))
(m/log (+ 1 2 2 3))

;; When you are writing reloadable code you have to protect things
;; that you don't want defined over and over.
Expand Down
24 changes: 11 additions & 13 deletions plugin/src/leiningen/figwheel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,17 @@
(update-in [:dependencies] conj ['figwheel-sidecar figwheel-sidecar-version])
(subproject/make-subproject crossover-path builds)
#_(update-in [:dependencies] #(filter (fn [[n _]] (not= n 'cljsbuild)) %)))]
(print (prn-str (:dependencies project')))
(leval/eval-in-project project'
;; can remove cljsbuild dep here

; Without an explicit exit, the in-project subprocess seems to just hang for
; around 30 seconds before exiting. I don't fully understand why...
`(try
(do
~form
(System/exit 0))
(catch cljsbuild.test.TestsFailedException e#
(catch cljsbuild.test.TestsFailedException e#
; Do not print stack trace on test failure
(System/exit 1))
(catch Exception e#
(do
(.printStackTrace e#)
(System/exit 1))
(catch Exception e#
(do
(.printStackTrace e#)
(System/exit 1))))
requires)))

Expand Down Expand Up @@ -190,10 +185,13 @@ See https://github.com/emezeske/lein-cljsbuild/blob/master/doc/CROSSOVERS.md for
figwheel-options (prep-options
(merge
{ :output-dir (-> current-build :compiler :output-dir )
:output-to (-> current-build :compiler :output-to ) }
:output-to (-> current-build :compiler :output-to ) }
(:figwheel project)
(select-keys project [:root :resource-paths])))]
(let [errors (check-for-valid-options (:cljsbuild project) figwheel-options)]
;; we can get the resource paths from the project
(select-keys project [:resource-paths])))]
(let [errors (check-for-valid-options
(:cljsbuild project)
figwheel-options)]
(println (str "Figwheel: focusing on build-id " "'" (:id current-build) "'"))
(if (empty? errors)
(run-compiler project
Expand Down
27 changes: 25 additions & 2 deletions sidecar/src/figwheel_sidecar/auto_builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@
[clj-stacktrace.repl]
[clojurescript-build.core :as cbuild]))

;; from cljsbuild
(def reset-color "\u001b[0m")
(def foreground-red "\u001b[31m")
(def foreground-green "\u001b[32m")

(defn- colorizer [c]
(fn [& args]
(str c (apply str args) reset-color)))

(def red (colorizer foreground-red))
(def green (colorizer foreground-green))

(defn- elapsed [started-at]
(let [elapsed-us (- (System/currentTimeMillis) started-at)]
(with-precision 2
(str (/ (double elapsed-us) 1000) " seconds"))))

;; should for optimizations none here?

(defn get-dependency-mtimes [src-dirs build-options]
Expand Down Expand Up @@ -37,11 +54,17 @@
(let [new-mtimes (get-dependency-mtimes src-dirs build-options)]
(when (not= dependency-mtimes new-mtimes)
(try
;; this is a good place to have a compile-started callback
;; this is a good place to have a compile-started callback
;; can add *assert* binding here
(binding [cljs.analyzer/*cljs-warning-handlers* warning-handlers]
(let [additional-changed-ns (cbuild/build-source-paths src-dirs build-options compiler-env)]
(println (str "Compiling \"" (:output-to build-options) "\" from " (pr-str src-dirs) "..."))
(flush)
(let [started-at (System/currentTimeMillis)
additional-changed-ns (cbuild/build-source-paths src-dirs build-options compiler-env)]
(println (green (str "Successfully compiled \"" (:output-to build-options) "\" in " (elapsed started-at) ".")))
(fig/check-for-changes figwheel-state' dependency-mtimes new-mtimes additional-changed-ns)))
(catch Throwable e
(println (red (str "Compiling \"" (:output-to build-options) "\" failed.")))
(clj-stacktrace.repl/pst+ e) ;; not sure if this is needed
(fig/compile-error-occured figwheel-state' e))))
(fig/check-for-css-changes figwheel-state')
Expand Down
9 changes: 4 additions & 5 deletions sidecar/src/figwheel_sidecar/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@
(keys new-mtimes))
(:cljs changed-source-file-paths))))))

(defn resource-paths [{:keys [root resource-paths]}]
(defn resource-paths [{:keys [resource-paths]}]
(mapv #(string/replace-first (norm-path %)
(str (norm-path root) "/") "") resource-paths))
(str (norm-path (.getCanonicalPath (io/file ".")))
"/") "") resource-paths))

(defn resource-paths-pattern-str [state]
(str "(" (string/join "|" (resource-paths state)) ")/"
Expand Down Expand Up @@ -332,9 +333,7 @@
unique-id
open-file-command] :as opts}]
;; I'm spelling this all out as a reference
{ :root (or root (.getCanonicalPath (io/file ".")))

:unique-id (or unique-id (project-unique-id))
{ :unique-id (or unique-id (project-unique-id))

:resource-paths (or resource-paths ["resources"])
:css-dirs css-dirs
Expand Down

0 comments on commit 4e5c1ed

Please sign in to comment.