| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * **docgen** is a tool for creating machine readable representations of Dart | 6 * **docgen** is a tool for creating machine readable representations of Dart |
| 7 * code metadata, including: classes, members, comments and annotations. | 7 * code metadata, including: classes, members, comments and annotations. |
| 8 * | 8 * |
| 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. | 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 10 * | 10 * |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 */ | 67 */ |
| 68 Future<bool> docgen(List<String> files, {String packageRoot, | 68 Future<bool> docgen(List<String> files, {String packageRoot, |
| 69 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 69 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 70 bool parseSdk: false, bool append: false}) { | 70 bool parseSdk: false, bool append: false}) { |
| 71 if (!append) { | 71 if (!append) { |
| 72 var dir = new Directory('docs'); | 72 var dir = new Directory('docs'); |
| 73 if (dir.existsSync()) dir.deleteSync(recursive: true); | 73 if (dir.existsSync()) dir.deleteSync(recursive: true); |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (packageRoot == null && !parseSdk) { | 76 if (packageRoot == null && !parseSdk) { |
| 77 // TODO(janicejl): At the moment, if a single file is passed it, it is | 77 var type = FileSystemEntity.typeSync(files.first); |
| 78 // assumed that it does not have a package root unless it is passed in by | 78 if (type == FileSystemEntityType.DIRECTORY) { |
| 79 // the user. In future, find a better way to find the packageRoot and also | |
| 80 // fully test finding the packageRoot. | |
| 81 if (FileSystemEntity.typeSync(files.first) | |
| 82 == FileSystemEntityType.DIRECTORY) { | |
| 83 packageRoot = _findPackageRoot(files.first); | 79 packageRoot = _findPackageRoot(files.first); |
| 80 } else if (type == FileSystemEntityType.FILE) { |
| 81 logger.warning('WARNING: No package root defined. If Docgen fails, try ' |
| 82 'again by setting the --package-root option.'); |
| 84 } | 83 } |
| 85 } | 84 } |
| 86 logger.info('Package Root: ${packageRoot}'); | 85 logger.info('Package Root: ${packageRoot}'); |
| 87 | 86 |
| 88 linkResolver = (name) => | 87 linkResolver = (name) => |
| 89 fixReference(name, _currentLibrary, _currentClass, _currentMember); | 88 fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| 90 | 89 |
| 91 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) | 90 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) |
| 92 .then((MirrorSystem mirrorSystem) { | 91 .then((MirrorSystem mirrorSystem) { |
| 93 if (mirrorSystem.libraries.isEmpty) { | 92 if (mirrorSystem.libraries.isEmpty) { |
| 94 throw new StateError('No library mirrors were created.'); | 93 throw new StateError('No library mirrors were created.'); |
| 95 } | 94 } |
| 96 _documentLibraries(mirrorSystem.libraries.values, | 95 _documentLibraries(mirrorSystem.libraries.values, |
| 97 includeSdk: includeSdk, includePrivate: includePrivate, | 96 includeSdk: includeSdk, includePrivate: includePrivate, |
| 98 outputToYaml: outputToYaml, append: append); | 97 outputToYaml: outputToYaml, append: append); |
| 99 | 98 |
| 100 return true; | 99 return true; |
| 101 }); | 100 }); |
| 102 } | 101 } |
| 103 | 102 |
| 104 List<String> _listLibraries(List<String> args) { | 103 List<String> _listLibraries(List<String> args) { |
| 105 // TODO(janicejl): At the moment, only have support to have either one file, | |
| 106 // or one directory. This is because there can only be one package directory | |
| 107 // since only one docgen is created per run. | |
| 108 if (args.length != 1) throw new UnsupportedError(USAGE); | 104 if (args.length != 1) throw new UnsupportedError(USAGE); |
| 109 var libraries = new List<String>(); | 105 var libraries = new List<String>(); |
| 110 var type = FileSystemEntity.typeSync(args[0]); | 106 var type = FileSystemEntity.typeSync(args[0]); |
| 111 | 107 |
| 112 if (type == FileSystemEntityType.FILE) { | 108 if (type == FileSystemEntityType.FILE) { |
| 113 libraries.add(path.absolute(args[0])); | 109 libraries.add(path.absolute(args[0])); |
| 114 logger.info('Added to libraries: ${libraries.last}'); | 110 logger.info('Added to libraries: ${libraries.last}'); |
| 115 } else { | 111 } else { |
| 116 libraries.addAll(_listDartFromDir(args[0])); | 112 libraries.addAll(_listDartFromDir(args[0])); |
| 117 } | 113 } |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 String outer; | 730 String outer; |
| 735 List<Type> inner; | 731 List<Type> inner; |
| 736 | 732 |
| 737 Type(this.outer, this.inner); | 733 Type(this.outer, this.inner); |
| 738 | 734 |
| 739 Map toMap() => { | 735 Map toMap() => { |
| 740 'outer': outer, | 736 'outer': outer, |
| 741 'inner': new List.from(inner.map((e) => e.toMap())) | 737 'inner': new List.from(inner.map((e) => e.toMap())) |
| 742 }; | 738 }; |
| 743 } | 739 } |
| OLD | NEW |