-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shorebird_cli): add shorebird build aar command (#570)
- Loading branch information
1 parent
efda257
commit 6c7473d
Showing
5 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/shorebird_cli/lib/src/commands/build/build_aar_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.