From f25debfdfbdb0ae3112862e04b9cce626351c66f Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Wed, 3 Apr 2024 11:49:15 -0300 Subject: [PATCH 1/6] fix: shorebird preview to indentify shorebird projects with flavors --- .../lib/src/commands/preview_command.dart | 19 ++++++++++++++++++- packages/shorebird_cli/pubspec.lock | 8 ++++---- .../src/commands/preview_command_test.dart | 12 +++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/preview_command.dart b/packages/shorebird_cli/lib/src/commands/preview_command.dart index 7a28dc387..138846272 100644 --- a/packages/shorebird_cli/lib/src/commands/preview_command.dart +++ b/packages/shorebird_cli/lib/src/commands/preview_command.dart @@ -76,6 +76,7 @@ class PreviewCommand extends ShorebirdCommand { @override Future run() async { + print('Helloo'); // TODO(bryanoltman): check preview target and run either // doctor.iosValidators or doctor.androidValidators as appropriate. try { @@ -88,10 +89,17 @@ class PreviewCommand extends ShorebirdCommand { final shorebirdYaml = shorebirdEnv.getShorebirdYaml(); final String? appId; + + final flavors = shorebirdYaml?.flavors; + if (results.wasParsed('app-id')) { appId = results['app-id'] as String; - } else if (shorebirdYaml != null && shorebirdYaml.flavors == null) { + } else if (shorebirdYaml != null && flavors == null) { appId = shorebirdYaml.appId; + } else if (shorebirdYaml != null && flavors != null) { + final flavorOptions = flavors.keys.toList(); + final choosenOne = await promptForFlavor(flavorOptions); + appId = flavors[choosenOne]; } else { appId = await promptForApp(); } @@ -172,6 +180,15 @@ class PreviewCommand extends ShorebirdCommand { return app.appId; } + Future promptForFlavor( + List flavors, + ) async { + return logger.chooseOne( + 'Which app flavor?', + choices: flavors, + ); + } + Future promptForReleaseVersion(List releases) async { if (releases.isEmpty) return null; final release = logger.chooseOne( diff --git a/packages/shorebird_cli/pubspec.lock b/packages/shorebird_cli/pubspec.lock index cc295bf45..5948f375c 100644 --- a/packages/shorebird_cli/pubspec.lock +++ b/packages/shorebird_cli/pubspec.lock @@ -141,10 +141,10 @@ packages: dependency: transitive description: name: built_value - sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e + sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb url: "https://pub.dev" source: hosted - version: "8.9.1" + version: "8.9.2" characters: dependency: transitive description: @@ -802,10 +802,10 @@ packages: dependency: transitive description: name: win32 - sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480" + sha256: "0a989dc7ca2bb51eac91e8fd00851297cfffd641aa7538b165c62637ca0eaa4a" url: "https://pub.dev" source: hosted - version: "5.3.0" + version: "5.4.0" xml: dependency: "direct main" description: diff --git a/packages/shorebird_cli/test/src/commands/preview_command_test.dart b/packages/shorebird_cli/test/src/commands/preview_command_test.dart index 020a10e75..8266e03bb 100644 --- a/packages/shorebird_cli/test/src/commands/preview_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/preview_command_test.dart @@ -712,7 +712,7 @@ channel: ${track.channel} verifyNever(() => codePushClientWrapper.getApps()); }); - test('prompts for app id when in shorebird project with flavors', + test('prompts for the flavor when in shorebird project with flavors', () async { when(() => shorebirdEnv.getShorebirdYaml()).thenReturn( const ShorebirdYaml( @@ -723,20 +723,18 @@ channel: ${track.channel} when(() => argResults.wasParsed('app-id')).thenReturn(false); when(() => argResults['app-id']).thenReturn(null); when( - () => logger.chooseOne( + () => logger.chooseOne( any(), choices: any(named: 'choices'), - display: any(named: 'display'), ), - ).thenReturn(app); + ).thenReturn('dev'); await runWithOverrides(command.run); verify( - () => logger.chooseOne( - 'Which app would you like to preview?', + () => logger.chooseOne( + any(), choices: any(named: 'choices'), - display: any(named: 'display'), ), ).called(1); }); From a15d0af4b6867d8c24a1692e55d134b66808b469 Mon Sep 17 00:00:00 2001 From: Erick Date: Wed, 3 Apr 2024 11:54:27 -0300 Subject: [PATCH 2/6] Update packages/shorebird_cli/lib/src/commands/preview_command.dart Co-authored-by: Bryan Oltman --- packages/shorebird_cli/lib/src/commands/preview_command.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/shorebird_cli/lib/src/commands/preview_command.dart b/packages/shorebird_cli/lib/src/commands/preview_command.dart index 138846272..31f85db01 100644 --- a/packages/shorebird_cli/lib/src/commands/preview_command.dart +++ b/packages/shorebird_cli/lib/src/commands/preview_command.dart @@ -76,7 +76,6 @@ class PreviewCommand extends ShorebirdCommand { @override Future run() async { - print('Helloo'); // TODO(bryanoltman): check preview target and run either // doctor.iosValidators or doctor.androidValidators as appropriate. try { From 8c3cb66e49716d1b1d41e5efcb2da2c43b5c09f1 Mon Sep 17 00:00:00 2001 From: Erick Date: Wed, 3 Apr 2024 11:55:05 -0300 Subject: [PATCH 3/6] Update packages/shorebird_cli/lib/src/commands/preview_command.dart Co-authored-by: Bryan Oltman --- packages/shorebird_cli/lib/src/commands/preview_command.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/preview_command.dart b/packages/shorebird_cli/lib/src/commands/preview_command.dart index 31f85db01..88b817e19 100644 --- a/packages/shorebird_cli/lib/src/commands/preview_command.dart +++ b/packages/shorebird_cli/lib/src/commands/preview_command.dart @@ -97,8 +97,8 @@ class PreviewCommand extends ShorebirdCommand { appId = shorebirdYaml.appId; } else if (shorebirdYaml != null && flavors != null) { final flavorOptions = flavors.keys.toList(); - final choosenOne = await promptForFlavor(flavorOptions); - appId = flavors[choosenOne]; + final choosenFlavor = await promptForFlavor(flavorOptions); + appId = flavors[choosenFlavor]; } else { appId = await promptForApp(); } From 6efc52b7d37bd593e69433cd25c62a9e516af243 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Wed, 3 Apr 2024 13:30:16 -0300 Subject: [PATCH 4/6] reverting pubspec.lock --- packages/shorebird_cli/pubspec.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/shorebird_cli/pubspec.lock b/packages/shorebird_cli/pubspec.lock index 5948f375c..cc295bf45 100644 --- a/packages/shorebird_cli/pubspec.lock +++ b/packages/shorebird_cli/pubspec.lock @@ -141,10 +141,10 @@ packages: dependency: transitive description: name: built_value - sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e url: "https://pub.dev" source: hosted - version: "8.9.2" + version: "8.9.1" characters: dependency: transitive description: @@ -802,10 +802,10 @@ packages: dependency: transitive description: name: win32 - sha256: "0a989dc7ca2bb51eac91e8fd00851297cfffd641aa7538b165c62637ca0eaa4a" + sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480" url: "https://pub.dev" source: hosted - version: "5.4.0" + version: "5.3.0" xml: dependency: "direct main" description: From 2ea9b3e6d0f10cd2d4091afe7b41fc2ad38cf785 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Wed, 3 Apr 2024 13:32:25 -0300 Subject: [PATCH 5/6] PR suggestions --- .../lib/src/commands/preview_command.dart | 14 ++++---------- .../test/src/commands/preview_command_test.dart | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/preview_command.dart b/packages/shorebird_cli/lib/src/commands/preview_command.dart index 88b817e19..9b28c83af 100644 --- a/packages/shorebird_cli/lib/src/commands/preview_command.dart +++ b/packages/shorebird_cli/lib/src/commands/preview_command.dart @@ -97,7 +97,10 @@ class PreviewCommand extends ShorebirdCommand { appId = shorebirdYaml.appId; } else if (shorebirdYaml != null && flavors != null) { final flavorOptions = flavors.keys.toList(); - final choosenFlavor = await promptForFlavor(flavorOptions); + final choosenFlavor = logger.chooseOne( + 'Which app flavor?', + choices: flavorOptions, + ); appId = flavors[choosenFlavor]; } else { appId = await promptForApp(); @@ -179,15 +182,6 @@ class PreviewCommand extends ShorebirdCommand { return app.appId; } - Future promptForFlavor( - List flavors, - ) async { - return logger.chooseOne( - 'Which app flavor?', - choices: flavors, - ); - } - Future promptForReleaseVersion(List releases) async { if (releases.isEmpty) return null; final release = logger.chooseOne( diff --git a/packages/shorebird_cli/test/src/commands/preview_command_test.dart b/packages/shorebird_cli/test/src/commands/preview_command_test.dart index 8266e03bb..24056b4f3 100644 --- a/packages/shorebird_cli/test/src/commands/preview_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/preview_command_test.dart @@ -734,7 +734,7 @@ channel: ${track.channel} verify( () => logger.chooseOne( any(), - choices: any(named: 'choices'), + choices: ['dev'], ), ).called(1); }); From 805b9689450009681a4a03b325060a4572891c27 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Wed, 3 Apr 2024 14:10:00 -0300 Subject: [PATCH 6/6] PR suggestions --- .../test/src/commands/preview_command_test.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/shorebird_cli/test/src/commands/preview_command_test.dart b/packages/shorebird_cli/test/src/commands/preview_command_test.dart index 24056b4f3..0b50085a8 100644 --- a/packages/shorebird_cli/test/src/commands/preview_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/preview_command_test.dart @@ -717,7 +717,10 @@ channel: ${track.channel} when(() => shorebirdEnv.getShorebirdYaml()).thenReturn( const ShorebirdYaml( appId: 'test-app-id', - flavors: {'dev': 'dev-app-id'}, + flavors: { + 'dev': 'dev-app-id', + 'prod': 'prod-app-id', + }, ), ); when(() => argResults.wasParsed('app-id')).thenReturn(false); @@ -734,7 +737,7 @@ channel: ${track.channel} verify( () => logger.chooseOne( any(), - choices: ['dev'], + choices: ['dev', 'prod'], ), ).called(1); });