Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Unified Diff: pkg/docgen/lib/docgen.dart

Issue 196963003: pkg/docgen: dir that look like packages, only document the contents of lib (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/docgen/lib/src/io.dart » ('j') | pkg/docgen/lib/src/io.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/docgen/lib/docgen.dart
diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart
index 4aaef720f57d5eab810a531eafa9082095b9f6d7..da817fe11db98798d1cb57f802f1507cb924eb88 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -576,9 +576,10 @@ class _Generator {
// To avoid anaylzing package files twice, only files with paths not
// containing '/packages' will be added. The only exception is if the file
// to analyze already has a '/package' in its path.
- var files = listDir(packageName, recursive: true).where(
- (f) => f.endsWith('.dart') && (!f.contains('${path.separator}packages')
- || packageName.contains('${path.separator}packages'))).toList();
+ var files = listDir(packageName, recursive: true, listDir: _packageDirList)
+ .where((f) => f.endsWith('.dart')
+ && (!f.contains('${path.separator}packages')
+ || packageName.contains('${path.separator}packages'))).toList();
files.forEach((String lib) {
// Only include libraries at the top level of "lib"
@@ -596,6 +597,28 @@ class _Generator {
return libraries;
}
+ /// If [dir] contains both a `lib` directory and a `pubspec.yaml` file treat
+ /// it like a package and only return the `lib` dir.
+ ///
+ /// This ensures that packages don't have non-`lib` content documented.
+ static List<FileSystemEntity> _packageDirList(Directory dir) {
+ var entities = dir.listSync();
+
+ var pubspec = entities
+ .firstWhere((e) => e is File &&
+ path.basename(e.path) == 'pubspec.yaml', orElse: () => null);
+
+ var libDir = entities
+ .firstWhere((e) => e is Directory &&
+ path.basename(e.path) == 'lib', orElse: () => null);
+
+ if (pubspec != null && libDir != null) {
+ return [libDir];
+ } else {
+ return entities;
+ }
+ }
+
/// All of the directories for our dependent packages
/// If this is not a package, return an empty list.
static List<String> _allDependentPackageDirs(String packageDirectory) {
« no previous file with comments | « no previous file | pkg/docgen/lib/src/io.dart » ('j') | pkg/docgen/lib/src/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698