Index: utils/pub/entrypoint.dart |
diff --git a/utils/pub/entrypoint.dart b/utils/pub/entrypoint.dart |
index 30bfeb1650a37f6af89274ae9180f255b30578eb..c830dd7bbd2965741df16dfa852279319f877312 100644 |
--- a/utils/pub/entrypoint.dart |
+++ b/utils/pub/entrypoint.dart |
@@ -14,6 +14,8 @@ import 'utils.dart'; |
import 'version.dart'; |
import 'version_solver.dart'; |
+final _README_REGEXP = new RegExp(r"^README($|\.)", caseSensitive: false); |
+ |
/// Pub operates over a directed graph of dependencies that starts at a root |
/// "entrypoint" package. This is typically the package where the current |
/// working directory is located. An entrypoint knows the [root] package it is |
@@ -54,6 +56,26 @@ class Entrypoint { |
/// The path to this "packages" directory. |
String get path => join(root.dir, 'packages'); |
+ /// 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. |
Bob Nystrom
2013/01/31 19:08:29
How about moving this to Package? It's not specifi
nweiz
2013/01/31 21:39:10
Done.
|
+ Future<String> get readmePath { |
+ return listDir(root.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); |
+ }); |
+ }); |
+ } |
+ |
/// Ensures that the package identified by [id] is installed to the directory. |
/// Returns the resolved [PackageId]. |
/// |