Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.
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
6 changes: 6 additions & 0 deletions build.boot
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

(set-env! :resource-paths #{"src" "resources"}
:dependencies '[[pandeiro/boot-http "0.7.1-SNAPSHOT" :scope "test"]
[com.cemerick/url "0.1.1"]
Expand All @@ -18,6 +19,11 @@
:license {"Eclipse Public License"
"http://www.eclipse.org/legal/epl-v10.html"}})

(set-env! :repositories [["clojars" (cond-> {:url "https://clojars.org/repo/"}
(System/getenv "CLOJARS_USER")
(merge {:username (System/getenv "CLOJARS_USER")
:password (System/getenv "CLOJARS_PASS")}))]])

(deftask build []
(comp (pom)
(jar)
Expand Down
6 changes: 3 additions & 3 deletions example/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "15.3.1",
"react-dom": "15.3.1",
"react-native": "0.36.0"
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-native": "^0.39.2"
}
}
2,751 changes: 2,751 additions & 0 deletions example/app/yarn.lock

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions example/build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
'[boot.core :as b]
'[boot.util :as u]
'[clojure.string :as s]
'[mattsum.boot-react-native :as rn :refer [patch-rn]]
)

(task-options! patch-rn {:app-dir "app"})
'[mattsum.boot-react-native :as rn])

(deftask build
[]
Expand All @@ -46,7 +43,7 @@
(deftask dev
"Build app and watch for changes"
[]
(comp (patch-rn)
(comp
(watch)
(build)
(speak)))
Expand All @@ -55,7 +52,6 @@
"Build a distributable bundle of the app"
[]
(comp
(patch-rn)
(cljs :ids #{"dist"})
(rn/bundle :files {"dist.js" "main.jsbundle"})
(target :dir ["app/dist"])))
2 changes: 1 addition & 1 deletion example/dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
(cd .. && boot build) && boot dev "$@"
(cd .. && boot inst) && boot dev "$@"
2 changes: 1 addition & 1 deletion readme.org
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This has been tested on Android and IOS.
There is an example app to demonstrate using this plugin.

To start it up:
* Run =npm install= inside example/app
* Run =npm install= or =yarn= inside example/app
* Run =boot dev= inside example
* For Android:
* Connect device to computer
Expand Down
68 changes: 23 additions & 45 deletions src/mattsum/boot_react_native.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[me.raynes.conch :refer [programs with-programs let-programs] :as sh]
[mattsum.impl
[boot-helpers :as bh :refer [exit-code find-file shell]]
[goog-deps :refer [get-files-to-process setup-links-for-dependency-map]]]))
[goog-deps :as gd :refer [get-files-to-process setup-links-for-dependency-map]]]))

