Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use single expo codebase for multiple apps

I got an application what we white-label for others. This means we share the same functionality through the apps but there are some specific design elements (mostly colors and pictures) in each app.

I'm looking for the easiest and best way to identify the built app for my Expo React Native codebase.

My plan is store everything in the same javascript codebase, and just get load the correct config files by the application name.

In this case, I would get a few apps in the stores:

  • BlueApp
  • RedApp
  • GreenApp

All of them would load the same expo app: exp.host/@comp/colours And this expo app should set the background to blue in the BlueApp and red in the RedApp.

! I don't want to detach my expo app, I want to still build my apps with the expo.

like image 631
wntsmk Avatar asked Aug 07 '18 02:08

wntsmk


1 Answers

It is possible to use a different configuration file by doing expo start --config=some-app.json. One problem I ran into is that some assets were still being required at a specific location (eg. assets/images/icon.png).

The solution I came up with is to switch the project, via a bash script, every time you start a project. That way, the development you run you will also publish without fussing around config parameters that expo may or may not support.

So in your package.json you can have run commands which look like this:

./switch project1 && expo start

The bash script would sync all assets from src directory, including app.json to their expected paths. The directory structure would looks like this:

src
 - project1
     - app.json
     - assets
 - project2
     - app.json
     - assets

and the script:

#!/bin/bash

if [ $1 == "swaggr" ] || [ $1 == "chatsera" ] 
then 
    echo "switching to $1"
    unlink app.json
    cp ./src/$1/app.json ./app.json
    rsync -rvz ./src/$1/assets/ ./assets/
else
    echo "could not switch project. $1 is invalid"
fi

If you use this approach I'd probably add app.json and all assets in .gitignore.

like image 92
Tim Hysniu Avatar answered Oct 17 '22 10:10

Tim Hysniu