Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a date formatting option to cljsbuild output #419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions plugin/src/leiningen/cljsbuild.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[leiningen.trampoline :as ltrampoline]
[robert.hooke :as hooke]
[clojure.java.io :as io]
[clojure.string :as string]))
[clojure.string :as string]
[cljsbuild.util :as util]))

(def ^:private repl-output-path "repl")

Expand Down Expand Up @@ -83,11 +84,11 @@
(doseq [build-id build-ids]
(if (empty? (filter #(= (:id %) build-id) builds))
(throw (Exception. (str "Unknown build identifier: " build-id)))))
(println (if watch? "Watching for changes before compiling ClojureScript..." "Compiling ClojureScript..."))
(util/log (if watch? "Watching for changes before compiling ClojureScript..." "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.
(when (not-empty crossovers)
(println "\033[31mWARNING: lein-cljsbuild crossovers are deprecated, and will be removed in future versions. See https://github.com/emezeske/lein-cljsbuild/blob/master/doc/CROSSOVERS.md for details.\033[0m")
(util/log (util/red "WARNING: lein-cljsbuild crossovers are deprecated, and will be removed in future versions. See https://github.com/emezeske/lein-cljsbuild/blob/master/doc/CROSSOVERS.md for details."))
(fs/mkdirs crossover-path))
(let [filtered-builds (if (empty? build-ids)
builds
Expand Down
4 changes: 3 additions & 1 deletion plugin/src/leiningen/cljsbuild/subproject.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[leiningen.core.main :as lmain]
[cljsbuild.compat :as cljs-compat]
[clojure.java.io :refer (resource)]
[clojure.string :as string]))
[clojure.string :as string]
[cljsbuild.util :as util]))

(def cljsbuild-version
(let [[_ coords version]
Expand Down Expand Up @@ -72,6 +73,7 @@
; we could emit a warning here indicating that we couldn't verify the cljsbuild/CLJS
; version pairing, but that would likely just confuse people
(when-not (cljs-compat/version-in-range? (first desired-cljs-version) acceptable-cljs-range)
(util/log (util/yellow ))
(print "\033[31m")
(apply println (concat cljs-version-message
["You are attempting to use ClojureScript"
Expand Down
25 changes: 7 additions & 18 deletions support/src/cljsbuild/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
[clojure.java.io :as io]
[fs.core :as fs]))

(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
Expand All @@ -32,9 +21,9 @@
(try
(util/sh (update-in command [:shell] (fn [old] (concat old [message]))))
(catch Throwable e
(println (red "Error running :notify-command:"))
(util/log (util/red "Error running :notify-command:"))
(pst+ e))))
(println (colorizer message)))
(util/log (colorizer message)))

(defn ns-from-file [f]
(try
Expand All @@ -56,7 +45,7 @@
parents (butlast relative-path)
path (apply str (interpose java.io.File/separator
(cons target-dir parents)))]
(io/file (io/file path)
(io/file (io/file path)
(str (last relative-path) ".js"))))

;; Cannnot call build with ["src/cljs" "src/cljs-more"] cause build thinks a vector
Expand All @@ -69,7 +58,7 @@
(defn- compile-cljs [cljs-paths compiler-options notify-command incremental? assert? watching?]
(let [output-file (:output-to compiler-options)
output-file-dir (fs/parent output-file)]
(println (str "Compiling \"" output-file "\" from " (pr-str cljs-paths) "..."))
(util/log (str "Compiling \"" output-file "\" from " (pr-str cljs-paths) "..."))
(flush)
(when (not incremental?)
(fs/delete-dir (:output-dir compiler-options)))
Expand All @@ -82,11 +71,11 @@
(fs/touch output-file started-at)
(notify-cljs
notify-command
(str "Successfully compiled \"" output-file "\" in " (elapsed started-at) ".") green)
(str "Successfully compiled \"" output-file "\" in " (elapsed started-at) ".") util/green)
(catch Throwable e
(notify-cljs
notify-command
(str "Compiling \"" output-file "\" failed.") red)
(str "Compiling \"" output-file "\" failed.") util/red)
(if watching?
(pst+ e)
(throw e)))))))
Expand Down Expand Up @@ -137,7 +126,7 @@
(catch Throwable e
(notify-cljs
notify-command
(str "Reloading Clojure file \"" path "\" failed.") red)
(str "Reloading Clojure file \"" path "\" failed.") util/red)
(pst+ e)))))

(defn run-compiler [cljs-paths checkout-paths crossover-path crossover-macro-paths
Expand Down
2 changes: 1 addition & 1 deletion support/src/cljsbuild/crossover.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
(comp is-macro-file? second)
all-resources)]
(when (empty? all-resources)
(println "WARNING: Unable to find crossover: " crossover))
(util/log "WARNING: Unable to find crossover: " crossover))
resources))

(defn find-crossovers [crossovers macros?]
Expand Down
2 changes: 1 addition & 1 deletion support/src/cljsbuild/repl/listen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(util/sleep 5000)
(util/process-start command)
(catch Exception e
(println "Error in background process: " e)
(util/log (str "Error in background process: " e))
(throw e)))))

(defn delayed-process-wait [process]
Expand Down
2 changes: 1 addition & 1 deletion support/src/cljsbuild/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(let [success (every? #(= % 0)
(dofor [[test-name test-command] test-commands]
(do
(println "Running ClojureScript test:" test-name)
(util/log (str "Running ClojureScript test:" test-name))
(util/sh test-command))))]
(when (not success)
(throw (cljsbuild.test.TestsFailedException. "Test failed.")))))
21 changes: 20 additions & 1 deletion support/src/cljsbuild/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[clojure.string :as string]
[fs.core :as fs])
(:import
(java.io File OutputStreamWriter)))
(java.io File OutputStreamWriter)
(java.util Date)))

(defn join-paths [& paths]
(apply str (interpose "/" paths)))
Expand Down Expand Up @@ -85,3 +86,21 @@
(defn sh [command]
(let [process (process-start command)]
((:wait process))))

(def reset-color "\u001b[0m")
(def foreground-red "\u001b[31m")
(def foreground-green "\u001b[32m")
(def foreground-yellow "\u001b[33m")

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

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

(def log-format "%tr")

(defn log [& args]
(apply println (format log-format (Date.)) "-" args))