Skip to content

Commit 1668517

Browse files
committed
change to --include-external
1 parent 62b5a7b commit 1668517

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"search" is passed, the page navigates to the first search result for its
44
value.
55
* [enhancement] added support for passing more than one `--header` or `--footer`
6-
* [enhancement] added the ability to `--include` libraries referenced by (but
7-
not directly inside) the project
6+
* [enhancement] added the ability to include libraries referenced by (but not
7+
directly inside) the project (`--include-external`)
88
* [bug] rev the analyzer version used to fix an issue generating docs for
99
Flutter
1010

bin/dartdoc.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ main(List<String> arguments) async {
7070

7171
List<String> excludeLibraries = args['exclude'];
7272
List<String> includeLibraries = args['include'];
73+
List<String> includeExternals = args['include-external'];
7374

7475
String url = args['hosted-url'];
7576
List<String> footerFilePaths = args['footer'].map(_resolveTildePath).toList();
@@ -126,7 +127,8 @@ main(List<String> arguments) async {
126127
initializeConfig(addCrossdart: addCrossdart, includeSource: includeSource);
127128

128129
var dartdoc = new DartDoc(inputDir, excludeLibraries, sdkDir, generators,
129-
outputDir, packageMeta, includeLibraries);
130+
outputDir, packageMeta, includeLibraries,
131+
includeExternals: includeExternals);
130132

131133
Chain.capture(() async {
132134
DartDocResults results = await dartdoc.generateDocs();
@@ -190,6 +192,8 @@ ArgParser _createArgsParser() {
190192
allowMultiple: true, help: 'library names to ignore');
191193
parser.addOption('include',
192194
allowMultiple: true, help: 'library names to generate docs for');
195+
parser.addOption('include-external',
196+
allowMultiple: true, help: 'additional (external) libraries to include');
193197
parser.addOption('hosted-url',
194198
help:
195199
'URL where the docs will be hosted (used to generate the sitemap).');

lib/dartdoc.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@ Future<List<Generator>> initGenerators(String url, List<String> headerFilePaths,
6060
/// directory.
6161
class DartDoc {
6262
final Directory rootDir;
63-
final List<String> excludes;
6463
final Directory sdkDir;
6564
final List<Generator> generators;
6665
final Directory outputDir;
6766
final PackageMeta packageMeta;
6867
final List<String> includes;
68+
final List<String> includeExternals;
69+
final List<String> excludes;
6970

7071
Stopwatch _stopwatch;
7172

7273
DartDoc(this.rootDir, this.excludes, this.sdkDir, this.generators,
73-
this.outputDir, this.packageMeta, this.includes);
74+
this.outputDir, this.packageMeta, this.includes,
75+
{this.includeExternals: const []});
7476

7577
/// Generate DartDoc documentation.
7678
///
@@ -85,14 +87,25 @@ class DartDoc {
8587
? const []
8688
: findFilesToDocumentInPackage(rootDir.path).toList();
8789

88-
List<LibraryElement> libraries = _parseLibraries(files, includes);
90+
List<LibraryElement> libraries = _parseLibraries(files, includeExternals);
8991

90-
// remove excluded libraries
91-
excludes.forEach((pattern) {
92-
libraries.removeWhere((lib) {
93-
return lib.name.startsWith(pattern) || lib.name == pattern;
92+
if (includes != null && includes.isNotEmpty) {
93+
Iterable knownLibraryNames = libraries.map((l) => l.name);
94+
Set notFound =
95+
new Set.from(includes).difference(new Set.from(knownLibraryNames));
96+
if (notFound.isNotEmpty) {
97+
throw 'Did not find: [${notFound.join(', ')}] in '
98+
'known libraries: [${knownLibraryNames.join(', ')}]';
99+
}
100+
libraries.removeWhere((lib) => !includes.contains(lib.name));
101+
} else {
102+
// remove excluded libraries
103+
excludes.forEach((pattern) {
104+
libraries.removeWhere((lib) {
105+
return lib.name.startsWith(pattern) || lib.name == pattern;
106+
});
94107
});
95-
});
108+
}
96109

97110
if (includes.isNotEmpty || excludes.isNotEmpty) {
98111
print('generating docs for libraries ${libraries.join(', ')}\n');
@@ -121,7 +134,7 @@ class DartDoc {
121134
}
122135

123136
List<LibraryElement> _parseLibraries(
124-
List<String> files, List<String> includes) {
137+
List<String> files, List<String> includeExternals) {
125138
Set<LibraryElement> libraries = new Set();
126139
DartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDir.path));
127140
List<UriResolver> resolvers = [];
@@ -206,10 +219,10 @@ class DartDoc {
206219
result = context.performAnalysisTask();
207220
}
208221

209-
// Use the includes.
222+
// Use the includeExternals.
210223
for (Source source in context.librarySources) {
211224
LibraryElement library = context.computeLibraryElement(source);
212-
if (includes.contains(Library.getLibraryName(library))) {
225+
if (includeExternals.contains(Library.getLibraryName(library))) {
213226
libraries.add(library);
214227
}
215228
}

test/dartdoc_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ void main() {
7373
test('generate docs including a single library', () async {
7474
PackageMeta meta = new PackageMeta.fromDir(testPackageDir);
7575
DartDoc dartdoc = new DartDoc(
76-
testPackageDir, [], getSdkDir(), [], tempDir, meta, ['dart.core']);
76+
testPackageDir, [], getSdkDir(), [], tempDir, meta, ['fake']);
7777

7878
DartDocResults results = await dartdoc.generateDocs();
7979
expect(results.package, isNotNull);
8080

8181
Package p = results.package;
8282
expect(p.name, 'test_package');
8383
expect(p.hasDocumentationFile, isTrue);
84-
expect(p.libraries.map((lib) => lib.name), contains('dart:core'));
84+
expect(p.libraries, hasLength(1));
8585
expect(p.libraries.map((lib) => lib.name), contains('fake'));
8686
});
8787

0 commit comments

Comments
 (0)