Skip to content

Commit

Permalink
YOMA-228 - chore: create env variable flow (#10)
Browse files Browse the repository at this point in the history
* chore: adding env creation and adding yoma api url to env and implementing in app

* chore: updating help.js with env:dev and env:test descriptions

* chore: removing testing on push now that circleci is setup
  • Loading branch information
cameronolivier authored Apr 12, 2021
1 parent 7aec8f6 commit 639e775
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
steps:
- checkout
- node/install-packages
- run: npm run env:test
- run: npm run code:lint
- run:
name: Unit Tests
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ buck-out/


.xgitconfig
src/env.json

android/java_pid843420.hprof
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
['transform-inline-environment-variables'],
[
'module-resolver',
{
Expand All @@ -17,4 +18,4 @@ module.exports = {
},
],
],
};
};
1 change: 1 addition & 0 deletions env/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions env/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"YOMA_API_BASE_PATH": "https://staging.api.yoma.africa/api/v1/"
}
20 changes: 20 additions & 0 deletions env/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs')
const R = require('ramda')

// get environment to generate from supplied argument:
const env = process.argv[2]
if (!env) {
console.error('\x1b[31m', 'No environment supplied!')
console.log('\x1b[33m', 'Please set an environment variable and try again')
process.exit(1)
}
// get the correct env file
const commonSettings = require('./common.json')
const envSettings = require(`./${env}.json`)

// generate settings object
const settings = R.mergeDeepRight(commonSettings, envSettings)

// create the env.json file in src from both files
fs.writeFileSync('src/env.json', JSON.stringify(settings, undefined, 2))
console.log('\x1b[32m', 'Success! env.json has been generated.')
3 changes: 3 additions & 0 deletions env/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"YOMA_API_BASE_PATH": "https://staging.api.yoma.africa/api/v1/"
}
2 changes: 2 additions & 0 deletions help.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"env:dev": "generate environment file (env.json) with dev variables",
"env:test": "generate environment file (env.json) with test variables (for use by circleci primarily)",
"init": "initialize package",
"init:ios": "init app for ios",
"ios": "serve app on ios simulator",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"private": true,
"scripts": {
"_git:pre-commit": "pretty-quick --staged",
"_git:pre-push": "npm-run-all code:lint _remove_on_ci_setup",
"_remove_on_ci_setup": "npm run test",
"_git:pre-push": "npm-run-all code:lint",
"env:dev": "node env/generate.js dev",
"env:test": "node env/generate.js test",
"init:ios": "npx pod-install",
"init": "npm-run-all env:dev init:ios",
"android": "react-native run-android",
Expand Down
4 changes: 2 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import axios from 'axios'

import Env from '../env.json'
import auth from './auth'
import users from './users'

const FALLBACK_MESSAGE = 'Unable to reach server'
const REFRESH_TOKEN_FAILED_MESSAGE = 'Unable to refresh your session'
const UNAUTHORIZED_STATUS_CODE = 401
const BASE_URL = 'https://staging.api.yoma.africa/api/v1/'

const instance = axios.create({
baseURL: BASE_URL,
baseURL: Env.YOMA_API_BASE_PATH,
headers: {
'Content-Type': 'application/json',
},
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"baseUrl": "./src"
"baseUrl": "./src",
"resolveJsonModule": true
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}

0 comments on commit 639e775

Please sign in to comment.