-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathdart_cli.dart
More file actions
140 lines (128 loc) · 3.65 KB
/
Copy pathdart_cli.dart
File metadata and controls
140 lines (128 loc) · 3.65 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
part of 'cli.dart';
/// Dart CLI
class Dart {
/// Determine whether dart is installed.
static Future<bool> installed({required Logger logger}) async {
try {
await _Cmd.run('dart', ['--version'], logger: logger);
return true;
} on Exception catch (_) {
return false;
}
}
/// Install dart dependencies (`dart pub get`).
static Future<bool> pubGet({
required Logger logger,
String cwd = '.',
bool recursive = false,
Set<String> ignore = const {},
}) async {
final initialCwd = cwd;
final result = await _runCommand(
cmd: (cwd) async {
final relativePath = p.relative(cwd, from: initialCwd);
final path = relativePath == '.'
? '.'
: '.${p.context.separator}$relativePath';
final installProgress = logger.progress(
'Running "dart pub get" in $path',
);
try {
await _verifyGitDependencies(cwd, logger: logger);
} catch (_) {
installProgress.fail();
rethrow;
}
try {
return await _Cmd.run(
'dart',
['pub', 'get', '--no-example'],
workingDirectory: cwd,
logger: logger,
);
} finally {
installProgress.complete();
}
},
cwd: cwd,
recursive: recursive,
ignore: ignore,
);
return result.every((e) => e.exitCode == ExitCode.success.code);
}
/// Apply all fixes (`dart fix --apply`).
static Future<void> applyFixes({
required Logger logger,
String cwd = '.',
bool recursive = false,
Set<String> ignore = const {},
}) async {
if (!recursive) {
final pubspec = File(p.join(cwd, 'pubspec.yaml'));
if (!pubspec.existsSync()) throw PubspecNotFound();
await _Cmd.run(
'dart',
['fix', '--apply'],
workingDirectory: cwd,
logger: logger,
);
return;
}
final processes = _Cmd.runWhere(
run: (entity) => _Cmd.run(
'dart',
['fix', '--apply'],
workingDirectory: entity.parent.path,
logger: logger,
),
where: (entity) => !ignore.excludes(entity) && _isPubspec(entity),
cwd: cwd,
);
if (processes.isEmpty) throw PubspecNotFound();
await Future.wait<void>(processes);
}
/// Run tests (`dart test`).
/// Returns a list of exit codes for each test process.
static Future<List<int>> test({
required Logger logger,
String cwd = '.',
bool recursive = false,
bool checkIgnore = true,
bool showUncovered = false,
bool collectCoverage = false,
bool optimizePerformance = false,
Set<String> ignore = const {},
double? minCoverage,
String? excludeFromCoverage,
CoverageCollectionMode collectCoverageFrom = CoverageCollectionMode.imports,
String? randomSeed,
bool? forceAnsi,
List<String>? arguments,
void Function(String)? stdout,
void Function(String)? stderr,
GeneratorBuilder buildGenerator = MasonGenerator.fromBundle,
String? reportOn,
}) async {
return TestCLIRunner.test(
logger: logger,
testType: TestRunType.dart,
cwd: cwd,
recursive: recursive,
checkIgnore: checkIgnore,
showUncovered: showUncovered,
collectCoverage: collectCoverage,
optimizePerformance: optimizePerformance,
ignore: ignore,
minCoverage: minCoverage,
excludeFromCoverage: excludeFromCoverage,
collectCoverageFrom: collectCoverageFrom,
randomSeed: randomSeed,
forceAnsi: forceAnsi,
arguments: arguments,
stdout: stdout,
stderr: stderr,
reportOn: reportOn,
buildGenerator: buildGenerator,
);
}
}