Repository navigation
Expand file tree
/
Copy pathbuild_examples_command.dart
More file actions
75 lines (61 loc) · 2.21 KB
/
Copy pathbuild_examples_command.dart
File metadata and controls
75 lines (61 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:path/path.dart' as p;
import 'common.dart';
class BuildExamplesCommand extends Command<Null> {
BuildExamplesCommand(this.packagesDir) {
argParser.addFlag('ipa', defaultsTo: Platform.isMacOS);
argParser.addFlag('apk');
}
final Directory packagesDir;
@override
final String name = 'build-examples';
@override
final String description = 'Builds all example apps.';
@override
Future<Null> run() async {
final List<String> failingPackages = <String>[];
for (Directory example in _getExamplePackages(packagesDir)) {
final String packageName =
p.relative(example.path, from: packagesDir.path);
if (argResults['ipa']) {
print('\nBUILDING IPA for $packageName');
final int exitCode = await runAndStream(
'flutter', <String>['build', 'ios', '--no-codesign'], example);
if (exitCode != 0) {
failingPackages.add('$packageName (ipa)');
}
}
if (argResults['apk']) {
print('\nBUILDING APK for $packageName');
final int exitCode =
await runAndStream('flutter', <String>['build', 'apk'], example);
if (exitCode != 0) {
failingPackages.add('$packageName (apk)');
}
}
}
print('\n\n');
if (failingPackages.isNotEmpty) {
print('The following build are failing (see above for details):');
for (String package in failingPackages) {
print(' * $package');
}
throw new ToolExit(1);
}
print('All builds successful!');
}
Iterable<Directory> _getExamplePackages(Directory dir) => dir
.listSync(recursive: true)
.where((FileSystemEntity entity) =>
entity is Directory && p.basename(entity.path) == 'example')
.where((FileSystemEntity entity) {
final Directory dir = entity;
return dir.listSync().any((FileSystemEntity entity) =>
entity is File && p.basename(entity.path) == 'pubspec.yaml');
});
}