@@ -40,7 +40,7 @@ export 'src/package_meta.dart';
4040
4141const String name = 'dartdoc' ;
4242// Update when pubspec version changes.
43- const String version = '0.9.13 ' ;
43+ const String version = '0.10.0 ' ;
4444
4545final String defaultOutDir = path.join ('doc' , 'api' );
4646
@@ -134,6 +134,7 @@ class DartDoc {
134134 ? const []
135135 : findFilesToDocumentInPackage (rootDir.path).toList ();
136136
137+ // TODO(jcollins-g): seems like most of this belongs in the Package constructor
137138 List <LibraryElement > libraries = _parseLibraries (files, includeExternals);
138139
139140 if (includes != null && includes.isNotEmpty) {
@@ -154,21 +155,27 @@ class DartDoc {
154155 });
155156 }
156157
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;
163159 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+ });
168169 }
170+ package = new Package (libraries, packageMeta);
171+
172+ print (
173+ 'generating docs for libraries ${package .libraries .map ((Library l ) => l .name ).join (', ' )}\n ' );
169174
170175 // 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);
172179
173180 // Create the out directory.
174181 if (! outputDir.existsSync ()) outputDir.createSync (recursive: true );
@@ -179,11 +186,11 @@ class DartDoc {
179186
180187 double seconds = _stopwatch.elapsedMilliseconds / 1000.0 ;
181188 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' } "
183190 "in ${seconds .toStringAsFixed (1 )} seconds." );
184191
185- if (libraries.isEmpty) {
186- print (
192+ if (package. libraries.isEmpty) {
193+ stderr. write (
187194 "\n dartdoc could not find any libraries to document. Run `pub get` and try again." );
188195 }
189196
@@ -192,7 +199,7 @@ class DartDoc {
192199
193200 List <LibraryElement > _parseLibraries (
194201 List <String > files, List <String > includeExternals) {
195- List <LibraryElement > libraries = [] ;
202+ Set <LibraryElement > libraries = new Set () ;
196203 DartSdk sdk = new FolderBasedDartSdk (PhysicalResourceProvider .INSTANCE ,
197204 PhysicalResourceProvider .INSTANCE .getFolder (sdkDir.path));
198205 List <UriResolver > resolvers = [];
@@ -257,7 +264,7 @@ class DartDoc {
257264 sources.add (source);
258265 if (context.computeKindOf (source) == SourceKind .LIBRARY ) {
259266 LibraryElement library = context.computeLibraryElement (source);
260- libraries.add (library);
267+ if ( ! isPrivate (library)) libraries.add (library);
261268 }
262269 }
263270
@@ -281,11 +288,35 @@ class DartDoc {
281288 LibraryElement library = context.computeLibraryElement (source);
282289 String libraryName = Library .getLibraryName (library);
283290 var fullPath = source.fullName;
291+
284292 if (includeExternals.any ((string) => fullPath.endsWith (string))) {
285293 if (libraries.map (Library .getLibraryName).contains (libraryName)) {
286294 continue ;
287295 }
288296 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);
289320 }
290321 }
291322
@@ -376,26 +407,3 @@ class _Error implements Comparable<_Error> {
376407 @override
377408 String toString () => '[${severityName }] ${description }' ;
378409}
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