Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#140: added realtime buildrunner logging #141

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog
## [7.0.0] - 2023-08-14
*BREAKING CHANGE*: Every type is now defined inline, this means that 'required' is no longer supported, if a field isn't nullable it is automatically required. This also means that the 'array' type is no longer supported and is instead just defined like 'List<T>'.
- *BREAKING CHANGE*: Every type is now defined inline, this means that 'required' is no longer supported, if a field isn't nullable it is automatically required. This also means that the 'array' type is no longer supported and is instead just defined like 'List<T>'.
- Logs of build runner now get shown in real time.

## [6.3.0] - 2023-06-05
- Fixed the deprecated `ignore` field. Added
Expand Down
48 changes: 18 additions & 30 deletions bin/model_generator.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:args/args.dart';
Expand All @@ -8,6 +9,7 @@ import 'package:model_generator/model/model/custom_model.dart';
import 'package:model_generator/model/model/enum_model.dart';
import 'package:model_generator/model/model/json_converter_model.dart';
import 'package:model_generator/model/model/object_model.dart';
import 'package:model_generator/run_process/run_process.dart';
import 'package:model_generator/util/list_extensions.dart';
import 'package:model_generator/writer/enum_model_writer.dart';
import 'package:model_generator/writer/object_model_writer.dart';
Expand Down Expand Up @@ -140,34 +142,20 @@ void writeToFiles(
}

Future<void> generateJsonGeneratedModels({required bool useFvm}) async {
ProcessResult result;
if (useFvm) {
result = Process.runSync('fvm', [
'flutter',
'packages',
'pub',
'run',
'build_runner',
'build',
'--delete-conflicting-outputs',
]);
} else {
result = Process.runSync('flutter', [
'packages',
'pub',
'run',
'build_runner',
'build',
'--delete-conflicting-outputs',
]);
}
if (result.exitCode == 0) {
print('Successfully generated the jsonSerializable generated files');
print('');
} else {
print(
'Failed to run `${useFvm ? 'fvm ' : ''}flutter packages pub run build_runner build --delete-conflicting-outputs`');
print('StdErr: ${result.stderr}');
print('StdOut: ${result.stdout}');
}
final arguments = [
if (useFvm) ...[
'fvm',
],
'flutter',
'packages',
'pub',
'run',
'build_runner',
'build',
'--delete-conflicting-outputs',
];
await ProcessRunner.runProcessVerbose(
arguments.first,
arguments.skip(1).toList(),
);
}
30 changes: 30 additions & 0 deletions lib/run_process/run_process.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

class ProcessRunner {
ProcessRunner._();

static Future<void> runProcessVerbose(
String command, List<String> args) async {
print('\n$command ${args.join(' ')}\n');
final completer = Completer<void>();
final result = await Process.start(
command,
args,
mode: ProcessStartMode.detachedWithStdio,
);
print(
'======================================================================');
final subscription = result.stdout
.listen((codeUnits) => stdout.write(utf8.decode(codeUnits)));
subscription.onDone(() {
print(
'======================================================================');
completer.complete();
});
subscription.onError((dynamic error) =>
completer.completeError('Failed to complete process run: $error'));
return completer.future;
}
}