This repository was archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Write white label MO for react-native #137
Open
sraikimaxime
wants to merge
1
commit into
master
Choose a base branch
from
white-label-implementation-mo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env node | ||
|
||
const program = require('commander'); | ||
require('colors'); | ||
const shippingConfigs = require('./lib/Configs'); | ||
const serviceAgent = require('./lib/appStyle.js'); | ||
|
||
let commandValid = false; | ||
const configs = shippingConfigs.getConfigList(); | ||
|
||
function checkCommandValid(config) { | ||
commandValid = configs.indexOf(config) !== -1; | ||
return commandValid; | ||
} | ||
|
||
program | ||
.version(require('../../../YourAwesomeProject/package').version) | ||
.description('Save and restore appStyle.'); | ||
|
||
program | ||
.command('save <config>') | ||
.alias('s') | ||
.description('Save the appStyle for a shipping config.') | ||
.action(config => { | ||
if (!checkCommandValid(config)) { | ||
return; | ||
} | ||
serviceAgent.saveAppStyle(config); | ||
}); | ||
|
||
program | ||
.command('restore <config>') | ||
.alias('r') | ||
.description('Save the appStyle from a shipping config.') | ||
.action(config => { | ||
if (!checkCommandValid(config)) { | ||
return; | ||
} | ||
serviceAgent.restoreAppStyle(config); | ||
}); | ||
|
||
program.on('--help', () => { | ||
console.log(''); | ||
console.log(' Available shipping config : '); | ||
console.log(''); | ||
|
||
configs.forEach(config => { | ||
console.log(`\t - ${config}`); | ||
}); | ||
}); | ||
|
||
program.parse(process.argv); | ||
|
||
if (!commandValid) { | ||
program.help(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
require('colors'); | ||
const shippingConfigs = require('./configs'); | ||
|
||
const appStylePath = path.join(__dirname, '../../../../YourAweSomeProject/src/appStyle.js'); | ||
const destDirName = shippingConfigs.configDir; | ||
|
||
function copyAppStyle(config, saving) { | ||
const savePath = path.join(destDirName, config, 'appStyle/appStyle.js'); | ||
const restorePath = appStylePath; | ||
|
||
const destFile = saving ? savePath : restorePath; | ||
const initialFile = saving ? restorePath : savePath; | ||
|
||
return new Promise((resolve, reject) => { | ||
try { | ||
console.log('Copying the appStyle'); | ||
fs.createReadStream(initialFile).pipe(fs.createWriteStream(destFile)); | ||
} catch (e) { | ||
console.log('Error copying the appStyle'.red); | ||
reject(e); | ||
} | ||
|
||
const verb = saving ? 'saved' : 'restored'; | ||
console.log(`AppStyle successfully ${verb}`.green); | ||
resolve(); | ||
}); | ||
} | ||
|
||
function saveAppStyle(config) { | ||
console.log(''); | ||
console.log(`Saving the appStyle for config ${config}`.yellow); | ||
|
||
const destDir = path.join(destDirName, config); | ||
|
||
if (!fs.existsSync(destDir)) { | ||
try { | ||
fs.mkdirSync(destDir); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
if (!fs.existsSync(path.join(destDir, 'appStyle'))) { | ||
try { | ||
fs.mkdirSync(path.join(destDir, 'appStyle')); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
|
||
return copyAppStyle(config, true); | ||
} | ||
|
||
function restoreAppStyle(config) { | ||
console.log(''); | ||
console.log(`Restoring the appStyle for config ${config}`.yellow); | ||
|
||
return copyAppStyle(config, false); | ||
} | ||
|
||
module.exports = { | ||
saveAppStyle, | ||
restoreAppStyle | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# [MO] How to implement white-label on a nodeJS server _(~<Time> 5)_ | ||
|
||
## Owner: [Maxime Sraïki](https://github.com/sraikimaxime) | ||
|
||
## Prerequisites _(~<Time> min)_ | ||
|
||
## Steps _(~<Time> min)_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# [MO] How to implement white-label on a React Native app _(~<Time> min)_ | ||
|
||
## Owner: [Maxime Sraïki](https://github.com/sraikimaxime) | ||
|
||
## Prerequisites | ||
|
||
- 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me it's not clear which one I should choose. For example should I choose "primary" or "deepBlue" or "BAMBlue"? |
||
- Use a centralized translations file with all the labels of your application | ||
- Have a centralized folder for your assets named in an agnostic way | ||
|
||
## Steps _(~<Time> min)_ | ||
|
||
### Step 1: Create the white-label folder _(40 sec)_ | ||
|
||
- Create a `white-label` folder at the root of your project _(10 sec)_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- Create `bin` subfolder in `white-label`, it will host all of your white-label scripts _(10 sec)_ | ||
- Create `lib` subfolder in `bin`, it will host the logic called by your scripts _(10 sec)_ | ||
- Create `config` subfolder in `white-label`, it will host all of your brand specific files, create a folder for all your brands in this folder _(10 sec)_ | ||
|
||
### Step 2: Create your first script to make appStyle brand specific _(15 min)_ | ||
|
||
- Go in `white-label/bin/lib` and create a `configs.js` file like this: | ||
|
||
```js | ||
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.js` and `bin/lib/appStyle.js` and 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 `/src` folder and copy them to `white-label/config/{{yourAwesomeBrand}}` | ||
- restore will take the files in your `white-label/config/{{yourAwesomeBrand}}` folder and copy them to `/src` | ||
|
||
- Add a script to your package.json that will allow you to call your brand new white-label script: | ||
|
||
```json | ||
"save:appStyle:{{YourAwesomeBrand}}": "./white-label/bin/appStyle.js save {{YourAwesomeBrand}}" | ||
``` | ||
|
||
### Step 3: Test your script _(5 min)_ | ||
|
||
- Test the save by running | ||
|
||
```sh | ||
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.js` and by running | ||
|
||
```sh | ||
yarn restore:appStyle:{{YourAwesomeBrand}} | ||
``` | ||
|
||
Your should see the `/src/appStyle.js` modified the same way you modified the one in your brand specific folder. | ||
|
||
### Step 4: Dev | ||
|
||
Now to develop on a specific brand you should always follow this workflow: | ||
|
||
- Run | ||
|
||
```sh | ||
yarn restore:appStyle:{{YourAwesomeBrand}} | ||
``` | ||
|
||
- Do a commit to have a clean git status | ||
|
||
```sh | ||
git add . | ||
git commit -m "Restoring {{YourAwesomeBrand}}" | ||
``` | ||
|
||
- Code your feature | ||
|
||
- Save your newly modified brand specific configuration by running: | ||
|
||
```sh | ||
yarn save:appStyle:{{YourAwesomeBrand}} | ||
``` | ||
|
||
- Do a commit to save your changes | ||
|
||
- Restore the default configuration | ||
|
||
```sh | ||
yarn restore:appStyle:{{YourAwesomeDefaultBrand}} | ||
``` | ||
|
||
- Do a commit | ||
|
||
```sh | ||
git add . | ||
git commit -m "Restoring {{YourAwesomeDefaultBrand}}" | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use variables for that, so we don't have to copy the whole file