Maintain multiple variant of a mobile app in single git repo | Mono-repo
javascript react react native mono-repo
It is not that difficult to maintain multiple variants of a mobile app you are working on in a single code-base.
Your current project directory structure might look like below
1
2
3
4
5
6
7
8
9
10
11
12
my-app
├── __tests__
├── android
│ ├── app
│ └── gradle
└── ios
├── Pods
├── gig
├── gig.xcodeproj
├── gig.xcworkspace
└── gigTests
Next you need to create a parent folder called my-app-repo
(it can be something else in your case).
Now, move your variants code folders into my-app-repo/packages
which makes your repo look like below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ my-app-repo
.
└── packages
├── myapp-var1
│ ├── __tests__
│ ├── android
│ │ ├── app
│ │ └── gradle
│ └── ios
│ ├── Pods
│ ├── gig
│ ├── gig.xcodeproj
│ ├── gig.xcworkspace
│ └── gigTests
└── myapp-var2
├── __tests__
├── android
│ ├── app
│ └── gradle
└── ios
├── Pods
├── gig_partner
├── gig_partner.xcodeproj
├── gig_partner.xcworkspace
└── gig_partnerTests
Next, you need to make this folder a js package.
1
$ yarn init my-app-repo
this will create package.json
file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// package.json
{
"private": true,
"dependencies": {
"react-devtools": "^4.10.1",
"react-native": "^0.64.2"
},
"scripts": {
"..": ".."
},
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": []
}
}
What we are basically doing is adding concept of workspaces
. You can now delegate commands to specific packages.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
,"scripts": {
"var1-android": "yarn workspace var1 android",
"var1-ios": "yarn workspace var1 ios",
"var1-start": "yarn workspace var1 start",
"var1-test": "yarn workspace var1 jest",
"var1-lint": "yarn workspace var1 eslint .",
"var1-podinstall": "yarn workspace var1 podinstall",
"var2-android": "yarn workspace var2 android",
"var2-ios": "yarn workspace var2 ios",
"var2-start": "yarn workspace var2 start",
"var2-test": "yarn workspace var2 jest",
"var2-lint": "yarn workspace var2 eslint ."
}
Configure Podfiles
Now you might need to replace a couple of lines of code
1
2
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
1
2
require_relative '../../../node_modules/react-native/scripts/react_native_pods'
require_relative '../../../node_modules/@react-native-community/cli-platform-ios/native_modules'
Install packages
Simply yarn install
will install all underlying packages
You might also like
Maintain Multiple Variant Of A Mobile App In Single Git Repo | Mono Repo
Shiva Bhusal (Software Engineer) 1 Min. Read Jan 26, 2021
javascript react react native mono-repo
Hidden View Helper Methods In Rails
Shiva Bhusal (Software Engineer) 2 Min. Read Oct 1, 2019
rails ruby views helpers
Read More..
Learn Dart Language In One Day
Shiva Bhusal (Software Engineer) 2 Min. Read Sep 4, 2019
Build Mob App Android iOS Dart Flutter Introduction
Read More..
List Of All Municipalities By Districts By Provinces Of Nepal
Shiva Bhusal (Software Engineer) 22 Min. Read Sep 2, 2019
Data Ruby Hash Nepal Districts Municipalities Province
Read More..
Easily Integrate Maps In Your Projects
Shiva Bhusal (Software Engineer) 4 Min. Read Aug 12, 2019
JS Javascript Google Map Open Street Map NPM Nodejs Plugins
Read More..
Read More..