Owner: Maxime Sraïki
- Generate a new React Native Project using rn-generator-toolbox
- Have all of your styles (at least the colors) in a centralized appstyle.js file
- Have your colors named in an agnostic way (primary > myClientBlue)
- Use a centralized translations file with all the labels of your application
- Have a centralized folder for your assets named in an agnostic way
- Create a
white-labelfolder at the root of your project (10 sec) - Create
binsubfolder inwhite-label, it will host all of your white-label scripts (10 sec) - Create
libsubfolder inbin, it will host the logic called by your scripts (10 sec) - Create
configsubfolder inwhite-label, it will host all of your brand specific files, create a folder for all your brands in this folder (10 sec)
- Go in
white-label/bin/liband create aconfigs.jsfile like this:
const path = require('path');
const fs = require('fs');
const configDir = path.join(__dirname, '../../config');
function getConfigList() {
const files = fs.readdirSync(configDir);
return files.map(file => file.replace('.js', ''));
}
module.exports = {
configDir,
getConfigList
};it will allow you to list the different available configs
-
Create two new files
bin/appStyle.jsandbin/lib/appStyle.jsand build them as they are built here: -
Check what happens in these files, they offer you two method, save and restore:
- save will take the files in your
/srcfolder and copy them towhite-label/config/{{yourAwesomeBrand}} - restore will take the files in your
white-label/config/{{yourAwesomeBrand}}folder and copy them to/src
- save will take the files in your
-
Add a script to your package.json that will allow you to call your brand new white-label script:
"save:appStyle:{{YourAwesomeBrand}}": "./white-label/bin/appStyle.js save {{YourAwesomeBrand}}"- Test the save by running
yarn save:appStyle:{{YourAwesomeBrand}}You should see a new file appStyle.js in your white-label/config/{{YourAwesomeBrand}} folder that is identic to the one you had in /src
- Test the restore by modifying the
white-label/config/{{}YourAwesomeBrand}}/appStyle.jsand by running
yarn restore:appStyle:{{YourAwesomeBrand}}Your should see the /src/appStyle.js modified the same way you modified the one in your brand specific folder.
Now to develop on a specific brand you should always follow this workflow:
- Run
yarn restore:appStyle:{{YourAwesomeBrand}}- Do a commit to have a clean git status
git add .
git commit -m "Restoring {{YourAwesomeBrand}}"-
Code your feature
-
Save your newly modified brand specific configuration by running:
yarn save:appStyle:{{YourAwesomeBrand}}-
Do a commit to save your changes
-
Restore the default configuration
yarn restore:appStyle:{{YourAwesomeDefaultBrand}}- Do a commit
git add .
git commit -m "Restoring {{YourAwesomeDefaultBrand}}"