Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v57 #192

Merged
merged 2 commits into from
Dec 3, 2018
Merged
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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "re-natal",
"version": "0.9.0",
"description": "Bootstrap ClojureScript React Native apps with reagent and re-frame for iOS and Android",
"description": "Bootstrap ClojureScript React Native apps with reagent, re-frame and om next for iOS and Android",
"main": "index.js",
"author": "Artur Girenko <[email protected]>",
"license": "MIT",
"dependencies": {
"chalk": "^1.1.1",
"chalk": "^2.4.1",
"check-dependencies": "^1.0.1",
"coffeescript": "^1.9.3",
"coffeescript": "^2.3.2",
"commander": "^2.8.1",
"deepmerge": "^1.5.2",
"fs-extra": "^0.26.5",
"deepmerge": "^2.1.1",
"fs-extra": "^7.0.0",
"handlebars": "^4.0.10",
"klaw-sync": "^2.1.0",
"klaw-sync": "^5.0.0",
"semver": "^5.0.1"
},
"engines": {
Expand All @@ -37,7 +37,8 @@
"ios",
"android",
"reagent",
"re-frame"
"re-frame",
"om next"
],
"bugs": {
"url": "https://github.com/drapanjanas/re-natal/issues"
Expand Down
26 changes: 17 additions & 9 deletions re-natal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ ipAddressRx = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/i
debugHostRx = /host]\s+\?:\s+@".*";/g
namespaceRx = /\(ns\s+([A-Za-z0-9.-]+)/g
jsRequireRx = /js\/require "(.+)"/g
rnVersion = '0.55.4'
rnWinVersion = '0.55.0-rc.0'
rnVersion = '0.57.0'
rnWinVersion = '0.57.0'
rnPackagerPort = 8081
process.title = 're-natal'
buildProfiles =
Expand Down Expand Up @@ -65,7 +65,7 @@ interfaceConf =
common: ["events.cljs", "subs.cljs", "db.cljs"]
other: [["reagent_dom.cljs","reagent/dom.cljs"], ["reagent_dom_server.cljs","reagent/dom/server.cljs"]]
deps: ['[reagent "0.8.1" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server cljsjs/create-react-class]]'
'[re-frame "0.10.5"]']
'[re-frame "0.10.6"]']
shims: []
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.ios.core)'
sampleCommand: '(dispatch [:set-greeting "Hello Native World!"])'
Expand All @@ -74,7 +74,7 @@ interfaceConf =
sources:
common: ["state.cljs"]
other: [["support.cljs","re_natal/support.cljs"]]
deps: ['[org.omcljs/om "1.0.0-beta3" :exclusions [cljsjs/react cljsjs/react-dom]]']
deps: ['[org.omcljs/om "1.0.0-beta4" :exclusions [cljsjs/react cljsjs/react-dom]]']
shims: ["cljsjs.react", "cljsjs.react.dom"]
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.state)'
sampleCommand: '(swap! app-state assoc :app/msg "Hello Native World!")'
Expand Down Expand Up @@ -131,7 +131,7 @@ ensureExecutableAvailable = (executable) ->
exec "type #{executable}"

isYarnAvailable = () ->
false
exec 'yarn -v'
Copy link
Owner

Choose a reason for hiding this comment

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

This fails if there is no yarn:

Command failed: yarn -v

Leave it as false for now?


isSomeDepsMissing = () ->
depState = ckDeps.sync {install: false, verbose: false}
Expand Down Expand Up @@ -338,6 +338,8 @@ copyDevEnvironmentFilesForPlatform = (platform, interfaceName, projNameHyph, pro
edit mainDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, platform]]

generateConfigNs = (config) ->
fs.copySync("#{resources}/rn-cli.config.js", "./rn-cli.config.js")

template = hb.compile(readFile "#{resources}/config.cljs")
fs.writeFileSync("#{config.envRoots.dev}/env/config.cljs", template(config))

Expand Down Expand Up @@ -559,10 +561,16 @@ init = (interfaceName, projName, platforms) ->
private: true
scripts:
start: 'node node_modules/react-native/local-cli/cli.js start'
'run-ios': 'node node_modules/react-native/local-cli/cli.js run-ios',
'run-android': 'node node_modules/react-native/local-cli/cli.js run-android',
# rn-cli-config.js & Node v8+ exposes GC avoids the GC out of memory errors when Babel compiles large Clojurescript output
'bundle-ios': 'lein prod-build && node --expose-gc --max_old_space_size=8192 \'./node_modules/react-native/local-cli/cli.js\' bundle --sourcemap-output main.jsbundle.map --bundle-output ios/main.jsbundle --entry-file index.ios.js --platform ios --assets-dest ios',
'bundle-android': 'lein prod-build && node --expose-gc --max_old_space_size=8192 \'./node_modules/react-native/local-cli/cli.js\' bundle --sourcemap-output main.jsbundle.map --bundle-output android/main.jsbundle --entry-file index.android.js --platform android --assets-dest android'
dependencies:
'react-native': rnVersion
# Fixes issue with packager 'TimeoutError: transforming ... took longer than 301 seconds.'
'babel-plugin-transform-es2015-block-scoping': '6.15.0'
'@babel/plugin-external-helpers': '^7.0.0'
devDependencies:
'metro-react-native-babel-preset': '0.45.4'

