-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.config.ts
366 lines (344 loc) · 10.1 KB
/
app.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import { Environment, Flavor } from '@appjusto/types';
import { ConfigContext, ExpoConfig } from '@expo/config';
import 'dotenv/config';
import { withBuildProperties } from 'expo-build-properties';
import { isEmpty } from 'lodash';
import { Extra } from './config/types';
import { version, versionCode } from './version.json';
const {
FLAVOR,
ENVIRONMENT,
EXPO_BUSINESS_ID,
EXPO_CONSUMER_ID,
EXPO_COURIER_ID,
FACEBOOK_CONSUMER_APP_ID,
FACEBOOK_CONSUMER_CLIENT_TOKEN,
FACEBOOK_COURIER_APP_ID,
FACEBOOK_COURIER_CLIENT_TOKEN,
FACEBOOK_BUSINESS_APP_ID,
FACEBOOK_BUSINESS_CLIENT_TOKEN,
FIREBASE_API_KEY_ANDROID,
FIREBASE_API_KEY_IOS,
FIREBASE_REGION,
FIREBASE_PROJECT_ID,
FIREBASE_MESSAGING_SENDER_ID,
FIREBASE_CONSUMER_APP_ID,
FIREBASE_COURIER_APP_ID,
FIREBASE_BUSINESS_APP_ID,
FIREBASE_EMULATOR_HOST,
SEGMENT_CONSUMER_IOS_KEY,
SEGMENT_CONSUMER_ANDROID_KEY,
SEGMENT_COURIER_IOS_KEY,
SEGMENT_COURIER_ANDROID_KEY,
SENTRY_DSN,
IUGU_ACCOUNT_ID,
ALGOLIA_APPID,
ALGOLIA_APIKEY,
SENTRY_AUTH_TOKEN,
} = process.env;
const flavor: Flavor = FLAVOR as Flavor;
const environment: Environment = ENVIRONMENT as Environment;
const getBaseDomain = (environment: Environment) =>
`${environment === 'live' ? '' : `${environment}.`}appjusto.com.br`;
const getDeeplinkDomain = (environment: Environment) =>
`${environment.charAt(0)}.deeplink.appjusto.com.br`;
const getFallbackDomain = (environment: Environment) =>
`${environment === 'live' ? '' : `${environment}.`}login.appjusto.com.br`;
const expoId = () => {
if (FLAVOR === 'consumer') return EXPO_CONSUMER_ID!;
if (FLAVOR === 'courier') return EXPO_COURIER_ID!;
if (FLAVOR === 'business') return EXPO_BUSINESS_ID!;
throw new Error('FLAVOR inválido');
};
const scheme = () => {
const scheme = flavor === 'consumer' ? 'appjusto' : 'appjusto' + flavor;
if (environment !== 'live') return `${scheme}${environment}`;
return scheme;
};
type Plugins = (string | [] | [string] | [string, unknown] | any)[];
const plugins = (): Plugins => {
let list: Plugins = [
'expo-splash-screen',
'sentry-expo',
'./scripts/react-maps-plugin',
[
'expo-image-picker',
{
photosPermission: 'Para o envio de documentos, caso necessário.',
cameraPermission: 'Para o envio de documentos, caso necessário.',
},
],
[
withBuildProperties,
{
android: {
compileSdkVersion: 33,
targetSdkVersion: 33,
buildToolsVersion: '33.0.1',
enableProguardInReleaseBuilds: false,
// extraProguardRules: '-keep public class com.horcrux.svg.** {*;}',
},
ios: {
useFrameworks: 'static',
},
},
],
// ['react-native-fbsdk-next', facebokConfig()],
// [
// 'expo-tracking-transparency',
// {
// userTrackingPermission:
// 'Usamos esse identificador para medir a conversão dos nossos anúncios.',
// },
// ],
];
if (FLAVOR === 'courier') {
list = [
...list,
[
'expo-notifications',
{
icon: './assets/notification-icon.png',
sounds: ['./assets/sounds/order_request.wav'],
},
],
];
}
return list;
};
export default (context: ConfigContext): ExpoConfig => {
const config: ExpoConfig = {
owner: 'appjusto',
name: name(),
slug: slug(),
scheme: scheme(),
privacy: 'hidden',
platforms: ['ios', 'android'],
version,
orientation: 'portrait',
splash: {
image: './assets/splash.png',
resizeMode: 'cover',
backgroundColor: '#9ce592',
},
notification: {
icon: './assets/notification-icon.png',
},
updates: {
fallbackToCacheTimeout: 1000 * (flavor === 'courier' ? 30 : 5),
},
assetBundlePatterns: ['**/*'],
ios: ios(),
android: android(),
androidStatusBar: {
hidden: true,
},
extra: extra(),
hooks: hooks(),
plugins: plugins(),
};
// console.log(config);
return config;
};
const name = () => {
let name = 'AppJusto';
if (environment === 'live') {
if (flavor === 'consumer') return name;
if (flavor === 'courier') return `${name} Entregador`;
if (flavor === 'business') return `${name} Restaurante`;
}
if (flavor === 'courier') name = 'Entregador';
if (flavor === 'business') name = 'Restaurante';
return `(${environment.charAt(0).toUpperCase()}) ${name}`;
};
const slug = () => {
const slug = `app-justo-${flavor}`;
if (environment !== 'live') return `${slug}-${environment}`;
return slug;
};
const appBundlePackage = () => {
return `br.com.appjusto.${flavor}.${environment}`;
};
const icon = (platform: 'ios' | 'android') => {
return `./assets/icon-${flavor}-${platform}.png`;
};
const facebokConfig = (): object => {
let appID = '';
let clientToken = '';
if (flavor === 'consumer') {
appID = FACEBOOK_CONSUMER_APP_ID!;
clientToken = FACEBOOK_CONSUMER_CLIENT_TOKEN!;
}
if (flavor === 'courier') {
appID = FACEBOOK_COURIER_APP_ID!;
clientToken = FACEBOOK_COURIER_CLIENT_TOKEN!;
}
if (flavor === 'business') {
appID = FACEBOOK_BUSINESS_APP_ID!;
clientToken = FACEBOOK_BUSINESS_CLIENT_TOKEN!;
}
if (isEmpty(appID) || isEmpty(clientToken)) return {};
return {
appID,
scheme: 'fb' + appID,
clientToken,
displayName: 'AppJusto',
advertiserIDCollectionEnabled: true,
autoLogAppEventsEnabled: true,
iosUserTrackingPermission:
'Usamos esse identificador para medir a conversão dos nossos anúncios.',
};
};
const ios = () => ({
bundleIdentifier: appBundlePackage(),
buildNumber: `${versionCode}`,
icon: icon('ios'),
supportsTablet: false,
infoPlist:
flavor === 'business'
? { UIBackgroundModes: ['fetch'] }
: flavor === 'consumer'
? {
NSUserTrackingUsageDescription:
'Usamos esse identificador para medir a conversão dos nossos anúncios.',
NSLocationWhenInUseUsageDescription:
'Precisamos da sua localização para exibir os restaurantes próximos a você',
}
: {
UIBackgroundModes: ['location'],
NSUserTrackingUsageDescription:
'Precisamos da sua localização para enviar corridas próximas e monitorar a entrega.',
NSLocationWhenInUseUsageDescription:
'Precisamos da sua localização para enviar corridas próximas e monitorar a entrega.',
NSLocationAlwaysAndWhenInUseUsageDescription:
'Precisamos da sua localização para enviar corridas próximas e monitorar a entrega.',
},
associatedDomains: [
`applinks:${getBaseDomain(environment)}`,
`applinks:${getDeeplinkDomain(environment)}`,
`applinks:${getFallbackDomain(environment)}`,
],
config: {
googleMapsApiKey: FIREBASE_API_KEY_IOS,
},
});
const intentFilter = (host: string, pathPrefix: string) => ({
action: 'VIEW',
autoVerify: true,
data: [
{
scheme: 'https',
host,
pathPrefix,
},
],
category: ['BROWSABLE', 'DEFAULT'],
});
// looks like intent filters are restrict one per domain
// in case we need more deeplinks we would need to add multiple objects inside data
// TODO: test it with eas
const intentFilters = () =>
[
intentFilter(getDeeplinkDomain(environment), `/${flavor}`),
intentFilter(getFallbackDomain(environment), `/${flavor}`),
]
.concat(flavor === 'consumer' ? [intentFilter(getBaseDomain(environment), `/r`)] : [])
.concat(flavor === 'courier' ? [intentFilter(getBaseDomain(environment), `/f`)] : []);
const android = () =>
((
{
android: {
package: appBundlePackage(),
versionCode,
adaptiveIcon: {
foregroundImage: icon('android'),
backgroundColor:
flavor === 'business' ? '#2F422C' : flavor === 'consumer' ? '#78E08F' : '#FFE493',
},
googleServicesFile: `./google-services-${environment}.json`,
softwareKeyboardLayoutMode: 'pan',
permissions: permissions(),
intentFilters: intentFilters(),
config: {
googleMaps: {
apiKey: FIREBASE_API_KEY_ANDROID,
},
},
},
} as ExpoConfig
).android);
const permissions = () =>
flavor === 'business'
? ['RECEIVE_BOOT_COMPLETED', 'WAKE_LOCK']
: flavor === 'consumer'
? ['ACCESS_FINE_LOCATION', 'ACCESS_COARSE_LOCATION', 'CAMERA', 'CAMERA_ROLL', 'MEDIA_LIBRARY']
: [
'RECEIVE_BOOT_COMPLETED',
'ACCESS_FINE_LOCATION',
'ACCESS_COARSE_LOCATION',
'ACCESS_BACKGROUND_LOCATION',
'CAMERA',
'CAMERA_ROLL',
'MEDIA_LIBRARY',
'READ_EXTERNAL_STORAGE',
'WRITE_EXTERNAL_STORAGE',
'VIBRATE',
// 'RECORD_AUDIO',
];
const extra = (): Extra => ({
flavor,
environment,
bundleIdentifier: appBundlePackage(),
androidPackage: appBundlePackage(),
firebase: {
apiKeyAndroid: FIREBASE_API_KEY_ANDROID!,
apiKeyiOS: FIREBASE_API_KEY_IOS!,
authDomain: `${FIREBASE_PROJECT_ID}.firebaseapp.com`,
region: FIREBASE_REGION!,
projectId: FIREBASE_PROJECT_ID!,
storageBucket:
process.env.FIREBASE_EMULATOR === 'true'
? 'gs://default-bucket'
: `${FIREBASE_PROJECT_ID}.appspot.com`,
messagingSenderId: FIREBASE_MESSAGING_SENDER_ID!,
appId:
flavor === 'consumer'
? FIREBASE_CONSUMER_APP_ID!
: flavor === 'courier'
? FIREBASE_COURIER_APP_ID!
: FIREBASE_BUSINESS_APP_ID!,
emulator: {
enabled: process.env.FIREBASE_EMULATOR === 'true',
host: FIREBASE_EMULATOR_HOST,
},
},
eas: {
projectId: expoId(),
},
analytics: {
segmentConsumerAndroidKey: SEGMENT_CONSUMER_ANDROID_KEY!,
segmentConsumeriOSKey: SEGMENT_CONSUMER_IOS_KEY!,
segmentCourierAndroidKey: SEGMENT_COURIER_ANDROID_KEY!,
segmentCourieriOSKey: SEGMENT_COURIER_IOS_KEY!,
sentryDNS: SENTRY_DSN!,
},
iugu: {
accountId: IUGU_ACCOUNT_ID!,
},
algolia: {
appId: ALGOLIA_APPID!,
apiKey: ALGOLIA_APIKEY!,
},
});
const hooks = () => ({
postPublish: [
{
file: 'sentry-expo/upload-sourcemaps',
config: {
organization: 'app-justo',
project: 'app',
authToken: SENTRY_AUTH_TOKEN,
},
},
],
});