28

I have a folder setup with some files I already want to have in the folder. I want to be able to run

react-native init PROJECTNAME

and instead of creating a folder PROJECTNAME it would init a react-native project in the folder I am currently in.

Is this possible?


Currently, I have my setup already created from previous projects that I enjoy using (packages.json, config files, etc). I delete the node_modules, and then react-native init PROJECTNAME. Then I take the PROJECTNAME/ios PROJECTNAME/android folders generated within that folder, move them into the main project folder and it works pretty smoothly. Just not optimal.

3
  • I'm also creating the project and manually moving the files. If you already had a build then I found I also needed to clear the cache ./node_modules/react-native/packager/packager.sh clean Commented Oct 13, 2016 at 10:01
  • 1
    would be nice to make a script out of this, or nice if react-native could update their cmd line to accept this setup :) Commented Oct 15, 2016 at 13:01
  • 1
    Yep, especially if you created the repo first. Commented Mar 4, 2017 at 2:48

5 Answers 5

33

You can do

$ cd .. && react-native init folder_name

It will overwrite your package.json but keep the non-default files.

Sign up to request clarification or add additional context in comments.

3 Comments

Will this not overwrite the entire folder?
Only the files it needs to.
This is the code to copy the folder name, drop down a level and init into it. result=${PWD##*/} && cd .. && react-native init $result just be sure to only use alphanumeric characters and underscores in folder names or react native will reject it. This assumes you start in the folder you want to init.
6

You should have install react-native-cli instead of react-native globally as described here.

And then the command is:

npx react-native-cli init appname --directory ./appPathToDir

Comments

2

This issue is currently tracked there.

1 Comment

Already working
1

The reason I wanted to do this was to have a sort of mono-repo, but I have transitioned away from this approach as I am not sure it is beneficial.

Comments

-1

expo init /.

this will create expo app in current directory using the folder name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.