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..3fa4002 100644 --- a/src/mattsum/boot_react_native.clj +++ b/src/mattsum/boot_react_native.clj @@ -284,12 +284,18 @@ 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" + 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 (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 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 ce99d46..f4a6a69 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,29 +202,31 @@ (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* [{: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) 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) - 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 (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" - "--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))))))