From 012118c265bc296e2b624fe5a5957e9f5ae56b62 Mon Sep 17 00:00:00 2001 From: Adam Frey Date: Tue, 8 Mar 2016 10:08:43 -0500 Subject: [PATCH 1/2] Accept app-dir option in bundle task Instead of hardcoding "app" --- example/build.boot | 5 ++--- src/mattsum/boot_react_native.clj | 7 ++++--- src/mattsum/impl/boot_helpers.clj | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/example/build.boot b/example/build.boot index c2eaa1f..cb63cb6 100644 --- a/example/build.boot +++ b/example/build.boot @@ -16,8 +16,7 @@ [org.clojure/clojurescript "1.7.170"] [reagent "0.5.1"] ;; [react-native-externs "0.0.1-SNAPSHOT"] - ] - ) + ]) (require '[adzerk.boot-cljs :refer [cljs]] @@ -74,5 +73,5 @@ [] (comp (cljs :ids #{"dist"}) - (rn/bundle :files {"dist.js" "main.jsbundle"}) + (rn/bundle :app-dir "app" :files {"dist.js" "main.jsbundle"}) (target :dir ["app/dist"]))) diff --git a/src/mattsum/boot_react_native.clj b/src/mattsum/boot_react_native.clj index c3c45a2..85f2c25 100644 --- a/src/mattsum/boot_react_native.clj +++ b/src/mattsum/boot_react_native.clj @@ -284,12 +284,13 @@ require('" boot-main "'); (deftask bundle "Bundle the files specified" - [f files ORIGIN:TARGET {str str} "{origin target} pair of files to bundle"] - (let [tmp (c/tmp-dir!)] + [a app-dir OUT str "The (relative) path to the React Native application" + f files ORIGIN:TARGET {str str} "{origin target} pair of files to bundle"] + (let [tmp (c/tmp-dir!)] (c/with-pre-wrap fileset (doseq [[origin target] files] (let [in (bh/file-by-path origin fileset) out (clojure.java.io/file tmp target)] (clojure.java.io/make-parents out) - (bh/bundle* in out tmp))) + (bh/bundle* app-dir in out tmp))) (-> fileset (c/add-resource tmp) c/commit!)))) diff --git a/src/mattsum/impl/boot_helpers.clj b/src/mattsum/impl/boot_helpers.clj index ce99d46..8fc487b 100644 --- a/src/mattsum/impl/boot_helpers.clj +++ b/src/mattsum/impl/boot_helpers.clj @@ -57,8 +57,7 @@ (spit out-content)) (-> fileset (c/add-resource tmp) - )))) -) + ))))) (defn append-to-file [fileset path content replacements] @@ -203,11 +202,12 @@ (defn copy-file [source-path dest-path] (clojure.java.io/copy (clojure.java.io/file source-path) (clojure.java.io/file dest-path))) -(defn bundle* [in outf outd] - (let [tempfname (str "nested/temp/" (java.util.UUID/randomUUID) ".js") - temppath (str "app/" tempfname) +(defn bundle* [app-dir in outf outd] + (let [app-dir (or app-dir "app") + tempfname (str "nested/temp/" (java.util.UUID/randomUUID) ".js") + temppath (str app-dir "/" tempfname) tempdirf (->> temppath clojure.java.io/as-file .getParentFile) - cli (-> "app/node_modules/react-native/local-cli/cli.js" + cli (-> (str app-dir "/node_modules/react-native/local-cli/cli.js") java.io.File. .getAbsolutePath) dir (-> in .getAbsoluteFile .getParent) @@ -218,7 +218,7 @@ (util/info "Creating temp dir: %s\n" (.getAbsolutePath tempdirf)) (.mkdirs tempdirf) (copy-file fname temppath) - (binding [util/*sh-dir* "app"] + (binding [util/*sh-dir* app-dir] (try (util/dosh "node" cli "bundle" "--platform" "ios" From 3431852ec1eb8f801c503c8e0263f4079de5584e Mon Sep 17 00:00:00 2001 From: Adam Frey Date: Tue, 8 Mar 2016 10:59:47 -0500 Subject: [PATCH 2/2] Add platform option to bundle task --- src/mattsum/boot_react_native.clj | 7 ++++++- src/mattsum/impl/boot_helpers.clj | 17 +++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mattsum/boot_react_native.clj b/src/mattsum/boot_react_native.clj index 85f2c25..3fa4002 100644 --- a/src/mattsum/boot_react_native.clj +++ b/src/mattsum/boot_react_native.clj @@ -285,6 +285,7 @@ require('" boot-main "'); (deftask bundle "Bundle the files specified" [a app-dir OUT str "The (relative) path to the React Native application" + p platform PLATFORM str "The platform to bundle" f files ORIGIN:TARGET {str str} "{origin target} pair of files to bundle"] (let [tmp (c/tmp-dir!)] (c/with-pre-wrap fileset @@ -292,5 +293,9 @@ require('" boot-main "'); (let [in (bh/file-by-path origin fileset) out (clojure.java.io/file tmp target)] (clojure.java.io/make-parents out) - (bh/bundle* app-dir in out tmp))) + (bh/bundle* {:app-dir app-dir + :platform platform + :input-file in + :output-file out + :output-dir tmp}))) (-> fileset (c/add-resource tmp) c/commit!)))) diff --git a/src/mattsum/impl/boot_helpers.clj b/src/mattsum/impl/boot_helpers.clj index 8fc487b..f4a6a69 100644 --- a/src/mattsum/impl/boot_helpers.clj +++ b/src/mattsum/impl/boot_helpers.clj @@ -202,7 +202,7 @@ (defn copy-file [source-path dest-path] (clojure.java.io/copy (clojure.java.io/file source-path) (clojure.java.io/file dest-path))) -(defn bundle* [app-dir in outf outd] +(defn bundle* [{:keys [app-dir platform input-file output-file output-dir]}] (let [app-dir (or app-dir "app") tempfname (str "nested/temp/" (java.util.UUID/randomUUID) ".js") temppath (str app-dir "/" tempfname) @@ -210,8 +210,8 @@ cli (-> (str app-dir "/node_modules/react-native/local-cli/cli.js") java.io.File. .getAbsolutePath) - dir (-> in .getAbsoluteFile .getParent) - fname (-> in .getAbsolutePath)] + dir (-> input-file .getAbsoluteFile .getParent) + fname (-> input-file .getAbsolutePath)] (util/info "Bundling %s...\n" fname) ;; create nested temp directory ;; we need this in order to keep the react packager happy @@ -221,11 +221,12 @@ (binding [util/*sh-dir* app-dir] (try (util/dosh "node" cli - "bundle" "--platform" "ios" - "--dev" "true" - "--entry-file" tempfname - "--bundle-output" (.getAbsolutePath outf) - "--assets-dest" (.getAbsolutePath outd)) + "bundle" + "--platform" platform + "--dev" "true" + "--entry-file" tempfname + "--bundle-output" (.getAbsolutePath output-file) + "--assets-dest" (.getAbsolutePath output-dir)) (finally (util/dosh "rm" "-f" tempfname))))))