|
6 | 6 | import 'dart:io'; |
7 | 7 |
|
8 | 8 | final String binaryName = Platform.isWindows ? 'pub.bat' : 'pub'; |
9 | | -void update(Directory directory, bool upgrade) { |
| 9 | +int runPub(Directory directory, List<String> pubArgs) { |
| 10 | + int updateCount = 0; |
10 | 11 | for (FileSystemEntity dir in directory.listSync()) { |
11 | 12 | if (dir is Directory) { |
12 | | - print("Updating ${dir.path}..."); |
| 13 | + updateCount++; |
| 14 | + Stopwatch timer = new Stopwatch()..start(); |
| 15 | + stdout.write("Updating ${dir.path}..."); |
13 | 16 | ProcessResult result = Process.runSync( |
14 | 17 | binaryName, |
15 | | - [ upgrade ? 'upgrade' : 'get' ], |
| 18 | + pubArgs, |
16 | 19 | workingDirectory: dir.path |
17 | 20 | ); |
| 21 | + timer.stop(); |
| 22 | + stdout.write(" (${timer.elapsedMilliseconds} ms)"); |
18 | 23 | if (result.exitCode != 0) { |
19 | 24 | print("... failed with exit code ${result.exitCode}."); |
20 | 25 | print(result.stdout); |
21 | 26 | print(result.stderr); |
| 27 | + } else { |
| 28 | + stdout.write("\n"); |
22 | 29 | } |
23 | 30 | } |
24 | 31 | } |
| 32 | + return updateCount; |
25 | 33 | } |
26 | 34 |
|
27 | 35 | void main(List<String> arguments) { |
| 36 | + Stopwatch timer = new Stopwatch()..start(); |
28 | 37 | bool upgrade = arguments.length > 0 && arguments[0] == '--upgrade'; |
29 | 38 | String FLUTTER_ROOT = new File(Platform.script.toFilePath()).parent.parent.path; |
30 | | - update(new Directory("$FLUTTER_ROOT/packages"), upgrade); |
31 | | - update(new Directory("$FLUTTER_ROOT/examples"), upgrade); |
| 39 | + List<String> pubArgs = [ upgrade ? 'upgrade' : 'get' ]; |
| 40 | + int count = 0; |
| 41 | + count += runPub(new Directory("$FLUTTER_ROOT/packages"), pubArgs); |
| 42 | + count += runPub(new Directory("$FLUTTER_ROOT/examples"), pubArgs); |
| 43 | + String command = "$binaryName ${pubArgs.join(' ')}"; |
| 44 | + print("Ran \"$command\" $count times in ${timer.elapsedMilliseconds} ms"); |
32 | 45 | } |
0 commit comments