1
1
import 'package:process_run/process_run.dart' ;
2
2
3
+ /// App Store Connect API credentials
4
+ abstract class AppStoreCredentials {}
5
+
6
+ /// User/password credential
7
+ class AppStoreCredentialsUserPassword implements AppStoreCredentials {
8
+ final String username;
9
+ final String password;
10
+
11
+ AppStoreCredentialsUserPassword (
12
+ {required this .username, required this .password});
13
+ }
14
+
15
+ class AppStoreCredentialsApiKeyIssuerId implements AppStoreCredentials {
16
+ final String apiKey;
17
+ final String issuerId;
18
+
19
+ AppStoreCredentialsApiKeyIssuerId (
20
+ {required this .apiKey, required this .issuerId});
21
+ }
22
+
3
23
/// Publisher for App Store Connect API
4
24
class AppStorePublisher {
25
+ /// AppStoreCredentials
26
+ late final AppStoreCredentials credentials;
27
+
5
28
/// App manager issuer id
6
- final String issuerId;
29
+ final String ? issuerId;
7
30
8
31
/// App manager api key
9
- final String apiKey;
32
+ final String ? apiKey;
10
33
11
34
/// Project path
12
35
final String path;
@@ -15,18 +38,36 @@ class AppStorePublisher {
15
38
16
39
/// Create a publisher
17
40
AppStorePublisher (
18
- {required this .issuerId, required this .apiKey, required this .path});
41
+ {AppStoreCredentials ? credentials,
42
+ // Compat
43
+ this .issuerId,
44
+ // Compat
45
+ this .apiKey,
46
+ required this .path}) {
47
+ this .credentials = credentials ??
48
+ AppStoreCredentialsApiKeyIssuerId (apiKey: apiKey! , issuerId: issuerId! );
49
+ }
50
+
51
+ String _credentialsArgs () {
52
+ var credentials = this .credentials;
53
+ if (credentials is AppStoreCredentialsUserPassword ) {
54
+ return ' -u ${shellArgument (credentials .username )} -p ${shellArgument (credentials .password )}' ;
55
+ } else if (credentials is AppStoreCredentialsApiKeyIssuerId ) {
56
+ return ' --apiKey ${shellArgument (credentials .apiKey )} --apiIssuer ${shellArgument (credentials .issuerId )}' ;
57
+ }
58
+ throw UnsupportedError ('Unsupported credentials' );
59
+ }
19
60
20
61
/// Typically in build/ios/ipa/xxx.ipa
21
62
Future <void > validateIosApp ({required String ipaPath}) async {
22
63
await _shell.run (
23
- 'xcrun altool --validate-app -f ${shellArgument (ipaPath )} -t ios --apiKey $ apiKey --apiIssuer $ issuerId ' );
64
+ 'xcrun altool --validate-app -f ${shellArgument (ipaPath )} -t ios${ _credentialsArgs ()} ' );
24
65
}
25
66
26
67
/// Upload ios app to TestFlight.
27
68
Future <void > uploadIosApp ({required String ipaPath}) async {
28
69
await _shell.run (
29
- 'xcrun altool --upload-app -f ${shellArgument (ipaPath )} -t ios --apiKey $ apiKey --apiIssuer $ issuerId ' );
70
+ 'xcrun altool --upload-app -f ${shellArgument (ipaPath )} -t ios${ _credentialsArgs ()} ' );
30
71
}
31
72
32
73
/// Validate and upload ios app to TestFlight.
0 commit comments