From 5cbfd0dbcab3eee8646c1beb6bb346e13d46acca Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 11 Jul 2023 17:06:07 -0400 Subject: [PATCH] feat(shorebird_cli): add previews directory to cache (#835) --- packages/shorebird_cli/lib/src/cache.dart | 15 ++++++++ .../lib/src/code_push_client_wrapper.dart | 2 +- .../shorebird_cli/test/src/cache_test.dart | 34 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/shorebird_cli/lib/src/cache.dart b/packages/shorebird_cli/lib/src/cache.dart index 90527549..235d41b7 100644 --- a/packages/shorebird_cli/lib/src/cache.dart +++ b/packages/shorebird_cli/lib/src/cache.dart @@ -60,6 +60,14 @@ class Cache { ); } + /// Get a named directory from with the cache's preview directory; + /// for example, `foo` would return `bin/cache/previews/foo`. + Directory getPreviewDirectory(String name) { + return Directory( + p.join(shorebirdPreviewsDirectory.path, p.withoutExtension(name)), + ); + } + /// The Shorebird cache directory. static Directory get shorebirdCacheDirectory { return Directory( @@ -67,6 +75,13 @@ class Cache { ); } + /// The Shorebird cached previews directory. + static Directory get shorebirdPreviewsDirectory { + return Directory( + p.join(shorebirdCacheDirectory.path, 'previews'), + ); + } + /// The Shorebird cached artifacts directory. static Directory get shorebirdArtifactsDirectory { return Directory( diff --git a/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart b/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart index db748528..0a11ddc8 100644 --- a/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart +++ b/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart @@ -63,7 +63,7 @@ class CodePushClientWrapper { Future> getApps() async { final fetchAppsProgress = logger.progress('Fetching apps'); try { - final apps = (await codePushClient.getApps()).toList(); + final apps = await codePushClient.getApps(); fetchAppsProgress.complete(); return apps; } catch (error) { diff --git a/packages/shorebird_cli/test/src/cache_test.dart b/packages/shorebird_cli/test/src/cache_test.dart index 9cd466ab..bcd2c0a6 100644 --- a/packages/shorebird_cli/test/src/cache_test.dart +++ b/packages/shorebird_cli/test/src/cache_test.dart @@ -84,6 +84,40 @@ void main() { expect(Cache.new, returnsNormally); }); + group('getArtifactDirectory', () { + test('returns correct directory', () { + final directory = cache.getArtifactDirectory('test'); + expect( + directory.path.endsWith( + p.join( + 'bin', + 'cache', + 'artifacts', + 'test', + ), + ), + isTrue, + ); + }); + }); + + group('getPreviewDirectory', () { + test('returns correct directory', () { + final directory = cache.getPreviewDirectory('test'); + expect( + directory.path.endsWith( + p.join( + 'bin', + 'cache', + 'previews', + 'test', + ), + ), + isTrue, + ); + }); + }); + group('CachedArtifact', () { late CachedArtifact artifact;