@@ -40,7 +40,7 @@ export 'src/package_meta.dart';
40
40
41
41
const String name = 'dartdoc' ;
42
42
// Update when pubspec version changes.
43
- const String version = '0.9.13 ' ;
43
+ const String version = '0.10.0 ' ;
44
44
45
45
final String defaultOutDir = path.join ('doc' , 'api' );
46
46
@@ -134,6 +134,7 @@ class DartDoc {
134
134
? const []
135
135
: findFilesToDocumentInPackage (rootDir.path).toList ();
136
136
137
+ // TODO(jcollins-g): seems like most of this belongs in the Package constructor
137
138
List <LibraryElement > libraries = _parseLibraries (files, includeExternals);
138
139
139
140
if (includes != null && includes.isNotEmpty) {
@@ -154,21 +155,27 @@ class DartDoc {
154
155
});
155
156
}
156
157
157
- if (includes.isNotEmpty || excludes.isNotEmpty) {
158
- print ('generating docs for libraries ${libraries .join (', ' )}\n ' );
159
- }
160
-
161
- Package package = new Package (libraries, packageMeta);
162
-
158
+ Package package;
163
159
if (config != null && config.autoIncludeDependencies) {
164
- final newLibraryElements =
165
- _buildLibrariesWithAutoincludedDependencies (package);
166
- Library .clearLibraryMap ();
167
- package = new Package (newLibraryElements, packageMeta);
160
+ package = Package .withAutoIncludedDependencies (libraries, packageMeta);
161
+ libraries = package.libraries.map ((l) => l.element).toList ();
162
+ // remove excluded libraries again, in case they are picked up through
163
+ // dependencies.
164
+ excludes.forEach ((pattern) {
165
+ libraries.removeWhere ((lib) {
166
+ return lib.name.startsWith (pattern) || lib.name == pattern;
167
+ });
168
+ });
168
169
}
170
+ package = new Package (libraries, packageMeta);
171
+
172
+ print (
173
+ 'generating docs for libraries ${package .libraries .map ((Library l ) => l .name ).join (', ' )}\n ' );
169
174
170
175
// Go through docs of every model element in package to prebuild the macros index
171
- package.allModelElements.forEach ((m) => m.documentation);
176
+ // TODO(jcollins-g): move index building into a cached-on-demand generation
177
+ // like most other bits in [Package].
178
+ package.allCanonicalModelElements.forEach ((m) => m.documentation);
172
179
173
180
// Create the out directory.
174
181
if (! outputDir.existsSync ()) outputDir.createSync (recursive: true );
@@ -179,11 +186,11 @@ class DartDoc {
179
186
180
187
double seconds = _stopwatch.elapsedMilliseconds / 1000.0 ;
181
188
print (
182
- "\n Documented ${libraries .length } librar${libraries .length == 1 ? 'y' : 'ies' } "
189
+ "\n Documented ${package . libraries .length } librar${package . libraries .length == 1 ? 'y' : 'ies' } "
183
190
"in ${seconds .toStringAsFixed (1 )} seconds." );
184
191
185
- if (libraries.isEmpty) {
186
- print (
192
+ if (package. libraries.isEmpty) {
193
+ stderr. write (
187
194
"\n dartdoc could not find any libraries to document. Run `pub get` and try again." );
188
195
}
189
196
@@ -192,7 +199,7 @@ class DartDoc {
192
199
193
200
List <LibraryElement > _parseLibraries (
194
201
List <String > files, List <String > includeExternals) {
195
- List <LibraryElement > libraries = [] ;
202
+ Set <LibraryElement > libraries = new Set () ;
196
203
DartSdk sdk = new FolderBasedDartSdk (PhysicalResourceProvider .INSTANCE ,
197
204
PhysicalResourceProvider .INSTANCE .getFolder (sdkDir.path));
198
205
List <UriResolver > resolvers = [];
@@ -257,7 +264,7 @@ class DartDoc {
257
264
sources.add (source);
258
265
if (context.computeKindOf (source) == SourceKind .LIBRARY ) {
259
266
LibraryElement library = context.computeLibraryElement (source);
260
- libraries.add (library);
267
+ if ( ! isPrivate (library)) libraries.add (library);
261
268
}
262
269
}
263
270
@@ -281,11 +288,35 @@ class DartDoc {
281
288
LibraryElement library = context.computeLibraryElement (source);
282
289
String libraryName = Library .getLibraryName (library);
283
290
var fullPath = source.fullName;
291
+
284
292
if (includeExternals.any ((string) => fullPath.endsWith (string))) {
285
293
if (libraries.map (Library .getLibraryName).contains (libraryName)) {
286
294
continue ;
287
295
}
288
296
libraries.add (library);
297
+ } else if (config != null &&
298
+ config.autoIncludeDependencies &&
299
+ libraryName != '' ) {
300
+ File searchFile = new File (fullPath);
301
+ searchFile =
302
+ new File (path.join (searchFile.parent.path, 'pubspec.yaml' ));
303
+ bool foundLibSrc = false ;
304
+ while (! foundLibSrc && searchFile.parent != null ) {
305
+ if (searchFile.existsSync ()) break ;
306
+ List <String > pathParts = path.split (searchFile.parent.path);
307
+ // This is a pretty intensely hardcoded convention, but there seems to
308
+ // to be no other way to identify what might be a "top level" library
309
+ // here. If lib/src is in the path between the file and the pubspec,
310
+ // assume that this is supposed to be private.
311
+ if (pathParts.length < 2 ) break ;
312
+ pathParts = pathParts.sublist (pathParts.length - 2 , pathParts.length);
313
+ foundLibSrc =
314
+ path.join (pathParts[0 ], pathParts[1 ]) == path.join ('lib' , 'src' );
315
+ searchFile = new File (
316
+ path.join (searchFile.parent.parent.path, 'pubspec.yaml' ));
317
+ }
318
+ if (foundLibSrc) continue ;
319
+ libraries.add (library);
289
320
}
290
321
}
291
322
@@ -376,26 +407,3 @@ class _Error implements Comparable<_Error> {
376
407
@override
377
408
String toString () => '[${severityName }] ${description }' ;
378
409
}
379
-
380
- Iterable <LibraryElement > _buildLibrariesWithAutoincludedDependencies (
381
- Package package) {
382
- final List <LibraryElement > newLibraryElements = []
383
- ..addAll (package.libraries.map ((l) => l.element as LibraryElement ));
384
-
385
- package.allModelElements.forEach ((modelElement) {
386
- modelElement.usedElements.forEach ((used) {
387
- if (used != null && used.modelType != null ) {
388
- final ModelElement modelTypeElement = used.modelType.element;
389
- final library = package.findLibraryFor (modelTypeElement.element);
390
- if (library == null && modelTypeElement.library != null ) {
391
- if (! newLibraryElements.contains (modelTypeElement.library.element) &&
392
- ! modelTypeElement.library.name.startsWith ("dart:" )) {
393
- newLibraryElements.add (modelTypeElement.library.element);
394
- }
395
- }
396
- }
397
- });
398
- });
399
-
400
- return newLibraryElements;
401
- }
0 commit comments