fix add to app workspace troubles

pull/2701/head
Eric Windmill 1 month ago
parent 716d87844b
commit 87b3799832

@ -5,9 +5,9 @@ environment:
sdk: ^3.9.0-0
workspace:
- add_to_app/android_view/flutter_module_using_plugin
- add_to_app/android_view/flutter_module_using_plugin_android_view
- add_to_app/books/flutter_module_books
- add_to_app/fullscreen/flutter_module
- add_to_app/fullscreen/flutter_module_fullscreen
- add_to_app/multiple_flutters/multiple_flutters_module
- add_to_app/plugin/flutter_module_using_plugin
- add_to_app/prebuilt_module/flutter_module

@ -9,6 +9,7 @@ Future<void> main() async {
final pubspecYaml = loadYaml(pubspecContent);
final workspace = pubspecYaml['workspace'] as YamlList?;
await _runCommand('flutter', ['pub', 'get'], workingDirectory: rootDir.path);
if (workspace == null) {
print('No workspace found in pubspec.yaml');
exit(1);
@ -19,16 +20,20 @@ Future<void> main() async {
for (final package in packages) {
final packagePath = path.join(rootDir.path, package);
print('== Testing \'$package\' ==');
await _runCommand('flutter', ['pub', 'get'], workingDirectory: packagePath);
await _runCommand('dart', ['analyze', '--fatal-infos', '--fatal-warnings'],
workingDirectory: packagePath);
await _runCommand('dart', ['format', '--output', 'none', '.'],
workingDirectory: packagePath);
await _runCommand('dart', [
'analyze',
'--fatal-infos',
'--fatal-warnings',
], workingDirectory: packagePath);
await _runCommand('dart', [
'format',
'--output',
'none',
'.',
], workingDirectory: packagePath);
if (await Directory(path.join(packagePath, 'test')).exists()) {
final packagePubspecFile =
File(path.join(packagePath, 'pubspec.yaml'));
final packagePubspecFile = File(path.join(packagePath, 'pubspec.yaml'));
final packagePubspecContent = await packagePubspecFile.readAsString();
if (packagePubspecContent.contains('flutter:')) {
await _runCommand('flutter', ['test'], workingDirectory: packagePath);
@ -39,13 +44,22 @@ Future<void> main() async {
}
}
Future<void> _runCommand(String executable, List<String> arguments,
{required String workingDirectory}) async {
final process = await Process.start(executable, arguments,
workingDirectory: workingDirectory, mode: ProcessStartMode.inheritStdio);
Future<void> _runCommand(
String executable,
List<String> arguments, {
required String workingDirectory,
}) async {
final process = await Process.start(
executable,
arguments,
workingDirectory: workingDirectory,
mode: ProcessStartMode.inheritStdio,
);
final exitCode = await process.exitCode;
if (exitCode != 0) {
print('Command "$executable ${arguments.join(' ')}" failed with exit code $exitCode in $workingDirectory');
print(
'Command "$executable ${arguments.join(' ')}" failed with exit code $exitCode in $workingDirectory',
);
exit(exitCode);
}
}
}

@ -19,19 +19,23 @@ class ReleaseScriptRunner {
Future<void> run(List<String> arguments) async {
final parser = ArgParser()
..addFlag('dry-run',
negatable: false,
help:
'Prints the commands that would be executed, but does not run them.');
..addFlag(
'dry-run',
negatable: false,
help:
'Prints the commands that would be executed, but does not run them.',
);
final argResults = parser.parse(arguments);
_isDryRun = argResults['dry-run'] as bool;
_setupLogging();
log(
styleBold
.wrap('Flutter Monorepo Update Script Started: ${DateTime.now()}'),
stdout);
styleBold.wrap(
'Flutter Monorepo Update Script Started: ${DateTime.now()}',
),
stdout,
);
log(blue.wrap('Log file: ${_logFile.path}')!, stdout);
if (_isDryRun) {
@ -52,15 +56,19 @@ class ReleaseScriptRunner {
final packages = await _getWorkspacePackages();
if (packages.isEmpty) {
log(yellow.wrap('No packages found in the root pubspec.yaml workspace.'),
stdout);
log(
yellow.wrap('No packages found in the root pubspec.yaml workspace.'),
stdout,
);
exit(0);
}
log(
blue.wrap(
'Found ${packages.length} Flutter project(s): ${packages.join(', ')}'),
stdout);
blue.wrap(
'Found ${packages.length} Flutter project(s): ${packages.join(', ')}',
),
stdout,
);
final failedProjects = <String>[];
for (final packagePath in packages) {
@ -73,9 +81,11 @@ class ReleaseScriptRunner {
_printSummary(packages.length, failedProjects);
log(
styleBold.wrap(
'\nFlutter Monorepo Update Script Completed: ${DateTime.now()}'),
stdout);
styleBold.wrap(
'\nFlutter Monorepo Update Script Completed: ${DateTime.now()}',
),
stdout,
);
if (failedProjects.isNotEmpty) {
exit(1);
@ -167,22 +177,28 @@ class ReleaseScriptRunner {
log(blue.wrap('Updating SDK constraints to use Dart $dartVersion'), stdout);
if (!_isDryRun) {
if (!await _updateSdkConstraints(projectPath, dartVersion)) {
log(red.wrap('Failed to update SDK constraints for $projectName'),
stderr);
log(
red.wrap('Failed to update SDK constraints for $projectName'),
stderr,
);
return false;
}
}
final commands = [
Command('dart analyze', 'Running dart analyze...', 'dart',
['analyze', '--fatal-infos', '--fatal-warnings']),
Command('dart analyze', 'Running dart analyze...', 'dart', [
'analyze',
'--fatal-infos',
'--fatal-warnings',
]),
Command('dart format', 'Running dart format...', 'dart', ['format', '.']),
];
final testDir = Directory(p.join(projectPath, 'test'));
if (projectName != 'material_3_demo' && testDir.existsSync()) {
commands.add(
Command('flutter test', 'Running tests...', 'flutter', ['test']));
Command('flutter test', 'Running tests...', 'flutter', ['test']),
);
}
for (final command in commands) {
@ -229,7 +245,9 @@ class ReleaseScriptRunner {
}
Future<bool> _updateSdkConstraints(
String projectDir, String versionString) async {
String projectDir,
String versionString,
) async {
final pubspecFile = File(p.join(projectDir, 'pubspec.yaml'));
if (!pubspecFile.existsSync()) {
log(red.wrap('pubspec.yaml not found in $projectDir'), stderr);
@ -245,44 +263,61 @@ class ReleaseScriptRunner {
await pubspecFile.writeAsString(editor.toString());
log(
blue.wrap(
'Updated Dart SDK constraint in $projectDir to: $newConstraint'),
stdout);
blue.wrap(
'Updated Dart SDK constraint in $projectDir to: $newConstraint',
),
stdout,
);
return true;
} catch (e) {
log(red.wrap('Failed to update SDK constraint in $projectDir: $e'),
stderr);
log(
red.wrap('Failed to update SDK constraint in $projectDir: $e'),
stderr,
);
return false;
}
}
Future<(bool, String)> _runCommand(String executable, List<String> arguments,
{String? workingDirectory}) async {
Future<(bool, String)> _runCommand(
String executable,
List<String> arguments, {
String? workingDirectory,
}) async {
final commandString = '$executable ${arguments.join(' ')}';
if (_isDryRun) {
log(
yellow.wrap(
' [DRY RUN] Would execute: `$commandString` in `${workingDirectory ?? '.'}`'),
stdout);
yellow.wrap(
' [DRY RUN] Would execute: `$commandString` in `${workingDirectory ?? '.'}`',
),
stdout,
);
return (true, '');
}
final process = await Process.start(executable, arguments,
workingDirectory: workingDirectory, runInShell: true);
final process = await Process.start(
executable,
arguments,
workingDirectory: workingDirectory,
runInShell: true,
);
StringBuffer output = StringBuffer('');
final stdoutFuture =
process.stdout.transform(SystemEncoding().decoder).forEach((line) {
log(line, stdout);
if (!_isOnlyWhitespace(line)) output.writeln('${line.trim().padLeft(2)}');
});
final stderrFuture =
process.stderr.transform(SystemEncoding().decoder).forEach((line) {
log(red.wrap(line), stderr);
if (!_isOnlyWhitespace(line)) output.writeln('${line.trim().padLeft(2)}');
});
final stdoutFuture = process.stdout
.transform(SystemEncoding().decoder)
.forEach((line) {
log(line, stdout);
if (!_isOnlyWhitespace(line))
output.writeln('${line.trim().padLeft(2)}');
});
final stderrFuture = process.stderr
.transform(SystemEncoding().decoder)
.forEach((line) {
log(red.wrap(line), stderr);
if (!_isOnlyWhitespace(line))
output.writeln('${line.trim().padLeft(2)}');
});
await Future.wait([stdoutFuture, stderrFuture]);

Loading…
Cancel
Save