touchups on the scripts
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user