diff options
| author | mo khan <mo@mokhan.ca> | 2016-12-24 13:56:21 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2016-12-24 13:56:21 -0700 |
| commit | 9832f776b4d44d03dd95e8c04663fe0032bb68d1 (patch) | |
| tree | 0f528de95238129274026125990e3eca42625fae | |
| parent | 2572430001f68fe3e080d31d4b7f1f1231be5b04 (diff) | |
use babel plugin to export ENV variables.
| -rw-r--r-- | .babelrc | 5 | ||||
| -rw-r--r-- | app/infrastructure/configuration.js | 13 | ||||
| -rw-r--r-- | app/screens/login-screen.js | 31 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | yarn.lock | 6 |
5 files changed, 21 insertions, 35 deletions
@@ -1,3 +1,4 @@ { -"presets": ["react-native"] -}
\ No newline at end of file +"presets": ["react-native"], +"plugins": ["transform-inline-environment-variables"] +} diff --git a/app/infrastructure/configuration.js b/app/infrastructure/configuration.js index 21bb037..03b8600 100644 --- a/app/infrastructure/configuration.js +++ b/app/infrastructure/configuration.js @@ -1,11 +1,11 @@ -import Config from 'react-native-config'; - -var _configuration = { +var _defaults = { development: { - API_HOST: 'http://localhost:3000' + API_HOST: 'http://localhost:3000', + ENV: 'development' }, production: { - API_HOST: 'https://www.stronglifters.com' + API_HOST: 'https://www.stronglifters.com', + ENV: 'production' } }; @@ -15,7 +15,6 @@ export default class Configuration { } value_for(key) { - //return Config[key]; - return _configuration[this.environment][key]; + return process.env[key] || _defaults[this.environment][key]; } } diff --git a/app/screens/login-screen.js b/app/screens/login-screen.js index 450ae4c..59bdc8e 100644 --- a/app/screens/login-screen.js +++ b/app/screens/login-screen.js @@ -1,10 +1,11 @@ import React from 'react'; -import { View, Button, StyleSheet } from 'react-native'; +import { View, Button, Text } from 'react-native'; import { Container, Header, Title, Content, Spinner } from 'native-base'; import Account from '../domain/account' import Api from '../infrastructure/api' import DashboardScreen from './dashboard-screen' import ApplicationComponent from '../components/application-component' +import Configuration from '../infrastructure/configuration' import * as events from '../services/events'; var t = require('tcomb-form-native'); @@ -13,6 +14,7 @@ var Form = t.form.Form; export default class LoginScreen extends ApplicationComponent { constructor(props) { super(props) + this.configuration = new Configuration('development'); this.state = { account: { username: 'mokha', password: 'password' }, eventsOfInterest: [events.LOGGED_IN], @@ -28,7 +30,7 @@ export default class LoginScreen extends ApplicationComponent { return ( <Container> <Header> - <Title>StrongLifters</Title> + <Title>StrongLifters ({this.configuration.value_for('ENV')})</Title> </Header> {this.content()} </Container> @@ -53,6 +55,7 @@ export default class LoginScreen extends ApplicationComponent { options={this.formOptions()} /> <Button onPress={this.onLogin.bind(this)} title="Login" /> + <Text>{this.configuration.value_for('API_HOST')}</Text> </Content> ); } @@ -86,27 +89,3 @@ export default class LoginScreen extends ApplicationComponent { }); } } - -const styles = StyleSheet.create({ - container: { - justifyContent: 'center', - marginTop: 50, - padding: 20, - backgroundColor: '#ffffff', - }, - buttonText: { - fontSize: 18, - color: 'white', - alignSelf: 'center' - }, - button: { - height: 36, - backgroundColor: '#48bbec', - borderColor: '#48bbed', - borderWidth: 1, - borderRadius: 8, - marginBottom: 10, - alignSelf: 'stretch', - justifyContent: 'center' - } -}); diff --git a/package.json b/package.json index 2fb901e..28ef18c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "devDependencies": { "babel-jest": "18.0.0", + "babel-plugin-transform-inline-environment-variables": "^6.8.0", "babel-preset-react-native": "1.9.1", "jest": "18.0.0", "react-test-renderer": "15.4.1" @@ -538,6 +538,12 @@ babel-plugin-transform-flow-strip-types@^6.18.0, babel-plugin-transform-flow-str babel-plugin-syntax-flow "^6.18.0" babel-runtime "^6.0.0" +babel-plugin-transform-inline-environment-variables@^6.8.0: + version "6.8.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-environment-variables/-/babel-plugin-transform-inline-environment-variables-6.8.0.tgz#fc91dd08127dc6c2abdfd1721b11e9602a69ba10" + dependencies: + babel-runtime "^6.0.0" + babel-plugin-transform-object-assign@^6.5.0: version "6.8.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-assign/-/babel-plugin-transform-object-assign-6.8.0.tgz#76e17f2dc0f36f14f548b9afd7aaef58d29ebb75" |
