1// Copyright 2015-present 650 Industries. All rights reserved.
2
3#import "EXBuildConstants.h"
4
5@implementation EXBuildConstants
6
7+ (instancetype)sharedInstance
8{
9  static EXBuildConstants *theBuildConstants;
10  static dispatch_once_t once;
11  dispatch_once(&once, ^{
12    if (!theBuildConstants) {
13      theBuildConstants = [[EXBuildConstants alloc] init];
14    }
15  });
16  return theBuildConstants;
17}
18
19- (instancetype)init
20{
21  if (self = [super init]) {
22    [self _loadConfig];
23  }
24  return self;
25}
26
27#pragma mark - internal
28
29- (void)_reset
30{
31  _expoRuntimeVersion = @"";
32}
33
34- (void)_loadConfig
35{
36  [self _reset];
37
38  NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"EXBuildConstants" ofType:@"plist"];
39  NSDictionary *config = (plistPath) ? [NSDictionary dictionaryWithContentsOfFile:plistPath] : [NSDictionary dictionary];
40  _isDevKernel = [config[@"IS_DEV_KERNEL"] boolValue];
41  _kernelDevManifestSource = [[self class] _kernelManifestSourceFromString:config[@"DEV_KERNEL_SOURCE"]];
42  if (_kernelDevManifestSource == kEXKernelDevManifestSourceLocal) {
43    // local kernel. use manifest and assetRequestHeaders from local server.
44    _kernelManifestAndAssetRequestHeadersJsonString = config[@"BUILD_MACHINE_KERNEL_MANIFEST"];
45  } else if (_kernelDevManifestSource == kEXKernelDevManifestSourcePublished) {
46    // dev published kernel. use published manifest and assetRequestHeaders.
47    _kernelManifestAndAssetRequestHeadersJsonString = config[@"DEV_PUBLISHED_KERNEL_MANIFEST"];
48  }
49  _apiServerEndpoint = [NSURL URLWithString:config[@"API_SERVER_ENDPOINT"]];
50  _temporarySdkVersion = config[@"TEMPORARY_SDK_VERSION"];
51  if (config[@"EXPO_RUNTIME_VERSION"]) {
52    _expoRuntimeVersion = config[@"EXPO_RUNTIME_VERSION"];
53  }
54  if (config[@"DEFAULT_API_KEYS"]) {
55    _defaultApiKeys = config[@"DEFAULT_API_KEYS"];
56  }
57  _expoKitDevelopmentUrl = config[@"developmentUrl"]; // TODO: make legacy name consistent with the rest of this file
58}
59
60+ (EXKernelDevManifestSource)_kernelManifestSourceFromString:(NSString *)sourceString
61{
62  if ([sourceString isEqualToString:@"LOCAL"]) {
63    return kEXKernelDevManifestSourceLocal;
64  } else if ([sourceString isEqualToString:@"PUBLISHED"]) {
65    return kEXKernelDevManifestSourcePublished;
66  }
67  return kEXKernelDevManifestSourceNone;
68}
69
70@end
71