aboutsummaryrefslogtreecommitdiff
path: root/lux-lein
diff options
context:
space:
mode:
authorEduardo Julian2017-03-21 23:22:21 -0400
committerEduardo Julian2017-03-21 23:22:21 -0400
commit749608e2f4f9804f33812b194297201851343947 (patch)
tree716888beb9aa95bf869445503b15a72325349288 /lux-lein
parentad2f9e165d2bdce646507f1aadd133b8f67ae75f (diff)
- Now packaging the complete JS code.
Diffstat (limited to 'lux-lein')
-rw-r--r--lux-lein/src/leiningen/lux/builder.clj19
-rw-r--r--lux-lein/src/leiningen/lux/packager.clj18
-rw-r--r--lux-lein/src/leiningen/lux/test.clj41
-rw-r--r--lux-lein/src/leiningen/lux/utils.clj16
4 files changed, 64 insertions, 30 deletions
diff --git a/lux-lein/src/leiningen/lux/builder.clj b/lux-lein/src/leiningen/lux/builder.clj
index ca9088d4c..65f45b90c 100644
--- a/lux-lein/src/leiningen/lux/builder.clj
+++ b/lux-lein/src/leiningen/lux/builder.clj
@@ -4,10 +4,17 @@
[packager :as &packager])))
(defn build [project]
- (if-let [program-module (get-in project [:lux :program])]
- (when (&utils/run-process (&utils/compile-path project program-module (get project :source-paths (list)))
- nil
- "[BUILD BEGIN]"
- "[BUILD END]")
- (&packager/package project program-module (get project :resource-paths (list))))
+ (if-let [program-modules (get-in project [:lux :program])]
+ (do (when-let [jvm-module (get-in program-modules [:jvm])]
+ (when (&utils/run-process (&utils/compile-path project "jvm" jvm-module (get project :source-paths (list)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (&packager/package project "jvm" jvm-module (get project :resource-paths (list)))))
+ (when-let [js-module (get-in program-modules [:js])]
+ (when (&utils/run-process (&utils/compile-path project "js" js-module (get project :source-paths (list)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (&packager/package project "js" js-module (get project :resource-paths (list))))))
(println "Please provide a program main module in [:lux :program]")))
diff --git a/lux-lein/src/leiningen/lux/packager.clj b/lux-lein/src/leiningen/lux/packager.clj
index 3ac117d15..afb4a82db 100644
--- a/lux-lein/src/leiningen/lux/packager.clj
+++ b/lux-lein/src/leiningen/lux/packager.clj
@@ -123,11 +123,11 @@
(def default-manifest-file (str "." java.io.File/separator "AndroidManifest.xml"))
;; [Resources]
-(defn package
+(defn ^:private package-jvm
"(-> Text (List Text) Null)"
[project module resources-dirs]
(let [output-package-name (get project :jar-name &utils/output-package)
- output-dir (&utils/prepare-path (get-in project [:lux :target] &utils/default-output-dir))
+ output-dir (&utils/prepare-path (get-in project [:lux :target] &utils/default-jvm-output-dir))
output-package (str output-dir java.io.File/separator output-package-name)
!all-jar-files (atom {})
includes-android? (boolean (some #(-> % first (= 'com.google.android/android))
@@ -161,7 +161,7 @@
(.closeEntry)))
nil))
(when (get-in project [:lux :android])
- (let [output-dir-context (new File (get-in project [:lux :target] &utils/default-output-dir))
+ (let [output-dir-context (new File (get-in project [:lux :target] &utils/default-jvm-output-dir))
output-dex "classes.dex"
_ (do (.delete (new File output-dex))
(&utils/run-process (str "dx --dex --output=" output-dex " " output-package-name)
@@ -206,7 +206,13 @@
(&utils/run-process (str "zipalign 4 " output-apk-unaligned-path " " output-apk-path)
nil
"[ZIPALIGN BEGIN]"
- "[ZIPALIGN END]"))
- )
- ]
+ "[ZIPALIGN END]")))]
nil)))))
+
+(defn package
+ "(-> Text Text (List Text) Null)"
+ [project platform module resources-dirs]
+ (case platform
+ "jvm" (package-jvm project module resources-dirs)
+ "js" nil)
+ )
diff --git a/lux-lein/src/leiningen/lux/test.clj b/lux-lein/src/leiningen/lux/test.clj
index 77dc342e7..d3755c1b6 100644
--- a/lux-lein/src/leiningen/lux/test.clj
+++ b/lux-lein/src/leiningen/lux/test.clj
@@ -5,18 +5,31 @@
[packager :as &packager])))
(defn test [project]
- (if-let [tests-module (get-in project [:lux :tests])]
- (when (&utils/run-process (&utils/compile-path project tests-module (concat (:test-paths project) (:source-paths project)))
- nil
- "[BUILD BEGIN]"
- "[BUILD END]")
- (let [java-cmd (get project :java-cmd "java")
- jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))
- output-package (str (get-in project [:lux :target] &utils/default-output-dir) "/"
- (get project :jar-name &utils/output-package))]
- (do (&packager/package project tests-module (get project :resource-paths (list)))
- (&utils/run-process (str java-cmd " " jvm-opts " -jar " output-package)
- nil
- "[TEST BEGIN]"
- "[TEST END]"))))
+ (if-let [tests-modules (get-in project [:lux :tests])]
+ (do (when-let [jvm-module (get-in tests-modules [:jvm])]
+ (when (&utils/run-process (&utils/compile-path project "jvm" jvm-module (concat (:test-paths project) (:source-paths project)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (let [java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))
+ output-package (str (get-in project [:lux :target] &utils/default-jvm-output-dir) "/"
+ (get project :jar-name &utils/output-package))]
+ (do (&packager/package project "jvm" jvm-module (get project :resource-paths (list)))
+ (&utils/run-process (str java-cmd " " jvm-opts " -jar " output-package)
+ nil
+ "[TEST BEGIN]"
+ "[TEST END]")))))
+ (when-let [js-module (get-in tests-modules [:js])]
+ (when (&utils/run-process (&utils/compile-path project "js" js-module (concat (:test-paths project) (:source-paths project)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (let [output-package (str (get-in project [:lux :target] &utils/default-js-output-dir) "/"
+ "program.js")]
+ (do (&packager/package project "js" js-module (get project :resource-paths (list)))
+ (&utils/run-process (str "node " output-package)
+ nil
+ "[TEST BEGIN]"
+ "[TEST END]"))))))
(println "Please provide a test module in [:lux :tests]")))
diff --git a/lux-lein/src/leiningen/lux/utils.clj b/lux-lein/src/leiningen/lux/utils.clj
index a786a4d6d..ae39c37b3 100644
--- a/lux-lein/src/leiningen/lux/utils.clj
+++ b/lux-lein/src/leiningen/lux/utils.clj
@@ -5,7 +5,8 @@
InputStreamReader
BufferedReader)))
-(def ^:const ^String default-output-dir (str "target" java.io.File/separator "jvm"))
+(def ^:const ^String default-jvm-output-dir (str "target" java.io.File/separator "jvm"))
+(def ^:const ^String default-js-output-dir (str "target" java.io.File/separator "js"))
(def ^:const ^String output-package "program.jar")
(def ^:private unit-separator (str (char 31)))
@@ -61,10 +62,17 @@
(str "lux " mode
" " (->> (get project :resource-paths (list)) (interpose unit-separator) (apply str))
" " (->> source-paths (interpose unit-separator) (apply str))
- " " (get-in project [:lux :target] default-output-dir)))
+ " " (get-in project [:lux :target] (cond (.contains mode "jvm")
+ default-jvm-output-dir
+
+ (.contains mode "js")
+ default-js-output-dir
+
+ :else
+ (assert false)))))
(do-template [<name> <mode>]
- (defn <name> [project module source-paths]
+ (defn <name> [project platform module source-paths]
(let [is-stdlib? (= stdlib-id [(get project :group) (get project :name)])
jar-paths (all-jars-in-classloader)
compiler-path (prepare-path (find-compiler-path jar-paths))
@@ -90,7 +98,7 @@
(str (java-command project) " -cp " class-path
" " (lux-command project <mode> source-paths))))
- compile-path (str "release jvm " module)
+ compile-path (str "release " platform " " module)
repl-path "repl"
)