touchups on the scripts
This commit is contained in:
parent
fdc49bcb8d
commit
22b13b9720
@ -28,8 +28,8 @@ dev_dependencies:
|
||||
very_good_analysis: ^5.1.0
|
||||
|
||||
scripts:
|
||||
run_build: dart scripts/run_build_runner.dart
|
||||
run_watch: dart scripts/run_build_runner.dart --watch
|
||||
runner_build: dart scripts/run_build_runner.dart
|
||||
runner_watch: dart scripts/run_build_runner.dart --watch
|
||||
build: dart_frog build
|
||||
dev: dart_frog dev
|
||||
e2e: dart scripts/test_runner.dart
|
||||
|
@ -54,20 +54,23 @@ void main(List<String> args) async {
|
||||
Future<void> runBuildRunner(String packagePath, {required bool watch}) async {
|
||||
final package = packagePath.split('/').last;
|
||||
print('📦 Starting build_runner for $package...');
|
||||
Future<(Process, bool)> buildRunnerFunc() => watch ? _runBuildRunnerWatch(packagePath) : _runBuildRunner(packagePath);
|
||||
Future<(Process, bool, String)> buildRunnerFunc() =>
|
||||
watch ? _runBuildRunnerWatch(packagePath) : _runBuildRunner(packagePath);
|
||||
const maxAttempts = 5;
|
||||
|
||||
Future<void> attemptRecover(Object? e, int i) async {
|
||||
try {
|
||||
print('\n⚠️ Error in $package:\n$e\nAttempting recovery (${i + 1} / $maxAttempts)...\n');
|
||||
print('\n⚠️ Error in $package:\n$e🤞 Attempting recovery (${i + 1} / $maxAttempts)...');
|
||||
|
||||
print(' Waiting 10 seconds before retry...');
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
await Future<void>.delayed(const Duration(seconds: 10));
|
||||
|
||||
// Recovery attempt
|
||||
print(' Running pub get...');
|
||||
final cmd = package == 'frontend' ? 'flutter' : 'dart';
|
||||
print('📥 Running $cmd pub get...');
|
||||
|
||||
await Process.run(
|
||||
package == 'frontend' ? 'flutter' : 'dart',
|
||||
cmd,
|
||||
['pub', 'get'],
|
||||
workingDirectory: packagePath,
|
||||
);
|
||||
@ -82,11 +85,11 @@ Future<void> runBuildRunner(String packagePath, {required bool watch}) async {
|
||||
Object? err;
|
||||
for (var i = 0; i < maxAttempts; i++) {
|
||||
try {
|
||||
final (process, needsRestart) = await buildRunnerFunc();
|
||||
final (process, needsRestart, errLogs) = await buildRunnerFunc();
|
||||
final removed = runnerWatchProcesses.remove(process.pid);
|
||||
assert(removed != null, true);
|
||||
if (needsRestart) {
|
||||
await attemptRecover(process.stderr, i);
|
||||
await attemptRecover(errLogs, i);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@ -98,12 +101,21 @@ Future<void> runBuildRunner(String packagePath, {required bool watch}) async {
|
||||
exitRunners();
|
||||
}
|
||||
|
||||
Future<(Process, bool)> _runBuildRunner(String package) async {
|
||||
final process = await Process.start(
|
||||
'dart',
|
||||
['run', 'build_runner', 'build', '--delete-conflicting-outputs'],
|
||||
workingDirectory: package,
|
||||
);
|
||||
Future<(Process, bool, String)> _runBuildRunner(String package) async {
|
||||
late final Process process;
|
||||
if (package == 'frontend') {
|
||||
process = await Process.start(
|
||||
'flutter',
|
||||
['pub', 'run', 'build_runner', 'build', '--delete-conflicting-outputs'],
|
||||
workingDirectory: package,
|
||||
);
|
||||
} else {
|
||||
process = await Process.start(
|
||||
'dart',
|
||||
['run', 'build_runner', 'build', '--delete-conflicting-outputs'],
|
||||
workingDirectory: package,
|
||||
);
|
||||
}
|
||||
|
||||
runnerWatchProcesses.addAll({process.pid: process});
|
||||
|
||||
@ -123,7 +135,7 @@ Future<(Process, bool)> _runBuildRunner(String package) async {
|
||||
.join('\n');
|
||||
|
||||
print('Build runner failed for $package:\n$relevantErrors');
|
||||
return (process, true);
|
||||
return (process, true, '');
|
||||
}
|
||||
|
||||
// Print success with minimal output
|
||||
@ -131,16 +143,26 @@ Future<(Process, bool)> _runBuildRunner(String package) async {
|
||||
outputLines.where((line) => line.contains('Succeeded') || line.contains('Generated')).join('\n').trim();
|
||||
|
||||
print(' ${successMessage.isEmpty ? "Completed successfully" : successMessage}');
|
||||
return (process, false);
|
||||
return (process, false, '');
|
||||
}
|
||||
|
||||
Future<(Process, bool)> _runBuildRunnerWatch(String packagePath) async {
|
||||
Future<(Process, bool, String)> _runBuildRunnerWatch(String packagePath) async {
|
||||
final package = packagePath.split('/').last;
|
||||
final process = await Process.start(
|
||||
'dart',
|
||||
['run', 'build_runner', 'watch', '--delete-conflicting-outputs'],
|
||||
workingDirectory: packagePath,
|
||||
);
|
||||
late final Process process;
|
||||
if (package == 'frontend') {
|
||||
process = await Process.start(
|
||||
'flutter',
|
||||
['pub', 'run', 'build_runner', 'watch', '--delete-conflicting-outputs'],
|
||||
workingDirectory: packagePath,
|
||||
);
|
||||
} else {
|
||||
process = await Process.start(
|
||||
'dart',
|
||||
['run', 'build_runner', 'watch', '--delete-conflicting-outputs'],
|
||||
workingDirectory: packagePath,
|
||||
);
|
||||
}
|
||||
final logs = <String>[];
|
||||
|
||||
runnerWatchProcesses.addAll({process.pid: process});
|
||||
|
||||
@ -153,6 +175,7 @@ Future<(Process, bool)> _runBuildRunnerWatch(String packagePath) async {
|
||||
print('🚩 [${package.toUpperCase()}] - ${line.trim()}');
|
||||
restart = true;
|
||||
}
|
||||
logs.add(line);
|
||||
});
|
||||
|
||||
process.stderr.transform(const SystemEncoding().decoder).listen((line) {
|
||||
@ -160,13 +183,14 @@ Future<(Process, bool)> _runBuildRunnerWatch(String packagePath) async {
|
||||
print('🎯 [${package.toUpperCase()}] - ${line.trim()}');
|
||||
restart = true;
|
||||
}
|
||||
logs.add(line);
|
||||
});
|
||||
|
||||
final code = await process.exitCode;
|
||||
if (!restart) {
|
||||
restart = code != 0;
|
||||
}
|
||||
return (process, restart);
|
||||
return (process, restart, logs.join('\n'));
|
||||
}
|
||||
|
||||
void exitRunners() {
|
||||
|
@ -9,24 +9,45 @@ void main() async {
|
||||
|
||||
final backendPath = '$projectRootPath/backend';
|
||||
// Start the server
|
||||
print('Starting Dart Frog server...');
|
||||
print('🐸 Building Dart Frog server...');
|
||||
final build = await Process.start(
|
||||
'dart_frog',
|
||||
['build'],
|
||||
workingDirectory: backendPath,
|
||||
mode: ProcessStartMode.inheritStdio,
|
||||
);
|
||||
|
||||
List<String> serverLogs = [];
|
||||
if (await build.exitCode != 0) {
|
||||
stdout.writeln('💀 Failed to build backend:');
|
||||
|
||||
for (final element in [build.stdout, build.stderr]) {
|
||||
element
|
||||
..transform(const SystemEncoding().decoder)
|
||||
..listen((line) => stdout.write(line));
|
||||
}
|
||||
stdout.writeln();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
final serverLogs = <String>[];
|
||||
final server = await Process.start('dart', ['build/bin/server.dart'], workingDirectory: backendPath);
|
||||
server.stdout.transform(const SystemEncoding().decoder).listen((line) => serverLogs.add(line));
|
||||
server.stderr.transform(const SystemEncoding().decoder).listen((line) => serverLogs.add(line));
|
||||
server.stdout.transform(const SystemEncoding().decoder).listen(serverLogs.add);
|
||||
server.stderr.transform(const SystemEncoding().decoder).listen(serverLogs.add);
|
||||
unawaited(
|
||||
server.exitCode.then((code) async {
|
||||
if (code != 0) {
|
||||
stdout
|
||||
..writeln('💀 Failed to run backend:\n')
|
||||
..write(serverLogs.join('\n'));
|
||||
exit(1);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
// Wait for server to be ready
|
||||
print('Waiting for server to be ready...');
|
||||
print('⏲️ Waiting for server to be ready...');
|
||||
await _waitForServer();
|
||||
|
||||
print('Running tests...');
|
||||
print('🤞 Running tests...');
|
||||
try {
|
||||
// Run the tests
|
||||
final testResult = await Process.run('dart', ['test', '$backendPath/test_e2e/tests/']);
|
||||
@ -39,12 +60,14 @@ void main() async {
|
||||
if (testResult.exitCode != 0) {
|
||||
final sub = serverLogs.length > 10 ? serverLogs.length - 10 : 0;
|
||||
stdout.write("Server logs:\n${serverLogs.sublist(sub).join('\n')}");
|
||||
} else {
|
||||
stdout.writeln("💨 Passed like a light breeze 😮💨");
|
||||
}
|
||||
|
||||
// Exit with the same code as the test process
|
||||
exit(testResult.exitCode);
|
||||
} catch (e) {
|
||||
print('Error running tests: $e');
|
||||
print('💩 Error running tests 💩: $e');
|
||||
build.kill();
|
||||
server.kill();
|
||||
|
||||
|
@ -320,14 +320,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.3.0"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http
|
||||
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
Loading…
Reference in New Issue
Block a user