@@ -11,7 +11,9 @@ import 'package:platform/platform.dart';
1111
1212import 'common.dart' ;
1313
14+ /// A command to build the example applications for packages.
1415class BuildExamplesCommand extends PluginCommand {
16+ /// Creates an instance of the build command.
1517 BuildExamplesCommand (
1618 Directory packagesDir,
1719 FileSystem fileSystem, {
@@ -39,33 +41,40 @@ class BuildExamplesCommand extends PluginCommand {
3941 'This command requires "flutter" to be in your path.' ;
4042
4143 @override
42- Future <Null > run () async {
43- if (! argResults[kIpa] &&
44- ! argResults[kApk] &&
45- ! argResults[kLinux] &&
46- ! argResults[kMacos] &&
47- ! argResults[kWeb] &&
48- ! argResults[kWindows]) {
49- print ('None of --linux, --macos, --web, --windows, --apk, or --ipa were '
50- 'specified, so not building anything.' );
44+ Future <void > run () async {
45+ final List <String > platformSwitches = < String > [
46+ kApk,
47+ kIpa,
48+ kLinux,
49+ kMacos,
50+ kWeb,
51+ kWindows,
52+ ];
53+ final Map <String , bool > platforms = < String , bool > {
54+ for (final String platform in platformSwitches)
55+ platform: argResults[platform] as bool
56+ };
57+ if (! platforms.values.any ((bool enabled) => enabled)) {
58+ print (
59+ 'None of ${platformSwitches .map ((String platform ) => '--$platform ' ).join (', ' )} '
60+ 'were specified, so not building anything.' );
5161 return ;
5262 }
5363 final String flutterCommand =
54- LocalPlatform ().isWindows ? 'flutter.bat' : 'flutter' ;
64+ const LocalPlatform ().isWindows ? 'flutter.bat' : 'flutter' ;
5565
56- final String enableExperiment = argResults[kEnableExperiment];
66+ final String enableExperiment = argResults[kEnableExperiment] as String ;
5767
58- checkSharding ();
5968 final List <String > failingPackages = < String > [];
60- await for (Directory plugin in getPlugins ()) {
61- for (Directory example in getExamplesForPlugin (plugin)) {
69+ await for (final Directory plugin in getPlugins ()) {
70+ for (final Directory example in getExamplesForPlugin (plugin)) {
6271 final String packageName =
6372 p.relative (example.path, from: packagesDir.path);
6473
65- if (argResults [kLinux]) {
74+ if (platforms [kLinux]) {
6675 print ('\n BUILDING Linux for $packageName ' );
6776 if (isLinuxPlugin (plugin, fileSystem)) {
68- int buildExitCode = await processRunner.runAndStream (
77+ final int buildExitCode = await processRunner.runAndStream (
6978 flutterCommand,
7079 < String > [
7180 'build' ,
@@ -82,10 +91,10 @@ class BuildExamplesCommand extends PluginCommand {
8291 }
8392 }
8493
85- if (argResults [kMacos]) {
94+ if (platforms [kMacos]) {
8695 print ('\n BUILDING macOS for $packageName ' );
8796 if (isMacOsPlugin (plugin, fileSystem)) {
88- int exitCode = await processRunner.runAndStream (
97+ final int exitCode = await processRunner.runAndStream (
8998 flutterCommand,
9099 < String > [
91100 'build' ,
@@ -102,10 +111,10 @@ class BuildExamplesCommand extends PluginCommand {
102111 }
103112 }
104113
105- if (argResults [kWeb]) {
114+ if (platforms [kWeb]) {
106115 print ('\n BUILDING web for $packageName ' );
107116 if (isWebPlugin (plugin, fileSystem)) {
108- int buildExitCode = await processRunner.runAndStream (
117+ final int buildExitCode = await processRunner.runAndStream (
109118 flutterCommand,
110119 < String > [
111120 'build' ,
@@ -122,10 +131,10 @@ class BuildExamplesCommand extends PluginCommand {
122131 }
123132 }
124133
125- if (argResults [kWindows]) {
134+ if (platforms [kWindows]) {
126135 print ('\n BUILDING Windows for $packageName ' );
127136 if (isWindowsPlugin (plugin, fileSystem)) {
128- int buildExitCode = await processRunner.runAndStream (
137+ final int buildExitCode = await processRunner.runAndStream (
129138 flutterCommand,
130139 < String > [
131140 'build' ,
@@ -142,7 +151,7 @@ class BuildExamplesCommand extends PluginCommand {
142151 }
143152 }
144153
145- if (argResults [kIpa]) {
154+ if (platforms [kIpa]) {
146155 print ('\n BUILDING IPA for $packageName ' );
147156 if (isIosPlugin (plugin, fileSystem)) {
148157 final int exitCode = await processRunner.runAndStream (
@@ -163,7 +172,7 @@ class BuildExamplesCommand extends PluginCommand {
163172 }
164173 }
165174
166- if (argResults [kApk]) {
175+ if (platforms [kApk]) {
167176 print ('\n BUILDING APK for $packageName ' );
168177 if (isAndroidPlugin (plugin, fileSystem)) {
169178 final int exitCode = await processRunner.runAndStream (
@@ -188,7 +197,7 @@ class BuildExamplesCommand extends PluginCommand {
188197
189198 if (failingPackages.isNotEmpty) {
190199 print ('The following build are failing (see above for details):' );
191- for (String package in failingPackages) {
200+ for (final String package in failingPackages) {
192201 print (' * $package ' );
193202 }
194203 throw ToolExit (1 );
0 commit comments