-
Notifications
You must be signed in to change notification settings - Fork 212
chore: use react-native init for generating example app #271
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
chore: use react-native init for generating example app #271
Conversation
packages/create-react-native-library/src/utils/exampleAppGenerators.ts
Outdated
Show resolved
Hide resolved
packages/create-react-native-library/src/utils/exampleAppGenerators.ts
Outdated
Show resolved
Hide resolved
packages/create-react-native-library/src/utils/exampleAppGenerators.ts
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,127 @@ | |||
import fs from 'fs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can call it generateExampleApp
.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exampleAppGenerators
is different 😅
I think generateReactNativeExample
or something like that is good, we'd also need generateExpoExample
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested your changes using Native view template and everything works fine. Great job 🚀 ❤️
… app This way we won't have to maintain these versions in the future Note: this only works for native example apps for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, after selecting my options, it feels like it gets stuck while generating the project with RN CLI.
We should add a progress indicator using https://www.npmjs.com/package/ora while the project is being generated. Something like [] Generating project...
(replace []
with a spinner)
If I don't have an internet connection, the CLI gets stuck and doesn't seem do anything. It should print an error instead.
...reate-react-native-library/templates/example-turbo/example/patches/react-native+0.70.0.patch
Outdated
Show resolved
Hide resolved
packages/create-react-native-library/src/utils/generateRNApp.ts
Outdated
Show resolved
Hide resolved
CLI getting stuck is caused by |
and one note:
I have tried many things but couldn't get it working properly. This is not a regression as before this PR, we didn't have these tests at all. |
Let's think about it in a follow up PR |
/rebase |
What's up with CLI getting stuck? Maybe @adamTrz could help out here |
Currently, if you become offline, CLI keeps trying to work. We might throw an error stating that the user is currently offline. |
Don't think I can help with no internet connection 😉 Tried to repro this with local CLI and I did got an error info There appears to be trouble with your network connection. Retrying... |
This is occasionally coming from Yarn. Nothing to be worried about imho |
In this case we skip installing dependencies so I think Yarn isn't involved here |
thanks for the hard work! |
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Summary
The current state of the library requires manual labor to upgrade example apps. Instead of manually upgrading the example app we can rely on React Native CLI to generate the app for us. We can then simply make necessary changes to the created template.
How does it work?
We first run
npx react-native init <projectName>Example --template react-native-template-typescript --directory example --skip-install
to create the app. We then make the following changes:.gitignore
,.eslintrc.js
,.prettierrc.js
,index.js
andApp.js
metro.config.js
andbabel.config.js
react-native.config.js
,src/App.tsx
andindex.ts
package.json
:test
andlint
scripts then addpods
andpostInstall
scriptsRemove some dependencies
@react-native-community/eslint-config @tsconfig/react-native @types/jest @types/react-native @typescript-eslint/eslint-plugin @typescript-eslint/parser babel-jest eslint jest typescriptAdd some dependencies
'babel-plugin-module-resolver': '^4.1.0' 'metro-react-native-babel-preset': '^0.72.1' 'patch-package': '^6.4.7' 'postinstall-postinstall': '^2.1.0'jest
confignewArchEnabled=true
onandroid/gradle.properties
and addENV['RCT_NEW_ARCH_ENABLED'] = '1'
toios/Podfile
__tests__/App-test.tsx
to importApp
from../src/App
package.json
'sreact
andreact-native
versions fromexample/package.json
Notes and issues
__tests__
folder insideexample
directory. The reason is that this folder includesreact-test-renderer
tests. These tests run fine when they are called fromexample/package.json
. But when you try to call them from root levelpackage.json
, it throws the following:I have tried many things but couldn't get it working properly. This is not a regression as before this PR, we didn't have these tests at all.
Test plan
lint
,test
andtypescript
scripts work properly on generated projectNext steps
Follow this approach for
Expo modules