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