vouch-opensource / krell

Simple ClojureScript React Native Tooling
Eclipse Public License 1.0
673 stars 37 forks source link

Customise generated index.js #144

Closed wodin closed 2 years ago

wodin commented 2 years ago

Hi

I got Krell working in an Expo app. The main thing you need to do is build with EAS Build instead of the "classic" build system. It's useful to install expo-dev-client too.

The only other thing you need to do is patch the generated index.js something like this:

diff --git resources/index.js resources/index.js
index ecebb2d..c8bf02d 100644
--- resources/index.js
+++ resources/index.js
@@ -1,12 +1,12 @@
 /* Generated by Krell, do not edit by hand */

+import 'expo-dev-client';
+import { registerRootComponent } from 'expo';
 import React from 'react';
 import {
-    AppRegistry,
     View,
     Text
 } from 'react-native';
-import {name as appName} from './app.json';
 import {krellUpdateRoot, onKrellReload} from './$KRELL_OUTPUT_TO';

 let plainStyle = {
@@ -58,4 +58,7 @@ class KrellRoot extends React.Component {
     }
 }

-AppRegistry.registerComponent(appName, () => KrellRoot);
+// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
+// It also ensures that whether you load the app in Expo Go or in a native build,
+// the environment is set up appropriately
+registerRootComponent(KrellRoot);

As you said on twitter, "it would be nice for example to allow anyone to write tiny Krell extension lib that injects what is required".

Thanks :)

swannodette commented 2 years ago

@wodin sorry for the delay - I've added a thing to master to make this easier in a couple of ways. There's now a command line flag to supply custom index.js on the classpath - and for people who want to compose some kind of template (without forcing users to supply args) - we try krell_index.js before defaulting to index.js.

Please give it a try. If it works for you we can close this.

wodin commented 2 years ago

Yes, this works. I copied the patched index.js to src/krell_index.js and that was used to generate the correct index.js.

This took me a while to get working because I couldn't work out how to get krell to connect to the right IP address. The last time I tried it it connected to my VPN IP address. This time it was connecting to a docker IP, so I could not just start my VPN to get things working.

Part of the problem was because I didn't realise that the --host option is silently ignored if you do this:

clj -M -m krell.main -co build.edn -r --host blah

I eventually worked out you have to specify it during the compile step.

swannodette commented 2 years ago

@wodin great! I'll cut 0.5.3 tomorrow.