Skip to content

Commit 8a1d977

Browse files
authored
Add include/exclude to supported config options (#1700)
* Add include/exclude to supported config options * Cleanup and more consistently use buildDartdoc in test * dartfmt and sort options in readme
1 parent cad1639 commit 8a1d977

23 files changed

+103
-59
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ Unrecognized options will be ignored. Supported options:
111111
112112
* **categoryOrder**: Specify the order of categories, below, for display in the sidebar and
113113
the package page.
114+
* **exclude**: Specify a list of library names to avoid generating docs for,
115+
overriding any specified in include.
116+
* **include**: Specify a list of library names to generate docs for, ignoring all others.
114117
* **linkTo**: For other packages depending on this one, if this map is defined those packages
115118
will use the settings here to control how hyperlinks to the package are generated.
116119
This will override the default for packages hosted on pub.dartlang.org.
@@ -133,12 +136,10 @@ as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows.
133136
* **ambiguousReexportScorerMinConfidence**: The ambiguous reexport scorer will emit a warning if
134137
it is not at least this confident. Default: 0.1
135138
* **examplePathPrefix**: Specify the prefix for the example paths, defaulting to the project root.
136-
* **exclude**: Specify a list of library names to avoid generating docs for, ignoring all others.
137139
* **favicon**: A path to a favicon for the generated docs.
138140
* **footer**: A list of paths to footer files containing HTML text.
139141
* **footerText**: A list of paths to text files for optional text next to the package name and version
140142
* **header**: A list of paths to header files containing HTML text.
141-
* **include**: Specify a list of library names to generate docs for, ignoring all others.
142143
* **includeExternal**: Specify a list of library filenames to add to the list of documented libraries.
143144

144145
### Categories

bin/dartdoc.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ main(List<String> arguments) async {
4242
createGeneratorOptions,
4343
]);
4444

