-
Notifications
You must be signed in to change notification settings - Fork 113
Adds Option To Generate ReactNative Example project #57
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
Adds Option To Generate ReactNative Example project #57
Conversation
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.
Amazing work 🎉
I really love this feature, I just have a few small questions.
lib.js
Outdated
// Adds and links the created library project | ||
const pathExampleApp = './' + name + '/example'; | ||
const options = { cwd: pathExampleApp, stdio:'inherit'}; | ||
execSync('yarn add file:../', options); |
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.
Would it be possible to check first if yarn is available here?
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.
Sure. I guess fallback would be npm or shall it just throw an error?
I think npm you may not be able to link locally (or I could be totally wrong - maybe it was the point at a commit that didn't work with npm).
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 added a try/catch around yarn and added fallback support for npm.
lib.js
Outdated
return; | ||
} | ||
// Adds and links the created library project | ||
const pathExampleApp = './' + name + '/example'; |
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.
Nitpick: What do you think about using template literals here? (It's just a personal preference on my part.)
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.
Sure. Will look at updating this.
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.
updated to use template literals.
dependencies { | ||
classpath 'com.android.tools.build:gradle:1.3.1' | ||
classpath 'com.android.tools.build:gradle:2.2.3' |
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'm a bit concerned that this change doesn't have a lot of to do with the rest of pull request. Am I missing something or could this be delivered separately?
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.
yes, resolved this in #59
fd7ab4f
to
e19a7ba
Compare
@maicki - could you give this a review? It's good to go. |
lib.js
Outdated
authorEmail, | ||
license, | ||
}; | ||
return Promise |
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 think we don't need the Promise.resolve here, just return the createFolder
Furthermore I think in all of the early returns for the !generateExample
checks we should return a Promise.reject if we consume the promise that is returned from this funciton or a Promise.resolve in case we see it as success.
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.
Yea, that's a good improvement. I move the createFolder
out.
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'll make these change and then merge it.
lib.js
Outdated
authorEmail, | ||
license, | ||
}; | ||
return Promise |
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.
Yea, that's a good improvement. I move the createFolder
out.
lib.js
Outdated
.resolve() | ||
.then(() => { | ||
if (!generateExample) { | ||
return |
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.
Yes, this should be a Promise.resolve()
lib.js
Outdated
}) | ||
.then(() => { | ||
if (!generateExample) { | ||
return; |
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.
same here Promise.resolve()
Verified that both with and without generate parameter it works as expected. |
This is a really great feature, but on a totally fresh install it causes Metro to get terribly confused. I see an "Ambiguous Module Resolution Error" caused by metro picking up both the package.json in the example/package.json directory but ALSO the same package.json a second time when it's installed in node_modules/$MODULE_NAME/example! I've worked around this by moving the example app out of the tree, but I'm not really sure what a good way to solve this would be at the tool level. |
@pvh - Hmm. I did not run into this and we always have an example folder inside a lib project (for testing purposes and to provide usage examples of a lib). What are the commands that you are running? Perhaps we could make the path for the example app configurable. The reason it's inside the project is because one would ideally push both the lib and example to a single repo on github. |
I get the same problem, steps to reproduce the issue:
Metro bundler fails with the error:
|
I tried to add a metro bundler configuration file to exclude the directory
|
@maxme - thanks for the steps. I'll try to repro this later. I see where my workflow differs. Instead of your last command
which theoretically should do the same. And I built out of AS or XCode. |
FWIW, I also tried:
And it fails with the same error. I'm far from being an RN veteran so I'm not sure what's the best way to setup the library and example directories. Having the example directory as a library sub directory seems to be a source of issues. |
that's great! it will save lot's time when making a native module at the beginning. when will this merged version will be sent to npm? because now still has no this feature in npm version yet. |
Adds the option
--generate-example
that generate an example project and links the newly created to it.This addresses #28.
Due to
react-native init project_name
not executing in a folder that already contains apackage.json
file, the example is generated first, then all the files are created and last the library is linked to the example.