Dependency installation and usage
Introduction
This page covers the installation and usage of client-specific dependencies for the OCB without affecting the existing functionality.
There are 2 types of dependency:
Generic (common for all the application clients)
Client-specific
For each client-specific dependency, we are creating mock files. When the client-specific dependency is imported in any of the components, we have to keep one condition check for each functionality use, so that it will not break if we don't install actually dependency.
Installation commands
To install dependencies for Windows, use this command:
yarn installPackages
To install dependencies with a valid client for Windows, use this command:
yarn installPackages client=<client name>
To install dependencies for iOS, use this command:
sudo yarn installPackages
To install dependencies with a valid client for iOS, use this command:
sudo yarn installPackages client=<client name>
Parameters
Client is an optional parameter. If no client name is added for this parameter, it will default to install dependencies from package.json and also the mock modules from dependencies.json (scripts/appBuild/dependencies.json).
If a valid client name is added, it will install generic dependencies together with client-specific dependencies.
Adding dependencies
To add a dependency, use this command.
yarn addPackage client=<client name> <dependencies name separated by space>
Examples
Here client parameter is missing so the module will be considered generic and it will install the ramda module and update the package.json file. If any module is already installed in any client with the same name, it will automatically be removed from the client.
/**
* Adding new generic dependencies for windows
*/
yarn addPackage ramda
Here the client is provided so the module is considered as client-specific and it will install the module and update scripts/appBuild/dependencies.json. Also for each client-specific module, mock files will be created under the optional-dependencies directory.
/**
* Adding new client-specific dependencies with version for IOS
*/
sudo yarn addPackage client=customer1 [email protected]
Removing dependencies command
To delete a dependency, use this command.
yarn delPackage client=<client name> <dependencies name separated by space>
Examples
Here client parameter is missing so the module will be considered generic and it will remove the ramda module and update the package.json file.
/**
* Removing the generic dependencies
*/
yarn delPackage ramda
Here the client is provided so the module is considered as client-specific and it will remove the module and update scripts/appBuild/dependencies.json. Also for each client-specific module, mock files will be removed under the optional-dependencies directory.
/**
* Removing the client-specific dependencies IOS
*/
sudo yarn delPackage client=customer1 ramda
Configuration file
{
"customer1": {
},
"optionalDependencies": {
}
}
Check before using client-specific dependencies
Client-specific dependencies from any components must be validated to check whether they are mock dependencies or actual dependencies.
Here is an example of validating the dependency:
import isNumber from "is-number"; // importing Client specific dependency
import { isMockDependency } from "src/store/utils/utils"; //method for validating the client specific dependency.
Before using any functionalities isNumber we have to validate it as follows.
!isMockDependency(isNumber)&&isNumber(1234);