Skip to content

Commit ea1f0b4

Browse files
authored
Add list command (#384)
Bump min SDK to 2.17
1 parent 362d5ce commit ea1f0b4

File tree

9 files changed

+272
-46
lines changed

9 files changed

+272
-46
lines changed

.github/workflows/dart.yml

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mono_repo/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## 6.3.0-dev
22

33
- Update to `subosito/flutter-action@v2.4.0`.
4-
- Require at least Dart >= 2.16.0
4+
- Require at least Dart >= 2.17.0
5+
- Add the `list` command.
56

67
## 6.2.2
78

mono_repo/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Global options:
3434
Available commands:
3535
check Check the state of the repository.
3636
generate Generates the CI configuration for child packages.
37+
list List all packages configured for mono_repo.
3738
presubmit Run the CI presubmits locally.
3839
pub Runs the `pub` command with the provided arguments across all packages.
3940
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pubspec_parse/pubspec_parse.dart';
6+
7+
import '../package_config.dart';
8+
import '../root_config.dart';
9+
import 'mono_repo_command.dart';
10+
11+
class ListCommand extends MonoRepoCommand {
12+
ListCommand() {
13+
argParser
14+
..addFlag(
15+
'only-published',
16+
abbr: 'p',
17+
help: 'Only list packages with a version and without publish_to set to '
18+
'none.',
19+
)
20+
..addMultiOption(
21+
'show',
22+
abbr: 's',
23+
help:
24+
'The properties of the package to show in a comma-seperated list.',
25+
allowed: Column.values.map((e) => e.name),
26+
allowedHelp: {for (var item in Column.values) item.name: item.help},
27+
defaultsTo: Column.values
28+
.where((element) => element.defaultsTo)
29+
.map((e) => e.name),
30+
);
31+
}
32+
33+
@override
34+
String get name => 'list';
35+
36+
@override
37+
String get description => 'List all packages configured for mono_repo.';
38+
39+
@override
40+
void run() => print(
41+
listPackages(
42+
rootConfig(),
43+
onlyPublished: argResults!['only-published'] as bool,
44+
showItems: (argResults!['show'] as List<String>)
45+
.map(
46+
(e) =>
47+
Column.values.singleWhere((element) => element.name == e),
48+
)
49+
.toSet(),
50+
).join('\n'),
51+
);
52+
}
53+
54+
enum Column {
55+
name(
56+
help: 'The name of the package as specified in the "name" field.',
57+
defaultsTo: true,
58+
),
59+
path(
60+
help: 'The path to the package relative to the root of the repository.',
61+
defaultsTo: true,
62+
),
63+
version(
64+
help: 'The version of the package as specified in the "version" field.',
65+
defaultsTo: false,
66+
),
67+
publishTo(
68+
help: 'The value of the "publish_to" field.',
69+
defaultsTo: false,
70+
);
71+
72+
const Column({
73+
required this.help,
74+
required this.defaultsTo,
75+
});
76+
77+
final String help;
78+
final bool defaultsTo;
79+
80+
String valueFor(PackageConfig cfg) {
81+
switch (this) {
82+
case Column.name:
83+
return cfg.pubspec.name;
84+
case Column.path:
85+
return cfg.relativePath;
86+
case Column.version:
87+
return cfg.pubspec.version?.toString() ?? '';
88+
case Column.publishTo:
89+
return cfg.pubspec.publishTo ?? '';
90+
}
91+
}
92+
}
93+
94+
Iterable<String> listPackages(
95+
RootConfig rootConfig, {
96+
required bool onlyPublished,
97+
required Set<Column> showItems,
98+
}) sync* {
99+
for (var pkg in rootConfig) {
100+
if (onlyPublished && !_published(pkg.pubspec)) {
101+
continue;
102+
}
103+
yield showItems.map((e) => e.valueFor(pkg)).join(',');
104+
}
105+
}
106+
107+
bool _published(Pubspec pubspec) =>
108+
pubspec.version != null && pubspec.publishTo != 'none';

mono_repo/lib/src/runner.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:args/command_runner.dart';
99

1010
import 'commands/check.dart';
1111
import 'commands/generate.dart';
12+
import 'commands/list_command.dart';
1213
import 'commands/mono_repo_command.dart';
1314
import 'commands/presubmit.dart';
1415
import 'commands/pub.dart';
@@ -18,6 +19,7 @@ final commands = List<Command<void>>.unmodifiable(
1819
[
1920
CheckCommand(),
2021
GenerateCommand(),
22+
ListCommand(),
2123
PresubmitCommand(),
2224
PubCommand(),
2325
],

mono_repo/mono_pkg.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ stages:
1010
- analyze: --fatal-infos .
1111
sdk: dev
1212
- analyze:
13-
sdk: 2.16.0
13+
sdk: 2.17.0
1414
- test:
1515
- test: -x yaml -P presubmit --test-randomize-ordering-seed=random
1616
os:
1717
- linux
1818
- windows
19-
sdk: [2.16.0, dev]
19+
sdk: [2.17.0, dev]
2020
- test: -t yaml --test-randomize-ordering-seed=random
2121
os:
2222
- linux
23-
sdk: [2.16.0, dev]
23+
sdk: [2.17.0, dev]
2424

2525
cache:
2626
directories:

mono_repo/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version: 6.3.0-dev
66
repository: https://github.com/google/mono_repo.dart
77

88
environment:
9-
sdk: '>=2.16.0 <3.0.0'
9+
sdk: '>=2.17.0 <3.0.0'
1010

1111
dependencies:
1212
args: ^2.0.0

0 commit comments

Comments
 (0)