Permalink
Browse files

Make it possible to invoke specific build configurations

  • Loading branch information...
1 parent 2745a0c commit 6eb029504c41f9df13a19ec4995449cc1f25790c @fhd fhd committed Mar 29, 2012
Showing with 38 additions and 11 deletions.
  1. +18 −0 README.md
  2. +6 −3 example-projects/advanced/project.clj
  3. +14 −8 plugin/src/leiningen/cljsbuild.clj
View
18 README.md
@@ -160,6 +160,24 @@ This is extremely convenient for doing library development in ClojureScript.
This allows cljsbuild to compile in all four optimization levels at once, for
easier testing, or to compile a test suite alongside the library code.
+You can optionally assign an id to a build configuration and then
+build only that one:
+
+```clj
+(defproject lein-cljsbuild-example "1.2.3"
+ :plugins [[lein-cljsbuild "0.1.3"]]
+ :cljsbuild {
+ :builds [
+ {:id "main"
+ :source-path "src-cljs-main"
+ :compiler {:output-to "main.js"}}
+ {:id "other"
+ :source-path "src-cljs-other"
+ :compiler {:output-to "other.js"}}}])
+```
+
+ $ lein cljsbuild auto main
+
See the
[example-projects/advanced] (https://github.com/emezeske/lein-cljsbuild/blob/0.1.3/example-projects/advanced)
directory for a working example of a project that uses this feature.
View
9 example-projects/advanced/project.clj
@@ -57,21 +57,24 @@
:builds [
; This build has the lowest level of optimizations, so it is
; useful when debugging the app.
- {:source-path "src-cljs"
+ {:id "dev"
+ :source-path "src-cljs"
:jar true
:compiler {:output-to "resources/public/js/main-debug.js"
:optimizations :whitespace
:pretty-print true}}
; This build has the highest level of optimizations, so it is
; efficient when running the app in production.
- {:source-path "src-cljs"
+ {:id "prod"
+ :source-path "src-cljs"
:compiler {:output-to "resources/public/js/main.js"
:optimizations :advanced
:pretty-print false}}
; This build is for the ClojureScript unit tests that will
; be run via PhantomJS. See the phantom/unit-test.js file
; for details on how it's run.
- {:source-path "test-cljs"
+ {:id "test"
+ :source-path "test-cljs"
:compiler {:output-to "resources/private/js/unit-test.js"
:optimizations :whitespace
:pretty-print true}}]}
View
22 plugin/src/leiningen/cljsbuild.clj
@@ -34,13 +34,19 @@
(assoc build :parsed-notify-command
(config/parse-shell-command (:notify-command build))))
-(defn- run-compiler [project {:keys [crossover-path crossovers builds]} watch?]
+(defn- run-compiler [project {:keys [crossover-path crossovers builds]} build-ids watch?]
+ (doseq [build-id build-ids]
+ (if (empty? (filter #(= (:id %) build-id) builds))
+ (throw (Exception. (str "Unknown build identifier: " build-id)))))
(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.
(when (not-empty crossovers)
(fs/mkdirs crossover-path))
- (let [parsed-builds (map parse-notify-command builds)]
+ (let [filtered-builds (if (empty? build-ids)
+ builds
+ (filter #(some #{(:id %)} build-ids) builds))
+ parsed-builds (map parse-notify-command filtered-builds)]
(run-local-project project crossover-path parsed-builds
'(require 'cljsbuild.compiler 'cljsbuild.crossover 'cljsbuild.util)
`(do
@@ -85,13 +91,13 @@
(defn- once
"Compile the ClojureScript project once."
- [project options]
- (run-compiler project options false))
+ [project options build-ids]
+ (run-compiler project options build-ids false))
(defn- auto
"Automatically recompile when files are modified."
- [project options]
- (run-compiler project options true))
+ [project options build-ids]
+ (run-compiler project options build-ids true))
(defn- clean
"Remove automatically generated files."
@@ -168,8 +174,8 @@
([project subtask & args]
(let [options (config/extract-options project)]
(case subtask
- "once" (once project options)
- "auto" (auto project options)
+ "once" (once project options args)
+ "auto" (auto project options args)
"clean" (clean project options)
"test" (test project options args)
"repl-listen" (repl-listen project options)

0 comments on commit 6eb0295

Please sign in to comment.