@@ -11,7 +11,9 @@ import 'package:platform/platform.dart';
11
11
12
12
import 'common.dart' ;
13
13
14
+ /// A command to build the example applications for packages.
14
15
class BuildExamplesCommand extends PluginCommand {
16
+ /// Creates an instance of the build command.
15
17
BuildExamplesCommand (
16
18
Directory packagesDir,
17
19
FileSystem fileSystem, {
@@ -39,33 +41,40 @@ class BuildExamplesCommand extends PluginCommand {
39
41
'This command requires "flutter" to be in your path.' ;
40
42
41
43
@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.' );
51
61
return ;
52
62
}
53
63
final String flutterCommand =
54
- LocalPlatform ().isWindows ? 'flutter.bat' : 'flutter' ;
64
+ const LocalPlatform ().isWindows ? 'flutter.bat' : 'flutter' ;
55
65
56
- final String enableExperiment = argResults[kEnableExperiment];
66
+ final String enableExperiment = argResults[kEnableExperiment] as String ;
57
67
58
- checkSharding ();
59
68
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)) {
62
71
final String packageName =
63
72
p.relative (example.path, from: packagesDir.path);
64
73
65
- if (argResults [kLinux]) {
74
+ if (platforms [kLinux]) {
66
75
print ('\n BUILDING Linux for $packageName ' );
67
76
if (isLinuxPlugin (plugin, fileSystem)) {
68
- int buildExitCode = await processRunner.runAndStream (
77
+ final int buildExitCode = await processRunner.runAndStream (
69
78
flutterCommand,
70
79
< String > [
71
80
'build' ,
@@ -82,10 +91,10 @@ class BuildExamplesCommand extends PluginCommand {
82
91
}
83
92
}
84
93
85
- if (argResults [kMacos]) {
94
+ if (platforms [kMacos]) {
86
95
print ('\n BUILDING macOS for $packageName ' );
87
96
if (isMacOsPlugin (plugin, fileSystem)) {
88
- int exitCode = await processRunner.runAndStream (
97
+ final int exitCode = await processRunner.runAndStream (
89
98
flutterCommand,
90
99
< String > [
91
100
'build' ,
@@ -102,10 +111,10 @@ class BuildExamplesCommand extends PluginCommand {
102
111
}
103
112
}
104
113
105
- if (argResults [kWeb]) {
114
+ if (platforms [kWeb]) {
106
115
print ('\n BUILDING web for $packageName ' );
107
116
if (isWebPlugin (plugin, fileSystem)) {
108
- int buildExitCode = await processRunner.runAndStream (
117
+ final int buildExitCode = await processRunner.runAndStream (
109
118
flutterCommand,
110
119
< String > [
111
120
'build' ,
@@ -122,10 +131,10 @@ class BuildExamplesCommand extends PluginCommand {
122
131
}
123
132
}
124
133
125
- if (argResults [kWindows]) {
134
+ if (platforms [kWindows]) {
126
135
print ('\n BUILDING Windows for $packageName ' );
127
136
if (isWindowsPlugin (plugin, fileSystem)) {
128
- int buildExitCode = await processRunner.runAndStream (
137
+ final int buildExitCode = await processRunner.runAndStream (
129
138
flutterCommand,
130
139
< String > [
131
140
'build' ,
@@ -142,7 +151,7 @@ class BuildExamplesCommand extends PluginCommand {
142
151
}
143
152
}
144
153
145
- if (argResults [kIpa]) {
154
+ if (platforms [kIpa]) {
146
155
print ('\n BUILDING IPA for $packageName ' );
147
156
if (isIosPlugin (plugin, fileSystem)) {
148
157
final int exitCode = await processRunner.runAndStream (
@@ -163,7 +172,7 @@ class BuildExamplesCommand extends PluginCommand {
163
172
}
164
173
}
165
174
166
- if (argResults [kApk]) {
175
+ if (platforms [kApk]) {
167
176
print ('\n BUILDING APK for $packageName ' );
168
177
if (isAndroidPlugin (plugin, fileSystem)) {
169
178
final int exitCode = await processRunner.runAndStream (
@@ -188,7 +197,7 @@ class BuildExamplesCommand extends PluginCommand {
188
197
189
198
if (failingPackages.isNotEmpty) {
190
199
print ('The following build are failing (see above for details):' );
191
- for (String package in failingPackages) {
200
+ for (final String package in failingPackages) {
192
201
print (' * $package ' );
193
202
}
194
203
throw ToolExit (1 );
0 commit comments