This is a problem I have been solving in my projects last days. And I think I have some good (not perfect) solution so far.
Idea. We don`t have any built-in functions to help us handle this case, so we can use some external manipulation that can do the job. What we need is just multiple Android and iOS projects and single JS code base.
Implementation. I`ve come to this project structure:
ios
and android
folders is well known to you, they are native project folders.
src
is a folder with JS code, you can organize it whatever you want
manager
is most interesting one. Here we can store multiple native project files. We can have multiple native project folders in it, for example app1-android
app1-ios
app2-android
app2-ios
. And when we want to work on app1
we just copy app1-ios
and app1-android
to our root ios
and android
folders, so the actual project is app1
. When we are done with app1
we can save android
and ios
folders to our manager
and then just copy app2-ios
and app2-android
to root ios
and android
. And we are all good to develop our app2
.
We can do it manually. But we are developers and we can make it much easier. I`ve written a PHP script that makes it as easy as php save.php -a app1
and php set.php -a app1
to copy from manager
to root and backwards. Moreover, it takes care of not copying some unimportant staff (pods folder in ios, build in android etc.) and running pod install
to ensure we have all pod in actual project.
I stick to one package.json
file to have all npm modules installed once, so I don`t have to run npm install
after each project switch.
Afterall, we can have as much projects as we wish in one repo, we can customize each one independently.
PS If you want me to share my scripts I`ll do it as fast as I can (need some time to prepare it for github and to write some more detailed instructions), just let me know.