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 directory_validator; | 5 library directory_validator; |
6 | 6 |
7 import '../entrypoint.dart'; | 7 import '../entrypoint.dart'; |
8 import '../io.dart'; | 8 import '../io.dart'; |
9 import '../validator.dart'; | 9 import '../validator.dart'; |
10 | 10 |
11 /// A validator that validates a package's top-level directories. | 11 /// A validator that validates a package's top-level directories. |
12 class DirectoryValidator extends Validator { | 12 class DirectoryValidator extends Validator { |
13 DirectoryValidator(Entrypoint entrypoint) | 13 DirectoryValidator(Entrypoint entrypoint) |
14 : super(entrypoint); | 14 : super(entrypoint); |
15 | 15 |
16 static final _PLURAL_NAMES = ["tools", "tests", "docs", "examples"]; | 16 static final _PLURAL_NAMES = ["tools", "tests", "docs", "examples"]; |
17 | 17 |
18 Future validate() { | 18 Future validate() { |
19 return listDir(entrypoint.root.dir).chain((dirs) { | 19 return listDir(entrypoint.root.dir).chain((dirs) { |
20 return Futures.wait(dirs.map((dir) { | 20 return Futures.wait(dirs.mappedBy((dir) { |
21 return dirExists(dir).transform((exists) { | 21 return dirExists(dir).then((exists) { |
22 if (!exists) return; | 22 if (!exists) return; |
23 | 23 |
24 dir = basename(dir); | 24 dir = basename(dir); |
25 if (_PLURAL_NAMES.contains(dir)) { | 25 if (_PLURAL_NAMES.contains(dir)) { |
26 // Cut off the "s" | 26 // Cut off the "s" |
27 var singularName = dir.substring(0, dir.length - 1); | 27 var singularName = dir.substring(0, dir.length - 1); |
28 warnings.add('Rename the top-level "$dir" directory to ' | 28 warnings.add('Rename the top-level "$dir" directory to ' |
29 '"$singularName".\n' | 29 '"$singularName".\n' |
30 'The Pub layout convention is to use singular directory ' | 30 'The Pub layout convention is to use singular directory ' |
31 'names.\n' | 31 'names.\n' |
32 'Plural names won\'t be correctly identified by Pub and other ' | 32 'Plural names won\'t be correctly identified by Pub and other ' |
33 'tools.'); | 33 'tools.'); |
34 } | 34 } |
35 | 35 |
36 if (dir.contains(new RegExp(r"^samples?$"))) { | 36 if (dir.contains(new RegExp(r"^samples?$"))) { |
37 warnings.add('Rename the top-level "$dir" directory to "example".\n' | 37 warnings.add('Rename the top-level "$dir" directory to "example".\n' |
38 'This allows Pub to find your examples and create "packages" ' | 38 'This allows Pub to find your examples and create "packages" ' |
39 'directories for them.\n'); | 39 'directories for them.\n'); |
40 } | 40 } |
41 }); | 41 }); |
42 })); | 42 })); |
43 }); | 43 }); |
44 } | 44 } |
45 } | 45 } |
OLD | NEW |