Maintain multiple variant of a mobile app in single git repo | Mono-repo

1 Min. Read
Jan 26, 2021

 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


Hidden View Helper Methods In Rails 

ShivaShiva Bhusal (Software Engineer) 2 Min. Read Oct 1, 2019
 rails ruby views helpers

There are a lot of Rails view helper methods that are still unknown to most of the Rails developers. They are undocumented in the Rails guide but have good explanation in API Doc though.
Read More..

Learn the awesome language Dart for Desktop, Mobile app development in just one day. You must have working knowledge of any language first.
Read More..

Find all the Provinces with districts with all Municipalities in Nepal.
Read More..

The purpose of this library is to combine features of `google map` such as map, marker and corresponding info window rendering to a single API call. This simplifies implementing google map into your project while not having to remember all the associated API calls provided by it. Just include the script tag into your project and initialize and object of `ideaMap` class with appropriate parameters while rendering the map. While instantiating the `ideaMap` class, there are certain parameters that you need to pass according to your requirement. Let’s go over them, Here, we’ve passed in an object while initializing the map.
Read More..



Write To Me

Hire me shiva bhusal
We'll never share your email with anyone else.
I'll never share your email with anyone else.