if 'windows' in platforms || 'wpf' in platforms
pkg.dependencies['react-native-windows'] = rnWinVersion
Expand Down Expand Up @@ -596,7 +604,7 @@ init = (interfaceName, projName, platforms) ->
log "cd #{projNameHyph}", 'inverse'
log ''
log 'Run iOS app:' , 'yellow'
log 'react-native run-ios > /dev/null', 'inverse'
log 'react-native run-ios --configuration Debug > /dev/null', 'inverse'
log ''
log 'To use figwheel type:' , 'yellow'
log 're-natal use-figwheel', 'inverse'
Expand Down Expand Up @@ -768,7 +776,7 @@ generateDevScripts = () ->

for platform in platforms
moduleMap = generateRequireModulesCode(platformModulesAndImages(config, platform))
fs.writeFileSync "index.#{platform}.js", "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','#{platform}','#{devHost[platform]}');"
fs.writeFileSync "index.#{platform}.js", "#{moduleMap}require('./figwheel-bridge').withModules(modules).start('#{projName}','#{platform}','#{devHost[platform]}');"
log "index.#{platform}.js was regenerated"

updateIosRCTWebSocketExecutor(devHost.ios)
Expand Down
10 changes: 5 additions & 5 deletions resources/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.238"]
[org.clojure/clojurescript "1.10.339"]
$INTERFACE_DEPS$]
:plugins [[lein-cljsbuild "1.1.4"]
[lein-figwheel "0.5.14"]]
[lein-figwheel "0.5.16"]]
:clean-targets ["target/" #_($PLATFORM_CLEAN$)]
:aliases {"prod-build" ^{:doc "Recompile code with prod profile."}
["do" "clean"
Expand All @@ -16,14 +16,14 @@
["do" "clean"
["with-profile" "advanced" "cljsbuild" "once"]]}
:jvm-opts ["-XX:+IgnoreUnrecognizedVMOptions" "--add-modules=java.xml.bind"]
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.14"]
[com.cemerick/piggieback "0.2.1"]]
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.16"]
[com.cemerick/piggieback "0.2.2"]]
:source-paths ["src" "env/dev"]
:cljsbuild {:builds [
#_($DEV_PROFILES$)]}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
:prod {:cljsbuild {:builds [
#_($PROD_PROFILES$)]}}
:advanced {:dependencies [[react-native-externs "0.1.0"]]
:advanced {:dependencies [[react-native-externs "0.2.0"]]
:cljsbuild {:builds [
#_($ADVANCED_PROFILES$)]}}})
104 changes: 104 additions & 0 deletions resources/rn-cli.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
This is a custom React Native/Metro Transformer to fix issues
with bundling a large single JS file. It works with RNv0.57.

Add the command below to package.json or project.clj.
node --expose-gc --max_old_space_size=8192 \
'./node_modules/react-native/local-cli/cli.js' bundle \
--sourcemap-output main.jsbundle.map \
--bundle-output ios/main.jsbundle \
--entry-file release.ios.js \
--platform ios \
--dev true \
--assets-dest ios \
--config=./rn-cli.config.js",
*/

var DEBUG = true;
var debug = DEBUG ?
function(){ console.log.call(this, [].slice.call(arguments)); } :
function(){};

// Big files can slow down Metro, so we'll dump GC every 30 seconds to be safe.
(function scheduleGc() {
if (!global.gc) {
console.log("Garbage collection is not exposed");
return;
}

var timeoutId = setTimeout(function() {
global.gc();
console.log("Manual gc", process.memoryUsage());
scheduleGc();
}, 30 * 1000);
timeoutId.unref();
})();

// Custom Metro Transform (validated with React Native v0.57)
var path = require("path");
var fs = require("fs");
var defaultTransformer = require("./node_modules/metro/src/reactNativeTransformer");

function clojurescriptTransformer(code, filename) {
console.log("Generating sourcemap for " + filename);
var map = fs.readFileSync(filename + ".map", { encoding: "utf8" });
var sourceMap = JSON.parse(map);

var sourcesContent = [];
sourceMap.sources.forEach(function(path) {
var sourcePath = __dirname + "/" + path;
var isDirectory = path.indexOf(".") === -1;
if (isDirectory) {
debug("ignore");
return;
}

try {
// try and find the corresponding `.cljs` file first
var file = sourcePath.replace(".js", ".cljs");
debug(file);
sourcesContent.push(fs.readFileSync(file, "utf8"));
} catch (e) {
// otherwise fallback to whatever is listed as the source
debug("sourcePath", path);
try {
sourcesContent.push(fs.readFileSync(sourcePath, "utf8"));
} catch (e) {
if (sourcePath.match(/\.js$/) !== null) {
console.warn("clojurescript transformer error with file ", sourcePath);
}
}
}
});
sourceMap.sourcesContent = sourcesContent;

return {
filename: filename,
code: code.replace("# sourceMappingURL=", ""),
map: sourceMap
};
}


var customClojurescriptTransformer = function(data){
var isCljsEntryFile = data.filename.match(/index\.*\.js/) !== null;
console.log('d', data.filename);
if (isCljsEntryFile) {
debug("using custom clojurescript transformer");
return clojurescriptTransformer(data.src, data.filename);
} else {
return defaultTransformer.transform(data);
}
}

// @see https://facebook.github.io/metro/docs/en/configuration
var rnCliConfig = {
projectRoot: path.resolve(__dirname),
getTransformModulePath: () => require.resolve("./rn-cli.config")
}

module.exports = {
transform: customClojurescriptTransformer,
projectRoot: projectRoot,
Copy link

Choose a reason for hiding this comment

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

I get an error here (node:19615) UnhandledPromiseRejectionWarning: ReferenceError: projectRoot is not defined

This line should probably be projectRoot: rnCliConfig.projectRoot,

getTransformModulePath: rnCliConfig.getTransformModulePath
};