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

Export better init function #1398

Closed
brody4hire opened this issue Apr 13, 2021 · 1 comment
Closed

Export better init function #1398

brody4hire opened this issue Apr 13, 2021 · 1 comment

Comments

@brody4hire
Copy link

Describe the Feature

Background

I would like to include and use @react-native-community/cli in tools such as create-react-native-module and react-native-module-init to generate an example project rather than relying on the user to install some version of the CLI. This was suggested in brody4hire/create-react-native-module#204.

One solution would be to use a utility such as execa to spawn and wait for the CLI to generate the example project. But I think it would be smoother to simply import and call a function in @react-native-community/cli to generate the example project.

@react-native-community/cli does export an init function but it seems to point into an internal initCompat module: https://github.com/react-native-community/cli/blob/v5.0.1-alpha.2/packages/cli/src/index.ts#L11

This exported function seems to assume that it should generate the project based on the React Native template in node_modules: https://github.com/react-native-community/cli/blob/v5.0.1-alpha.2/packages/cli/src/tools/generator/templates.ts#L25

When I tried using this exported function in create-react-native-module I was not happy with the result due to the lack of flexibility, as in this abandoned PR: brody4hire/create-react-native-module#420

Another disadvantage is that react-native would be needed as a peer dependency.

Requested feature

Export a better init function that allows a different React Native version such as [email protected] or the wonderful react-native-tvos fork. Here is the function that I would like to use: https://github.com/react-native-community/cli/blob/v5.0.1-alpha.2/packages/cli/src/commands/init/init.ts#L196-L220

Temporary workaround

I made https://github.com/brodybits/react-native-init-func with the following workaround in its index.js:

const init = require('@react-native-community/cli/build/commands/init').default
  .func

module.exports = init

Possible Implementations

Simply export a function such as https://github.com/react-native-community/cli/blob/v5.0.1-alpha.2/packages/cli/src/commands/init/init.ts#L196-L220

Related Issues

N/A

@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant