Skip to content

Commit fa1aeec

Browse files
committed
send build number in environment
1 parent da72fa7 commit fa1aeec

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

App/Mixins/AuthHelper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var Text = require('../Components/Text');
1313
var Button = require('../Components/Button');
1414
var TextInput = require('../Components/TextInput');
1515

16+
var EnvironmentStore = require('../Stores/EnvironmentStore');
17+
1618
var AuthHelper = {
1719

1820
// parent implements: onAuthButton, getDefaultProps
@@ -111,7 +113,7 @@ var AuthHelper = {
111113
<View style={styles.bottom}>
112114
{this.renderPassword()}
113115
<View style={styles.flex} />
114-
<Text style={[styles.bottomText, styles.version]}>TODO: v1</Text>
116+
<Text style={[styles.bottomText, styles.version]}>Version {EnvironmentStore.get().displayVersion()}</Text>
115117
</View>
116118
</View>
117119
)

App/Models/Environment.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var assign = require('../Lib/assignDefined');
2+
var jsVersion = require('../jsVersion');
23

34
var Model = function(options) {
45
this.data = {};
@@ -8,7 +9,11 @@ var Model = function(options) {
89
Model.prototype.setAttributes = function(options) {
910
options = (options || {});
1011
assign(this.data, {
11-
name: options.name
12+
name: options.name,
13+
simulator: options.simulator,
14+
buildCode: parseInt(options.buildCode),
15+
version: options.version,
16+
locale: options.locale
1217
});
1318
};
1419

@@ -18,9 +23,27 @@ Model.prototype.getApiHost = function() {
1823
return 'http://localhost:3001';
1924
case 'debug':
2025
return 'http://localhost:3000';
26+
case 'staging':
27+
return 'https://someday.herokuapp.com';
2128
default:
2229
throw("Unknown Environment.getApiHost: " + this.data.name);
2330
}
2431
};
2532

33+
Model.prototype.combinedBuildCode = function() {
34+
var ios = this.data.buildCode * 1000000;
35+
return ios + jsVersion;
36+
};
37+
38+
Model.prototype.displayVersion = function() {
39+
var out = this.data.version;
40+
out += "." + this.data.buildCode;
41+
out += "." + jsVersion;
42+
return out;
43+
};
44+
45+
Model.prototype.getLocale = function() {
46+
return this.data.locale;
47+
};
48+
2649
module.exports = Model;

App/Screens/Settings.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
var React = require('react-native');
22
var {
33
View,
4-
StyleSheet
4+
StyleSheet,
5+
Text
56
} = React;
67

8+
var cssVar = require('../Lib/cssVar');
9+
710
var SimpleList = require('../Components/SimpleList');
811
var AppConstants = require('../Constants/AppConstants');
912

13+
var EnvironmentStore = require('../Stores/EnvironmentStore');
14+
1015
function getListState() {
1116
var list = [];
1217
list.push({
@@ -28,6 +33,9 @@ var Settings = React.createClass({
2833
return (
2934
<View style={styles.container}>
3035
<SimpleList currentRoute={this.props.currentRoute} items={this.state.items} />
36+
<View style={styles.bottom}>
37+
<Text style={styles.bottomText}>Version {EnvironmentStore.get().displayVersion()}</Text>
38+
</View>
3139
</View>
3240
)
3341
}
@@ -36,7 +44,12 @@ var Settings = React.createClass({
3644
var styles = StyleSheet.create({
3745
container: {
3846
flex: 1
39-
}
47+
},
48+
bottomText: {
49+
padding: 10,
50+
color: cssVar('gray20'),
51+
fontSize: 12
52+
},
4053
});
4154

4255
module.exports = Settings;

App/Stores/EnvironmentStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ var SingletonStore = assign({}, EventEmitter.prototype, {
3838
Dispatcher.register(function(action) {
3939
switch(action.actionType) {
4040
case AppConstants.APP_LAUNCHED:
41-
EnvironmentManager.get(function(name) {
42-
console.log("Environment: " + name);
43-
setSingleton({name: name});
41+
EnvironmentManager.get(function(attributes) {
42+
console.log("Environment: " + attributes.name);
43+
setSingleton(attributes);
4444
SingletonStore.emitChange();
4545
});
4646
break;

App/jsVersion.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 2;

ios/Sample/EnvironmentManager.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ @implementation EnvironmentManager
1616

1717
RCT_EXPORT_METHOD(get:(RCTResponseSenderBlock)callback)
1818
{
19-
//TODO: NSString * envName = kEnvironment;
20-
NSString * envName = @"debug";
19+
NSString *locale = [[NSLocale currentLocale] localeIdentifier];
20+
locale = [locale stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
21+
22+
NSNumber * simulator = @NO;
23+
NSString * version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
24+
NSString * buildCode = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
25+
26+
NSString * envName = kEnvironment;
2127
NSDictionary *passed = [[NSProcessInfo processInfo] environment];
2228
NSString *override = [passed valueForKey:@"SAMPLE_ENV"];
2329
if (override) {
@@ -26,7 +32,22 @@ @implementation EnvironmentManager
2632
#ifdef TEST_ENVIRONMENT
2733
envName = @"test";
2834
#endif
29-
callback(@[envName]);
35+
#ifdef STAGING_ENVIRONMENT
36+
envName = @"staging";
37+
#endif
38+
39+
40+
#if TARGET_IPHONE_SIMULATOR
41+
simulator = @YES;
42+
#endif
43+
44+
callback(@[ @{
45+
@"name": envName,
46+
@"buildCode": buildCode,
47+
@"simulator": simulator,
48+
@"version": version,
49+
@"locale": locale
50+
}]);
3051
}
3152

3253
@end

0 commit comments

Comments
 (0)