Skip to content

Commit 9b9a354

Browse files
committed
feat add appstore credentials
1 parent 826a88f commit 9b9a354

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
library;
22

3-
export 'src/appstore_publisher.dart' show AppStorePublisher;
3+
export 'src/appstore_publisher.dart'
4+
show
5+
AppStorePublisher,
6+
AppStoreCredentials,
7+
AppStoreCredentialsApiKeyIssuerId,
8+
AppStoreCredentialsUserPassword;

packages/appstore_publish/lib/src/appstore_publisher.dart

+46-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
import 'package:process_run/process_run.dart';
22

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+
323
/// Publisher for App Store Connect API
424
class AppStorePublisher {
25+
/// AppStoreCredentials
26+
late final AppStoreCredentials credentials;
27+
528
/// App manager issuer id
6-
final String issuerId;
29+
final String? issuerId;
730

831
/// App manager api key
9-
final String apiKey;
32+
final String? apiKey;
1033

1134
/// Project path
1235
final String path;
@@ -15,18 +38,36 @@ class AppStorePublisher {
1538

1639
/// Create a publisher
1740
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+
}
1960

2061
/// Typically in build/ios/ipa/xxx.ipa
2162
Future<void> validateIosApp({required String ipaPath}) async {
2263
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()}');
2465
}
2566

2667
/// Upload ios app to TestFlight.
2768
Future<void> uploadIosApp({required String ipaPath}) async {
2869
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()}');
3071
}
3172

3273
/// Validate and upload ios app to TestFlight.

0 commit comments

Comments
 (0)