mirror of https://github.com/flutter/samples.git
parent
6f45031ed4
commit
d34c74b467
@ -0,0 +1,51 @@
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final rootDir = Directory.current;
|
||||
final pubspecFile = File(path.join(rootDir.path, 'pubspec.yaml'));
|
||||
final pubspecContent = await pubspecFile.readAsString();
|
||||
final pubspecYaml = loadYaml(pubspecContent);
|
||||
|
||||
final workspace = pubspecYaml['workspace'] as YamlList?;
|
||||
if (workspace == null) {
|
||||
print('No workspace found in pubspec.yaml');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
final packages = workspace.map((e) => e.toString()).toList();
|
||||
|
||||
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);
|
||||
|
||||
if (await Directory(path.join(packagePath, 'test')).exists()) {
|
||||
final packagePubspecFile =
|
||||
File(path.join(packagePath, 'pubspec.yaml'));
|
||||
final packagePubspecContent = await packagePubspecFile.readAsString();
|
||||
if (packagePubspecContent.contains('flutter:')) {
|
||||
await _runCommand('flutter', ['test'], workingDirectory: packagePath);
|
||||
} else {
|
||||
await _runCommand('dart', ['test'], workingDirectory: packagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
exit(exitCode);
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in new issue