;;(use 'alex-and-georges.debug-repl)

Expand Down Expand Up @@ -73,7 +73,7 @@
new-script (str "
var CLOSURE_UNCOMPILED_DEFINES = null;
require('./" out-dir "goog/base.js');
require('" boot-main "');
require('./" gd/output-dir "/" boot-main "');
")]
(spit out-file new-script)
(-> fileset
Expand Down Expand Up @@ -260,59 +260,37 @@ For the output-dir and output-to options, see the ClojureScript compiler options
[]
(let [running (atom false)]
(c/with-post-wrap fileset
(when-not @running ;; make sure we run only once
(reset! running true)
(binding [util/*sh-dir* "app"]
(util/dosh "node" "node_modules/react-native/local-cli/cli.js" "run-ios")))
fileset)))
(when-not @running ;; make sure we run only once
(reset! running true)
(binding [util/*sh-dir* "app"]
(util/dosh "node" "node_modules/react-native/local-cli/cli.js" "run-ios")))
fileset)))

(deftask print-ios-log
"Print iOS simulator log"
[g grep GREP str "Only print lines containg GREP, using fgrep(1). Defaults to printing all lines"]
(let [!running (atom false)]
(c/with-pre-wrap fileset
(when-not @!running ;; make sure we run only once
(reset! !running true)
(future (bh/tail-fn bh/newest-log grep)))
fileset)))
(when-not @!running ;; make sure we run only once
(reset! !running true)
(future (bh/tail-fn bh/newest-log grep)))
fileset)))

(deftask bundle
"Bundle the files specified"
[f files ORIGIN:TARGET {str str} "{origin target} pair of files to bundle"]
(let [tmp (c/tmp-dir!)]
(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)))
(-> fileset (c/add-resource tmp) c/commit!))))
(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)))
(-> fileset (c/add-resource tmp) c/commit!))))

(deftask patch-rn
"Patch the node module `react-native' to recognize goog.require as a dependency

Currently works with react-native >= 0.29.0

Note that you will need to `npm install' before calling this task. The task
checks if the patch has already been applied and, if so, skips it silently. As a
result it can be safely run on every build.

See https://github.com/mjmeintjes/boot-react-native/issues/49"
[a app-dir OUT str "Path to the React Native app-dir containing package.json"]
(let [app-dir (or app-dir "app")]
(c/with-pre-wrap fileset
(let [path (bh/write-resource-to-path "patch-rn.sh" "patch-rn.sh")
path2 (bh/write-resource-to-path "rn-goog-require.patch" "rn-goog-require.patch")]
(util/info "Checking if React Native needs to be patched...\n")
(assert (-> (str app-dir "/package.json") io/as-file .exists)
(str "Did not find expected file package.json in " app-dir))
(assert (-> (str app-dir "/node_modules/react-native") io/as-file .exists)
(str "Did not find expected directory node_modules/react-native in " app-dir
". Did you run `npm install?'"))
(try
(util/dosh "bash" (str path "/patch-rn.sh") (str path2 "/rn-goog-require.patch") app-dir)
(catch Exception e
(util/warn "Could not patch React Native in app-dir `%s'. Possibly incompatible version of react-native?\n"
app-dir)
(throw e)))
fileset))))
"DEPRECATED, no longer needed"
[a app-dir OUT str "Path to the React Native app-dir containing package.json"]
(util/info "patch-rn is DEPRECATED since it is no longer needed\n")
(c/with-pre-wrap fileset
fileset))
49 changes: 31 additions & 18 deletions src/mattsum/impl/goog_deps.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
(ns mattsum.impl.goog-deps
(:require [boot
[core :as c]
[util :as u]
[file :as fl]]
[clojure.java.io :as io]
[clojure.string :as s]
[mattsum.impl.boot-helpers :refer [find-file]]))

(def output-dir "cljs_output")

(defn split-line [line]
(when-let [res (re-find #"[\"|'](.*?)[\"|'],\s(\[\'.*?\'\])" line)]
[(res 1) (res 2)]))
Expand Down Expand Up @@ -54,15 +58,16 @@
that can be used the set up files in directory structure that React Native can use"
[dependency-maps fileset tmp-dir src-dir]
(map (fn [{:keys [ns path]}]
{:target-file (io/file (str tmp-dir "/node_modules") ns)
{:target-file (io/file (str tmp-dir "/" output-dir) ns)
:source-file (some->> (str src-dir path)
(find-file fileset))
:map-file (some->> (str src-dir path ".map")
(find-file fileset))
:cljs-file (some->> (.replace (str src-dir path) ".js" ".cljs")
(find-file fileset))
:target-map (io/file (str tmp-dir "/node_modules") (str ns ".map"))
:target-cljs (io/file (str tmp-dir "/node_modules") (.replace ns ".js" ".cljs"))
:target-map (io/file (str tmp-dir "/" output-dir) (str ns ".map"))
:target-cljs (io/file (str tmp-dir "/" output-dir)
(.replace ns ".js" ".cljs"))
:ns ns
})
dependency-maps))
Expand All @@ -75,18 +80,26 @@

(defn setup-links-for-dependency-map
[files-to-process]
(doseq [{:keys [target-file
source-file
map-file
cljs-file
target-map
target-cljs
ns]} files-to-process]
(when source-file
(io/make-parents target-file)
(new-hard-link source-file target-file)
(when (and (fl/exists? map-file)
(fl/exists? cljs-file))
(new-hard-link map-file target-map)
(new-hard-link cljs-file target-cljs)))))

(let [tm (System/currentTimeMillis)]
(doseq [{:keys [target-file
source-file
map-file
cljs-file
target-map
target-cljs
ns]} files-to-process]
(when source-file
(io/make-parents target-file)
(spit
target-file
(reduce-kv #(.replace %1 %2 %3)
(slurp source-file)
{"goog.require('" "require('./"
"goog.require(\"" "require(\"./"}))
(when (and (fl/exists? map-file)
(fl/exists? cljs-file))
(new-hard-link map-file target-map)
(new-hard-link cljs-file target-cljs))))
(u/dbug "Time to copy and rewrite js files to %s: %s ms\n"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a debug tag so that you can measure how long the copying and replacement takes

output-dir
(- (System/currentTimeMillis) tm))))