-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathcapacitor.config.ts
109 lines (98 loc) · 3.59 KB
/
capacitor.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
import type { CapacitorConfig } from '@capacitor/cli';
import { argv, env } from 'process';
type Platform = 'android' | 'ios';
const PlatformOverrideEnvVariable = 'CAPACITOR_PLATFORM_OVERRIDE';
const validatePlatformString: (
platformString: string,
) => Platform | undefined = (platformString) => {
switch (platformString) {
case 'android':
return 'android';
case 'ios':
return 'ios';
default:
return undefined;
}
};
const getPlatform: () => Platform = () => {
/* This is slightly hacky, but it is build-time configuration and we can
* just fail if something unexpected happens.
* See https://github.com/ionic-team/capacitor/discussions/4173
*
* https://github.com/ionic-team/capacitor/issues/3976 would be a much better
* solution if it is ever implemented, but for now this has to suffice.
*/
const platformFromEnv = validatePlatformString(
env[PlatformOverrideEnvVariable],
);
if (platformFromEnv) {
return platformFromEnv;
}
const platformFromArgv = validatePlatformString(process.argv[3]);
if (platformFromArgv) {
return platformFromArgv;
}
const errorMessage =
'==================================================================\n' +
'Cannot determine platform from environment or arguments.\n' +
`${PlatformOverrideEnvVariable} = '${env[PlatformOverrideEnvVariable]}'; ` +
`argv[3]='${argv[3]}'\n\n` +
'Please run platform configuration seperately, for example ' +
'"npm run cap sync android" and "npm run cap sync ios" ' +
'instead of just "npm run cap sync".\n' +
'If you just want to sync all platforms, run "npm run capsync" as a ' +
'convenient shorcut.\n' +
'If you really need to, you can override the platform using the ' +
`environment variable ${PlatformOverrideEnvVariable}\n` +
'==================================================================\n';
console.error(errorMessage);
throw new Error('\n' + errorMessage);
};
const createConfig = () => {
const config: CapacitorConfig = {
appId: 'com.beanconqueror.app',
appName: 'Beanconqueror',
webDir: 'www',
loggingBehavior: 'none',
zoomEnabled: false,
server: {
// Will be set in platform section below
},
ios: {
// Will be set in platform section below
},
plugins: {
CapacitorHttp: {
// Enabling this will patch fetch() to use CapacitorHttp instead of the
// native fetch() in the WebView. This is required as functionality
// such as mulipart file upload is only available using the patched
// fetch() API and is not available using the CapacitorHttp API.
// See https://capacitorjs.com/docs/apis/http#configuration
enabled: true,
},
SplashScreen: {
launchAutoHide: false, // we will hide the splashcreen inside the app
backgroundColor: '#FFFFFF',
androidScaleType: 'CENTER_CROP',
useDialog: false, // required to set the correct scale type
},
},
};
switch (getPlatform()) {
case 'android':
// Using this hostname and scheme is required to retain access
// to the __baristaDB on Android when updating from Cordova builds
config.server.hostname = 'beanconqueror.com';
config.server.androidScheme = 'https';
break;
case 'ios':
// Using this hostname and scheme is required to retain access
// to the __baristaDB on iOS when updating from Cordova builds
config.server.hostname = 'localhost';
config.server.iosScheme = 'ionic';
break;
}
return config;
};
const config: CapacitorConfig = createConfig();
export default config;