| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub.package; | 5 library pub.package; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }).toList(); | 88 }).toList(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /// Returns the path to the README file at the root of the entrypoint, or null | 91 /// Returns the path to the README file at the root of the entrypoint, or null |
| 92 /// if no README file is found. | 92 /// if no README file is found. |
| 93 /// | 93 /// |
| 94 /// If multiple READMEs are found, this uses the same conventions as | 94 /// If multiple READMEs are found, this uses the same conventions as |
| 95 /// pub.dartlang.org for choosing the primary one: the README with the fewest | 95 /// pub.dartlang.org for choosing the primary one: the README with the fewest |
| 96 /// extensions that is lexically ordered first is chosen. | 96 /// extensions that is lexically ordered first is chosen. |
| 97 String get readmePath { | 97 String get readmePath { |
| 98 var readmes = listFiles(recursive: false).map(p.basename). | 98 var readmes = listFiles(recursive: false, useGitIgnore: true) |
| 99 where((entry) => entry.contains(_README_REGEXP)); | 99 .map(p.basename) |
| 100 .where((entry) => entry.contains(_README_REGEXP)); |
| 100 if (readmes.isEmpty) return null; | 101 if (readmes.isEmpty) return null; |
| 101 | 102 |
| 102 return p.join(dir, readmes.reduce((readme1, readme2) { | 103 return p.join(dir, readmes.reduce((readme1, readme2) { |
| 103 var extensions1 = ".".allMatches(readme1).length; | 104 var extensions1 = ".".allMatches(readme1).length; |
| 104 var extensions2 = ".".allMatches(readme2).length; | 105 var extensions2 = ".".allMatches(readme2).length; |
| 105 var comparison = extensions1.compareTo(extensions2); | 106 var comparison = extensions1.compareTo(extensions2); |
| 106 if (comparison == 0) comparison = readme1.compareTo(readme2); | 107 if (comparison == 0) comparison = readme1.compareTo(readme2); |
| 107 return (comparison <= 0) ? readme1 : readme2; | 108 return (comparison <= 0) ? readme1 : readme2; |
| 108 })); | 109 })); |
| 109 } | 110 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 static final _WHITELISTED_FILES = const ['.htaccess']; | 188 static final _WHITELISTED_FILES = const ['.htaccess']; |
| 188 | 189 |
| 189 /// A set of patterns that match paths to blacklisted files. | 190 /// A set of patterns that match paths to blacklisted files. |
| 190 static final _blacklistedFiles = createFileFilter(['pubspec.lock']); | 191 static final _blacklistedFiles = createFileFilter(['pubspec.lock']); |
| 191 | 192 |
| 192 /// A set of patterns that match paths to blacklisted directories. | 193 /// A set of patterns that match paths to blacklisted directories. |
| 193 static final _blacklistedDirs = createDirectoryFilter(['packages']); | 194 static final _blacklistedDirs = createDirectoryFilter(['packages']); |
| 194 | 195 |
| 195 /// Returns a list of files that are considered to be part of this package. | 196 /// Returns a list of files that are considered to be part of this package. |
| 196 /// | 197 /// |
| 197 /// If this is a Git repository, this will respect .gitignore; otherwise, it | |
| 198 /// will return all non-hidden, non-blacklisted files. | |
| 199 /// | |
| 200 /// If [beneath] is passed, this will only return files beneath that path, | 198 /// If [beneath] is passed, this will only return files beneath that path, |
| 201 /// which is expected to be relative to the package's root directory. If | 199 /// which is expected to be relative to the package's root directory. If |
| 202 /// [recursive] is true, this will return all files beneath that path; | 200 /// [recursive] is true, this will return all files beneath that path; |
| 203 /// otherwise, it will only return files one level beneath it. | 201 /// otherwise, it will only return files one level beneath it. |
| 204 /// | 202 /// |
| 205 /// If [useGitIgnore] is passed, this will take the .gitignore rules into | 203 /// If [useGitIgnore] is passed, this will take the .gitignore rules into |
| 206 /// account if the package's root directory is a Git repository. | 204 /// account if the root directory of the package is (or is contained within) a |
| 205 /// Git repository. |
| 207 /// | 206 /// |
| 208 /// Note that the returned paths won't always be beneath [dir]. To safely | 207 /// Note that the returned paths won't always be beneath [dir]. To safely |
| 209 /// convert them to paths relative to the package root, use [relative]. | 208 /// convert them to paths relative to the package root, use [relative]. |
| 210 List<String> listFiles({String beneath, bool recursive: true, | 209 List<String> listFiles({String beneath, bool recursive: true, |
| 211 bool useGitIgnore: false}) { | 210 bool useGitIgnore: false}) { |
| 212 // An in-memory package has no files. | 211 // An in-memory package has no files. |
| 213 if (dir == null) return []; | 212 if (dir == null) return []; |
| 214 | 213 |
| 215 if (beneath == null) { | 214 if (beneath == null) { |
| 216 beneath = dir; | 215 beneath = dir; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 434 |
| 436 bool operator ==(other) { | 435 bool operator ==(other) { |
| 437 // TODO(rnystrom): We're assuming here that we don't need to delve into the | 436 // TODO(rnystrom): We're assuming here that we don't need to delve into the |
| 438 // description. | 437 // description. |
| 439 return other is PackageDep && | 438 return other is PackageDep && |
| 440 other.name == name && | 439 other.name == name && |
| 441 other.source == source && | 440 other.source == source && |
| 442 other.constraint == constraint; | 441 other.constraint == constraint; |
| 443 } | 442 } |
| 444 } | 443 } |
| OLD | NEW |