Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shorebird_cli): add release android_archive command #573

Merged
merged 9 commits into from
May 31, 2023
3 changes: 3 additions & 0 deletions packages/shorebird_cli/lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// Signature for a function which takes a list of bytes and returns a hash.
typedef HashFunction = String Function(List<int> bytes);

/// Signature for a function which takes a path to a zip file.
typedef UnzipFn = Future<void> Function(String zipFilePath, String outputDir);

typedef CodePushClientBuilder = CodePushClient Function({
required http.Client httpClient,
Uri? hostedUri,
Expand Down
1 change: 1 addition & 0 deletions packages/shorebird_cli/lib/src/commands/build/build.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'build_aar_command.dart';
export 'build_apk_command.dart';
export 'build_app_bundle_command.dart';
export 'build_command.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'dart:async';
import 'dart:io';

import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';

/// {@template build_aar_command}
///
/// `shorebird build aar`
/// Build an Android aar file from your app.
/// {@endtemplate}
class BuildAarCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
BuildAarCommand({
required super.logger,
super.auth,
}) {
// We would have a "target" option here, similar to what [BuildApkCommand]
// and [BuildAabCommand] have, but target cannot currently be configured in
// `flutter build aar` and is always assumed to be lib/main.dart.
argParser
..addOption(
'flavor',
help: 'The product flavor to use when building the app.',
)
// `flutter build aar` defaults to a build number of 1.0, so we do the
// same.
..addOption(
'build-number',
help: 'The build number of the aar',
defaultsTo: '1.0',
);
}

@override
String get name => 'aar';

@override
String get description => 'Build an Android AAR file from your module.';

@override
Future<int> run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

final pubspec = getPubspecYaml();
if (pubspec == null) {
logger.err('No pubspec.yaml file found.');
return ExitCode.config.code;
}

final module = pubspec.flutter?['module'] as Map?;
final androidPackageName = module?['androidPackage'] as String?;
if (androidPackageName == null) {
logger.err('Could not find androidPackage in pubspec.yaml.');
return ExitCode.config.code;
}

final flavor = results['flavor'] as String?;
final buildNumber = results['build-number'] as String;
final buildProgress = logger.progress('Building aar');
try {
await buildAar(buildNumber: buildNumber, flavor: flavor);
} on ProcessException catch (error) {
buildProgress.fail('Failed to build: ${error.message}');
return ExitCode.software.code;
}

buildProgress.complete();

final aarPath = p.joinAll([
'build',
'host',
'outputs',
'repo',
...androidPackageName.split('.'),
'flutter_release',
buildNumber,
'flutter_release-$buildNumber.aar',
]);

logger.info('''
📦 Generated an aar at:
${lightCyan.wrap(aarPath)}''');

return ExitCode.success.code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:shorebird_cli/src/commands/build/build.dart';
class BuildCommand extends ShorebirdCommand {
/// {@macro build_command}
BuildCommand({required super.logger}) {
addSubcommand(BuildAarCommand(logger: logger));
addSubcommand(BuildApkCommand(logger: logger));
addSubcommand(BuildAppBundleCommand(logger: logger));
addSubcommand(BuildIpaCommand(logger: logger));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'release_android_archive_command.dart';
export 'release_android_command.dart';
export 'release_command.dart';
export 'release_ios_command.dart';
Loading