45-
DartdocProgramOptionContext config =
46-
new DartdocProgramOptionContext(optionSet, Directory.current);
47-
4845
try {
4946
optionSet.parseArguments(arguments);
5047
} on FormatException catch (e) {
@@ -63,6 +60,8 @@ main(List<String> arguments) async {
6360
_printVersionAndExit(optionSet.argParser);
6461
}
6562

63+
DartdocProgramOptionContext config =
64+
new DartdocProgramOptionContext(optionSet, null);
6665
startLogging(config);
6766

6867
Directory outputDir = new Directory(config.output);

lib/src/dartdoc_options.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,17 @@ class DartdocOptionContext {
883883
// TODO(jcollins-g): Allow passing in structured data to initialize a
884884
// [DartdocOptionContext]'s arguments instead of having to parse strings
885885
// via optionSet.
886+
/// If [entity] is null, assume this is the initialization case and use
887+
/// the inputDir flag to determine the context.
886888
DartdocOptionContext(this.optionSet, FileSystemEntity entity) {
887-
context = new Directory(pathLib
888-
.canonicalize(entity is File ? entity.parent.path : entity.path));
889+
if (entity == null) {
890+
String inputDir = optionSet['inputDir'].valueAt(Directory.current) ??
891+
Directory.current.path;
892+
context = new Directory(inputDir);
893+
} else {
894+
context = new Directory(pathLib
895+
.canonicalize(entity is File ? entity.parent.path : entity.path));
896+
}
889897
}
890898

891899
/// Build a DartdocOptionContext from an analyzer element (using its source

lib/src/model.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,7 +3597,8 @@ abstract class ModelElement extends Canonicalization
35973597
width = int.parse(match[2]);
35983598
} on FormatException {
35993599
warn(PackageWarning.invalidParameter,
3600-
message: 'An animation has an invalid width ($name): ${match[2]}. The '
3600+
message:
3601+
'An animation has an invalid width ($name): ${match[2]}. The '
36013602
'width must be an integer.');
36023603
return '';
36033604
}
@@ -3606,7 +3607,8 @@ abstract class ModelElement extends Canonicalization
36063607
height = int.parse(match[3]);
36073608
} on FormatException {
36083609
warn(PackageWarning.invalidParameter,
3609-
message: 'An animation has an invalid height ($name): ${match[3]}. The '
3610+
message:
3611+
'An animation has an invalid height ($name): ${match[3]}. The '
36103612
'height must be an integer.');
36113613
return '';
36123614
}
@@ -3615,7 +3617,8 @@ abstract class ModelElement extends Canonicalization
36153617
movieUrl = Uri.parse(match[4]);
36163618
} on FormatException catch (e) {
36173619
warn(PackageWarning.invalidParameter,
3618-
message: 'An animation URL could not be parsed ($name): ${match[4]}\n$e');
3620+
message:
3621+
'An animation URL could not be parsed ($name): ${match[4]}\n$e');
36193622
return '';
36203623
}
36213624
final String overlayName = '${name}_play_button_';
@@ -3655,7 +3658,7 @@ abstract class ModelElement extends Canonicalization
36553658
</video>
36563659
</div>
36573660
3658-
'''; // String must end at beginning of line, or following inline text will be
3661+
'''; // String must end at beginning of line, or following inline text will be
36593662
// indented.
36603663
});
36613664
}
@@ -5742,7 +5745,8 @@ class PackageBuilder {
57425745
if (config.include.isNotEmpty) {
57435746
Iterable knownLibraryNames = libraries.map((l) => l.name);
57445747
Set notFound = new Set.from(config.include)
5745-
.difference(new Set.from(knownLibraryNames));
5748+
.difference(new Set.from(knownLibraryNames))
5749+
.difference(new Set.from(config.exclude));
57465750
if (notFound.isNotEmpty) {
57475751
throw 'Did not find: [${notFound.join(', ')}] in '
57485752
'known libraries: [${knownLibraryNames.join(', ')}]';

test/dartdoc_test.dart

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'dart:io';
99

1010
import 'package:dartdoc/dartdoc.dart';
1111
import 'package:dartdoc/src/model.dart';
12-
import 'package:dartdoc/src/package_meta.dart';
1312
import 'package:path/path.dart' as pathLib;
1413
import 'package:test/test.dart';
1514

@@ -28,24 +27,51 @@ void main() {
2827
delete(tempDir);
2928
});
3029

31-
Future<DartdocGeneratorOptionContext> generatorContextFromArgvTemp(
32-
List<String> argv) async {
33-
return await generatorContextFromArgv(argv..addAll(outputParam));
30+
Future<Dartdoc> buildDartdoc(
31+
List<String> argv, Directory packageRoot) async {
32+
return await Dartdoc.withDefaultGenerators(await generatorContextFromArgv(
33+
argv..addAll(['--input', packageRoot.path])..addAll(outputParam)));
3434
}
3535

36+
group('include/exclude parameters', () {
37+
test('with config file', () async {
38+
Dartdoc dartdoc = await buildDartdoc([], testPackageImportExport);
39+
DartdocResults results = await dartdoc.generateDocs();
40+
PackageGraph p = results.packageGraph;
41+
expect(p.localPublicLibraries.map((l) => l.name),
42+
orderedEquals(['explicitly_included', 'more_included']));
43+
});
44+
45+
test('with include command line argument', () async {
46+
Dartdoc dartdoc = await buildDartdoc(
47+
['--include', 'another_included'], testPackageImportExport);
48+
DartdocResults results = await dartdoc.generateDocs();
49+
PackageGraph p = results.packageGraph;
50+
expect(p.localPublicLibraries.length, equals(1));
51+
expect(p.localPublicLibraries.first.name, equals('another_included'));
52+
});
53+
54+
test('with exclude command line argument', () async {
55+
Dartdoc dartdoc = await buildDartdoc(
56+
['--exclude', 'more_included'], testPackageImportExport);
57+
DartdocResults results = await dartdoc.generateDocs();
58+
PackageGraph p = results.packageGraph;
59+
expect(p.localPublicLibraries.length, equals(1));
60+
expect(
61+
p.localPublicLibraries.first.name, equals('explicitly_included'));
62+
});
63+
});
64+
3665
test('package without version produces valid semver in docs', () async {
37-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
38-
await generatorContextFromArgvTemp(
39-
['--input', testPackageMinimumDir.path]));
66+
Dartdoc dartdoc = await buildDartdoc([], testPackageMinimumDir);
4067
DartdocResults results = await dartdoc.generateDocs();
4168
PackageGraph p = results.packageGraph;
42-
assert(p.defaultPackage.version == '0.0.0-unknown');
69+
expect(p.defaultPackage.version, equals('0.0.0-unknown'));
4370
});
4471

4572
test('basic interlinking test', () async {
46-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
47-
await generatorContextFromArgvTemp(
48-
['--input', testPackageDir.path, '--link-to-remote']));
73+
Dartdoc dartdoc =
74+
await buildDartdoc(['--link-to-remote'], testPackageDir);
4975
DartdocResults results = await dartdoc.generateDocs();
5076
PackageGraph p = results.packageGraph;
5177
Package tuple = p.publicPackages.firstWhere((p) => p.name == 'tuple');
@@ -73,8 +99,7 @@ void main() {
7399

74100
test('generate docs for ${pathLib.basename(testPackageDir.path)} works',
75101
() async {
76-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
77-
await generatorContextFromArgvTemp(['--input', testPackageDir.path]));
102+
Dartdoc dartdoc = await buildDartdoc([], testPackageDir);
78103

79104
DartdocResults results = await dartdoc.generateDocs();
80105
expect(results.packageGraph, isNotNull);
@@ -89,9 +114,7 @@ void main() {
89114

90115
test('generate docs for ${pathLib.basename(testPackageBadDir.path)} fails',
91116
() async {
92-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
93-
await generatorContextFromArgvTemp(
94-
['--input', testPackageBadDir.path]));
117+
Dartdoc dartdoc = await buildDartdoc([], testPackageBadDir);
95118

96119
try {
97120
await dartdoc.generateDocs();
@@ -102,9 +125,7 @@ void main() {
102125
});
103126

104127
test('generate docs for a package that does not have a readme', () async {
105-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
106-
await generatorContextFromArgvTemp(
107-
['--input', testPackageWithNoReadme.path]));
128+
Dartdoc dartdoc = await buildDartdoc([], testPackageWithNoReadme);
108129

109130
DartdocResults results = await dartdoc.generateDocs();
110131
expect(results.packageGraph, isNotNull);
@@ -117,9 +138,8 @@ void main() {
117138
});
118139

119140
test('generate docs including a single library', () async {
120-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
121-
await generatorContextFromArgvTemp(
122-
['--input', testPackageDir.path, '--include', 'fake']));
141+
Dartdoc dartdoc =
142+
await buildDartdoc(['--include', 'fake'], testPackageDir);
123143

124144
DartdocResults results = await dartdoc.generateDocs();
125145
expect(results.packageGraph, isNotNull);
@@ -132,9 +152,8 @@ void main() {
132152
});
133153

134154
test('generate docs excluding a single library', () async {
135-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
136-
await generatorContextFromArgvTemp(
137-
['--input', testPackageDir.path, '--exclude', 'fake']));
155+
Dartdoc dartdoc =
156+
await buildDartdoc(['--exclude', 'fake'], testPackageDir);
138157

139158
DartdocResults results = await dartdoc.generateDocs();
140159
expect(results.packageGraph, isNotNull);
@@ -148,11 +167,7 @@ void main() {
148167
});
149168

150169
test('generate docs for package with embedder yaml', () async {
151-
PackageMeta meta = new PackageMeta.fromDir(testPackageWithEmbedderYaml);
152-
if (meta.needsPubGet) meta.runPubGet();
153-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(
154-
await generatorContextFromArgvTemp(
155-
['--input', testPackageWithEmbedderYaml.path]));
170+
Dartdoc dartdoc = await buildDartdoc([], testPackageWithEmbedderYaml);
156171

157172
DartdocResults results = await dartdoc.generateDocs();
158173
expect(results.packageGraph, isNotNull);

test/model_test.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,11 @@ void main() {
576576
isTrue);
577577
});
578578
test("Doesn't place animations in one line doc", () {
579-
expect(
580-
withAnimationInline.oneLineDoc, isNot(contains('<video')));
581-
expect(
582-
withAnimationInline.documentation, contains('<video'));
579+
expect(withAnimationInline.oneLineDoc, isNot(contains('<video')));
580+
expect(withAnimationInline.documentation, contains('<video'));
583581
});
584582
test("Handles animations inline properly", () {
585-
expect(
586-
withAnimationInline.documentation, isNot(contains(' works')));
583+
expect(withAnimationInline.documentation, isNot(contains(' works')));
587584
});
588585
});
589586

test/src/utils.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ final Directory testPackageWithEmbedderYaml =
2727
new Directory('testing/test_package_embedder_yaml');
2828
final Directory testPackageWithNoReadme =
2929
new Directory('testing/test_package_small');
30+
final Directory testPackageImportExport =
31+
new Directory('testing/test_package_include_exclude');
3032

3133
/// Convenience factory to build a [DartdocGeneratorOptionContext] and associate
32-
/// it with a [DartdocOptionSet] based on the current working directory.
34+
/// it with a [DartdocOptionSet] based on the current working directory and/or
35+
/// the '--input' flag.
3336
Future<DartdocGeneratorOptionContext> generatorContextFromArgv(
3437
List<String> argv) async {
3538
DartdocOptionSet optionSet = await DartdocOptionSet.fromOptionGenerators(
3639
'dartdoc', [createDartdocOptions, createGeneratorOptions]);
3740
optionSet.parseArguments(argv);
38-
return new DartdocGeneratorOptionContext(optionSet, Directory.current);
41+
return new DartdocGeneratorOptionContext(optionSet, null);
3942
}
4043

4144
/// Convenience factory to build a [DartdocOptionContext] and associate it with a

testing/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*/doc/api/
2+
*/ios
3+
*/pubspec.lock
4+
*/.packages

testing/test_package/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

testing/test_package_bad/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

testing/test_package_flutter_plugin/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

testing/test_package_imported/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// This is a libraryish thing in the wrong place.
2+
library included;
3+
4+
void main() {
5+
print('hello, world');
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library not_included;
2+
3+
void main() {
4+
print('another binary not included');
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dartdoc:
2+
include: ['explicitly_included', 'more_included']
3+
exclude: ['excluded']
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library another_included;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library excluded;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library explicitly_included;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library more_included;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library not_explicitly_included;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library included_under_src;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: test_package_include_exclude
2+
version: 0.0.1

testing/test_package_minimum/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)