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

Unified Diff: utils/pub/package.dart

Issue 12090081: Add a Pub validator for READMEs that are invalid utf-8. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 11 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 | « utils/pub/io.dart ('k') | utils/pub/validator.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/package.dart
diff --git a/utils/pub/package.dart b/utils/pub/package.dart
index f62e2becd0ffbda4ff69ee4a14c900e1a78a3cde..15fcb97b65874279b40ab650285091dcb6ba299e 100644
--- a/utils/pub/package.dart
+++ b/utils/pub/package.dart
@@ -11,6 +11,8 @@ import 'source.dart';
import 'source_registry.dart';
import 'version.dart';
+final _README_REGEXP = new RegExp(r"^README($|\.)", caseSensitive: false);
+
/// A named, versioned, unit of code and resource reuse.
class Package {
/// Loads the package whose root directory is [packageDir]. [name] is the
@@ -58,6 +60,26 @@ class Package {
/// specified in the pubspec when this package depends on another.
Collection<PackageRef> get dependencies => pubspec.dependencies;
+ /// Returns the path to the README file at the root of the entrypoint, or null
+ /// if no README file is found. If multiple READMEs are found, this uses the
+ /// same conventions as pub.dartlang.org for choosing the primary one: the
+ /// README with the fewest extensions that is lexically ordered first is
+ /// chosen.
+ Future<String> get readmePath {
+ return listDir(dir).then((entries) {
+ var readmes = entries.where((entry) => entry.contains(_README_REGEXP));
+ if (readmes.isEmpty) return;
+
+ return readmes.min((readme1, readme2) {
+ var extensions1 = ".".allMatches(readme1).length;
+ var extensions2 = ".".allMatches(readme2).length;
+ var comparison = extensions1.compareTo(extensions2);
+ if (comparison != 0) return comparison;
+ return readme1.compareTo(readme2);
+ });
+ });
+ }
+
/// Constructs a package with the given pubspec. The package will have no
/// directory associated with it.
Package.inMemory(this.pubspec)
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/validator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698