1
+ import 'dart:io' ;
2
+ import 'package:path/path.dart' as path;
3
+ import 'package:yaml/yaml.dart' ;
4
+
5
+ Future <void > main () async {
6
+ final rootDir = Directory .current;
7
+ final pubspecFile = File (path.join (rootDir.path, 'pubspec.yaml' ));
8
+ final pubspecContent = await pubspecFile.readAsString ();
9
+ final pubspecYaml = loadYaml (pubspecContent);
10
+
11
+ final workspace = pubspecYaml['workspace' ] as YamlList ? ;
12
+ if (workspace == null ) {
13
+ print ('No workspace found in pubspec.yaml' );
14
+ exit (1 );
15
+ }
16
+
17
+ final packages = workspace.map ((e) => e.toString ()).toList ();
18
+
19
+ for (final package in packages) {
20
+ final packagePath = path.join (rootDir.path, package);
21
+ print ('== Testing \' $package \' ==' );
22
+
23
+ await _runCommand ('flutter' , ['pub' , 'get' ], workingDirectory: packagePath);
24
+ await _runCommand ('dart' , ['analyze' , '--fatal-infos' , '--fatal-warnings' ],
25
+ workingDirectory: packagePath);
26
+ await _runCommand ('dart' , ['format' , '--output' , 'none' , '.' ],
27
+ workingDirectory: packagePath);
28
+
29
+ if (await Directory (path.join (packagePath, 'test' )).exists ()) {
30
+ final packagePubspecFile =
31
+ File (path.join (packagePath, 'pubspec.yaml' ));
32
+ final packagePubspecContent = await packagePubspecFile.readAsString ();
33
+ if (packagePubspecContent.contains ('flutter:' )) {
34
+ await _runCommand ('flutter' , ['test' ], workingDirectory: packagePath);
35
+ } else {
36
+ await _runCommand ('dart' , ['test' ], workingDirectory: packagePath);
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ Future <void > _runCommand (String executable, List <String > arguments,
43
+ {required String workingDirectory}) async {
44
+ final process = await Process .start (executable, arguments,
45
+ workingDirectory: workingDirectory, mode: ProcessStartMode .inheritStdio);
46
+ final exitCode = await process.exitCode;
47
+ if (exitCode != 0 ) {
48
+ print ('Command "$executable ${arguments .join (' ' )}" failed with exit code $exitCode in $workingDirectory ' );
49
+ exit (exitCode);
50
+ }
51
+ }
0 commit comments