55import 'dart:async' ;
66import 'dart:io' ;
77
8- import 'package:args/command_runner .dart' ;
8+ import 'package:args/args .dart' ;
99import 'package:io/ansi.dart' ;
1010import 'package:path/path.dart' as p;
1111
1212import '../root_config.dart' ;
1313import 'mono_repo_command.dart' ;
1414
15- class PubCommand extends Command <void > {
16- PubCommand () {
17- addSubcommand (_PubSubCommand ('get' ));
18- addSubcommand (_PubSubCommand ('upgrade' ));
19- }
15+ class PubCommand extends MonoRepoCommand {
16+ @override
17+ final ArgParser argParser = ArgParser .allowAnything ();
2018
2119 @override
2220 String get name => 'pub' ;
2321
2422 @override
2523 String get description =>
26- 'Run `dart pub get` or `dart pub upgrade` against all packages.' ;
27- }
28-
29- const _offline = 'offline' ;
30- const _dryRun = 'dry-run' ;
31- const _precompile = 'precompile' ;
32-
33- class _PubSubCommand extends MonoRepoCommand {
34- @override
35- final String name;
36-
37- _PubSubCommand (this .name) {
38- argParser
39- ..addFlag (
40- _offline,
41- help: 'Use cached packages instead of accessing the network.' ,
42- )
43- ..addFlag (
44- _dryRun,
45- abbr: 'n' ,
46- negatable: false ,
47- help: "Report what dependencies would change but don't change any." ,
48- )
49- ..addFlag (
50- _precompile,
51- help: 'Precompile executables and transformed dependencies.' ,
52- );
53- }
54-
55- @override
56- String get description => 'Run `dart pub $name ` against all packages.' ;
24+ 'Runs the `pub` command with the provided arguments across all packages.' ;
5725
5826 @override
5927 Future <void > run () => pub (
6028 rootConfig (),
61- name,
62- offline: argResults! [_offline] as bool ,
63- dryRun: argResults! [_dryRun] as bool ,
64- preCompile: argResults! [_precompile] as bool ,
29+ argResults? .rest ?? const [],
6530 );
6631}
6732
68- Future <void > pub (
69- RootConfig rootConfig,
70- String pubCommand, {
71- required bool offline,
72- required bool dryRun,
73- required bool preCompile,
74- }) async {
33+ Future <void > pub (RootConfig rootConfig, List <String > args) async {
7534 final pkgDirs = rootConfig.map ((pc) => pc.relativePath).toList ();
7635
77- // TODO(kevmoo): use UI-as-code features when min SDK is >= 2.3.0
78- final args = [pubCommand];
79- if (offline) {
80- args.add ('--$_offline ' );
81- }
82-
83- if (dryRun) {
84- args.add ('--$_dryRun ' );
85- }
86-
87- // Note: the default is `false`
88- if (preCompile) {
89- args.add ('--$_precompile ' );
90- }
91-
9236 print (
9337 lightBlue.wrap (
9438 'Running `dart pub ${args .join (' ' )}` across ${pkgDirs .length } '
9539 'package(s).' ,
9640 ),
9741 );
9842
43+ final packageArgs = ['pub' , ...args];
44+
45+ var successCount = 0 ;
46+ final failSet = < String > {};
47+
9948 for (var config in rootConfig) {
10049 final dir = config.relativePath;
101- List <String > packageArgs;
10250 String executable;
10351
10452 if (config.hasFlutterDependency) {
10553 executable = _flutterPath;
106- packageArgs = ['packages' , ...args];
10754 } else {
108- executable = _pubPath;
109- packageArgs = args;
55+ executable = _dartPath;
11056 }
11157
11258 print ('' );
11359 print (
11460 wrapWith (
115- 'Starting `$executable ${packageArgs .join (' ' )}` in `$ dir `... ' ,
61+ '`$ dir `: Starting `$executable ${packageArgs .join (' ' )}`' ,
11662 [styleBold, lightBlue],
11763 ),
11864 );
@@ -124,10 +70,27 @@ Future<void> pub(
12470 final exit = await proc.exitCode;
12571
12672 if (exit == 0 ) {
73+ successCount++ ;
12774 print (wrapWith ('`$dir `: success!' , [styleBold, green]));
12875 } else {
76+ failSet.add (dir);
12977 print (wrapWith ('`$dir `: failed!' , [styleBold, red]));
13078 }
79+
80+ if (rootConfig.length > 1 ) {
81+ print ('' );
82+ print ('Successes: $successCount ' );
83+ if (failSet.isNotEmpty) {
84+ print (
85+ 'Failures: ${failSet .length }\n '
86+ '${failSet .map ((e ) => ' $e ' ).join ('\n ' )}' ,
87+ );
88+ }
89+ final remaining = rootConfig.length - (successCount + failSet.length);
90+ if (remaining > 0 ) {
91+ print ('Remaining: $remaining ' );
92+ }
93+ }
13194 }
13295}
13396
@@ -140,8 +103,8 @@ final String _sdkDir = (() {
140103 return aboveExecutable;
141104})();
142105
143- final String _pubPath =
144- p.join (_sdkDir, 'bin' , Platform .isWindows ? 'pub .bat' : 'pub ' );
106+ final String _dartPath =
107+ p.join (_sdkDir, 'bin' , Platform .isWindows ? 'dart .bat' : 'dart ' );
145108
146109/// The "flutter[.bat] " command.
147110final String _flutterPath = Platform .isWindows ? 'flutter.bat' : 'flutter' ;
0 commit comments