chore(shorebird_cli): move logs to application config directory (#2060)
This commit is contained in:
@@ -109,6 +109,11 @@ class Cache {
|
||||
if (cacheDir.existsSync()) {
|
||||
cacheDir.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
final logsDirectory = shorebirdEnv.logsDirectory;
|
||||
if (logsDirectory.existsSync()) {
|
||||
logsDirectory.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ class CleanCacheCommand extends ShorebirdCommand {
|
||||
progress.fail(
|
||||
'''Failed to delete cache directory $cachePath: $error''',
|
||||
);
|
||||
|
||||
if (!platform.isWindows) {
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@ class ShorebirdLogger extends Logger {
|
||||
|
||||
late final File logFile = (() {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
final file = File(
|
||||
p.join(
|
||||
shorebirdEnv.shorebirdRoot.path,
|
||||
'logs',
|
||||
shorebirdEnv.logsDirectory.path,
|
||||
'${timestamp}_$_logFileName',
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'dart:io' hide Platform;
|
||||
|
||||
import 'package:checked_yaml/checked_yaml.dart';
|
||||
import 'package:cli_util/cli_util.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
import 'package:scoped/scoped.dart';
|
||||
import 'package:shorebird_cli/src/command_runner.dart';
|
||||
import 'package:shorebird_cli/src/config/shorebird_yaml.dart';
|
||||
import 'package:shorebird_cli/src/platform.dart';
|
||||
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
|
||||
@@ -29,6 +31,16 @@ class ShorebirdEnv {
|
||||
|
||||
final String? _flutterRevisionOverride;
|
||||
|
||||
/// The application config directory for the Shorebird CLI.
|
||||
Directory get configDirectory {
|
||||
return Directory(applicationConfigHome(executableName));
|
||||
}
|
||||
|
||||
/// The directory where shorebird logs are stored.
|
||||
Directory get logsDirectory {
|
||||
return Directory(p.join(configDirectory.path, 'logs'));
|
||||
}
|
||||
|
||||
/// The root directory of the Shorebird install.
|
||||
///
|
||||
/// Assumes we are running from $ROOT/bin/cache.
|
||||
|
||||
@@ -25,6 +25,7 @@ void main() {
|
||||
|
||||
late ArtifactManager artifactManager;
|
||||
late Directory shorebirdRoot;
|
||||
late Directory logsDirectory;
|
||||
late http.Client httpClient;
|
||||
late ShorebirdLogger logger;
|
||||
late Platform platform;
|
||||
@@ -77,6 +78,7 @@ void main() {
|
||||
shorebirdProcess = MockShorebirdProcess();
|
||||
|
||||
shorebirdRoot = Directory.systemTemp.createTempSync();
|
||||
logsDirectory = Directory.systemTemp.createTempSync();
|
||||
when(
|
||||
() => artifactManager.extractZip(
|
||||
zipFile: any(named: 'zipFile'),
|
||||
@@ -90,6 +92,7 @@ void main() {
|
||||
() => shorebirdEnv.shorebirdEngineRevision,
|
||||
).thenReturn(shorebirdEngineRevision);
|
||||
when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot);
|
||||
when(() => shorebirdEnv.logsDirectory).thenReturn(logsDirectory);
|
||||
|
||||
when(() => platform.environment).thenReturn({});
|
||||
setMockPlatform(Platform.macOS);
|
||||
@@ -163,18 +166,28 @@ void main() {
|
||||
final shorebirdCacheDirectory = runWithOverrides(
|
||||
() => Cache.shorebirdCacheDirectory,
|
||||
)..createSync(recursive: true);
|
||||
final logsDirectory = runWithOverrides(
|
||||
() => shorebirdEnv.logsDirectory,
|
||||
)..createSync(recursive: true);
|
||||
expect(shorebirdCacheDirectory.existsSync(), isTrue);
|
||||
expect(logsDirectory.existsSync(), isTrue);
|
||||
runWithOverrides(cache.clear);
|
||||
expect(shorebirdCacheDirectory.existsSync(), isFalse);
|
||||
expect(logsDirectory.existsSync(), isFalse);
|
||||
});
|
||||
|
||||
test('does nothing if directory does not exist', () {
|
||||
final shorebirdCacheDirectory = runWithOverrides(
|
||||
() => Cache.shorebirdCacheDirectory,
|
||||
);
|
||||
final logsDirectory = runWithOverrides(
|
||||
() => shorebirdEnv.logsDirectory,
|
||||
)..deleteSync(recursive: true);
|
||||
expect(shorebirdCacheDirectory.existsSync(), isFalse);
|
||||
expect(logsDirectory.existsSync(), isFalse);
|
||||
runWithOverrides(cache.clear);
|
||||
expect(shorebirdCacheDirectory.existsSync(), isFalse);
|
||||
expect(logsDirectory.existsSync(), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -96,8 +96,9 @@ void main() {
|
||||
|
||||
when(cache.updateAll).thenAnswer((_) async => {});
|
||||
|
||||
when(() => codePushClientWrapper.getApp(appId: any(named: 'appId')))
|
||||
.thenAnswer((_) async => appMetadata);
|
||||
when(
|
||||
() => codePushClientWrapper.getApp(appId: any(named: 'appId')),
|
||||
).thenAnswer((_) async => appMetadata);
|
||||
when(
|
||||
() => codePushClientWrapper.maybeGetRelease(
|
||||
appId: any(named: 'appId'),
|
||||
@@ -127,8 +128,9 @@ void main() {
|
||||
|
||||
when(() => releaser.assertPreconditions()).thenAnswer((_) async => {});
|
||||
when(() => releaser.assertArgsAreValid()).thenAnswer((_) async => {});
|
||||
when(() => releaser.buildReleaseArtifacts())
|
||||
.thenAnswer((_) async => File(''));
|
||||
when(
|
||||
() => releaser.buildReleaseArtifacts(),
|
||||
).thenAnswer((_) async => File(''));
|
||||
when(
|
||||
() => releaser.getReleaseVersion(
|
||||
releaseArtifactRoot: any(named: 'releaseArtifactRoot'),
|
||||
@@ -140,11 +142,13 @@ void main() {
|
||||
appId: any(named: 'appId'),
|
||||
),
|
||||
).thenAnswer((_) async => {});
|
||||
when(() => releaser.postReleaseInstructions)
|
||||
.thenReturn(postReleaseInstructions);
|
||||
when(
|
||||
() => releaser.postReleaseInstructions,
|
||||
).thenReturn(postReleaseInstructions);
|
||||
when(() => releaser.releaseType).thenReturn(ReleaseType.android);
|
||||
when(() => releaser.releaseMetadata())
|
||||
.thenAnswer((_) async => UpdateReleaseMetadata.forTest());
|
||||
when(
|
||||
() => releaser.releaseMetadata(),
|
||||
).thenAnswer((_) async => UpdateReleaseMetadata.forTest());
|
||||
when(() => releaser.requiresReleaseVersionArg).thenReturn(false);
|
||||
|
||||
when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml);
|
||||
|
||||
@@ -12,32 +12,29 @@ import 'mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('ShorebirdLogger', () {
|
||||
late Directory shorebirdRootDir;
|
||||
late Directory logsDirectory;
|
||||
late ShorebirdEnv shorebirdEnv;
|
||||
late ShorebirdLogger shorebirdLogger;
|
||||
|
||||
setUp(() {
|
||||
shorebirdRootDir = Directory.systemTemp.createTempSync('shorebird_logs');
|
||||
logsDirectory = Directory.systemTemp.createTempSync(
|
||||
'shorebird_logs',
|
||||
);
|
||||
|
||||
shorebirdEnv = MockShorebirdEnv();
|
||||
when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRootDir);
|
||||
when(() => shorebirdEnv.logsDirectory).thenReturn(logsDirectory);
|
||||
|
||||
// Setting to quiet so we don't spam the stdout/stderr while testing
|
||||
shorebirdLogger = ShorebirdLogger(level: Level.quiet);
|
||||
});
|
||||
|
||||
String readLogFile() {
|
||||
final logFile = Directory(
|
||||
p.join(shorebirdRootDir.path, 'logs'),
|
||||
).listSync().first;
|
||||
final logFile = Directory(p.join(logsDirectory.path)).listSync().first;
|
||||
return File(logFile.path).readAsStringSync();
|
||||
}
|
||||
|
||||
test('can be instantiated', () {
|
||||
expect(
|
||||
ShorebirdLogger.new,
|
||||
returnsNormally,
|
||||
);
|
||||
expect(ShorebirdLogger.new, returnsNormally);
|
||||
});
|
||||
|
||||
test('info', () {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:path/path.dart' as p;
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
import 'package:scoped/scoped.dart';
|
||||
import 'package:shorebird_cli/src/command_runner.dart';
|
||||
import 'package:shorebird_cli/src/platform.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_env.dart';
|
||||
import 'package:test/test.dart';
|
||||
@@ -64,6 +65,24 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('configDirectory', () {
|
||||
test('returns correct directory', () {
|
||||
expect(
|
||||
runWithOverrides(() => shorebirdEnv.configDirectory.path),
|
||||
endsWith(executableName),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('logsDirectory', () {
|
||||
test('returns correct directory', () {
|
||||
expect(
|
||||
runWithOverrides(() => shorebirdEnv.logsDirectory.path),
|
||||
endsWith(p.join(executableName, 'logs')),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('getShorebirdYamlFile', () {
|
||||
test('returns correct file', () {
|
||||
final tempDir = Directory.systemTemp.createTempSync();
|
||||
|
||||
Reference in New Issue
Block a user