| 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 /// **docgen** is a tool for creating machine readable representations of Dart | 5 /// **docgen** is a tool for creating machine readable representations of Dart |
| 6 /// code metadata, including: classes, members, comments and annotations. | 6 /// code metadata, including: classes, members, comments and annotations. |
| 7 /// | 7 /// |
| 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. | 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 9 /// | 9 /// |
| 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] | 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 List<markdown.InlineSyntax> markdownSyntaxes = | 59 List<markdown.InlineSyntax> markdownSyntaxes = |
| 60 [new markdown.CodeSyntax(r'\[:\s?((?:.|\n)*?)\s?:\]')]; | 60 [new markdown.CodeSyntax(r'\[:\s?((?:.|\n)*?)\s?:\]')]; |
| 61 | 61 |
| 62 /// Index of all indexable items. This also ensures that no class is | 62 /// Index of all indexable items. This also ensures that no class is |
| 63 /// created more than once. | 63 /// created more than once. |
| 64 Map<String, Indexable> entityMap = new Map<String, Indexable>(); | 64 Map<String, Indexable> entityMap = new Map<String, Indexable>(); |
| 65 | 65 |
| 66 /// This is set from the command line arguments flag --include-private | 66 /// This is set from the command line arguments flag --include-private |
| 67 bool _includePrivate = false; | 67 bool _includePrivate = false; |
| 68 | 68 |
| 69 /// This is set from the command line flag --include-dependent-packages |
| 70 bool _includeDependentPackages = false; |
| 71 |
| 69 /// Library names to explicitly exclude. | 72 /// Library names to explicitly exclude. |
| 70 /// | 73 /// |
| 71 /// Set from the command line option | 74 /// Set from the command line option |
| 72 /// --exclude-lib. | 75 /// --exclude-lib. |
| 73 List<String> _excluded; | 76 List<String> _excluded; |
| 74 | 77 |
| 75 // TODO(janicejl): Make MDN content generic or pluggable. Maybe move | 78 // TODO(janicejl): Make MDN content generic or pluggable. Maybe move |
| 76 // MDN-specific code to its own library that is imported into the default impl? | 79 // MDN-specific code to its own library that is imported into the default impl? |
| 77 /// Map of all the comments for dom elements from MDN. | 80 /// Map of all the comments for dom elements from MDN. |
| 78 Map _mdn; | 81 Map _mdn; |
| 79 | 82 |
| 80 /// Docgen constructor initializes the link resolver for markdown parsing. | 83 /// Docgen constructor initializes the link resolver for markdown parsing. |
| 81 /// Also initializes the command line arguments. | 84 /// Also initializes the command line arguments. |
| 82 /// | 85 /// |
| 83 /// [packageRoot] is the packages directory of the directory being analyzed. | 86 /// [packageRoot] is the packages directory of the directory being analyzed. |
| 84 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 87 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 85 /// also be documented. | 88 /// also be documented. |
| 86 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 89 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 87 /// This option is useful when only the SDK libraries are needed. | 90 /// This option is useful when only the SDK libraries are needed. |
| 88 /// | 91 /// |
| 89 /// Returned Future completes with true if document generation is successful. | 92 /// Returned Future completes with true if document generation is successful. |
| 90 Future<bool> docgen(List<String> files, {String packageRoot, | 93 Future<bool> docgen(List<String> files, {String packageRoot, |
| 91 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 94 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 92 bool parseSdk: false, bool append: false, String introduction: '', | 95 bool parseSdk: false, bool append: false, String introduction: '', |
| 93 out: DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries}) { | 96 out: DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries, |
| 97 bool includeDependentPackages}) { |
| 94 _excluded = excludeLibraries; | 98 _excluded = excludeLibraries; |
| 95 _includePrivate = includePrivate; | 99 _includePrivate = includePrivate; |
| 96 _outputDirectory = out; | 100 _outputDirectory = out; |
| 101 _includeDependentPackages = includeDependentPackages; |
| 97 if (!append) { | 102 if (!append) { |
| 98 var dir = new Directory(_outputDirectory); | 103 var dir = new Directory(_outputDirectory); |
| 99 if (dir.existsSync()) dir.deleteSync(recursive: true); | 104 if (dir.existsSync()) dir.deleteSync(recursive: true); |
| 100 } | 105 } |
| 101 | 106 |
| 102 if (packageRoot == null && !parseSdk) { | 107 if (packageRoot == null && !parseSdk) { |
| 103 var type = FileSystemEntity.typeSync(files.first); | 108 var type = FileSystemEntity.typeSync(files.first); |
| 104 if (type == FileSystemEntityType.DIRECTORY) { | 109 if (type == FileSystemEntityType.DIRECTORY) { |
| 105 packageRoot = _findPackageRoot(files.first); | 110 packageRoot = _findPackageRoot(files.first); |
| 106 } else if (type == FileSystemEntityType.FILE) { | 111 } else if (type == FileSystemEntityType.FILE) { |
| 107 logger.warning('WARNING: No package root defined. If Docgen fails, try ' | 112 logger.warning('WARNING: No package root defined. If Docgen fails, try ' |
| 108 'again by setting the --package-root option.'); | 113 'again by setting the --package-root option.'); |
| 109 } | 114 } |
| 110 } | 115 } |
| 111 logger.info('Package Root: ${packageRoot}'); | 116 logger.info('Package Root: ${packageRoot}'); |
| 117 if (_includeDependentPackages) { |
| 118 files.addAll(allDependentPackageDirs(files.first)); |
| 119 } |
| 112 var requestedLibraries = _listLibraries(files); | 120 var requestedLibraries = _listLibraries(files); |
| 113 var allLibraries = []..addAll(requestedLibraries); | 121 var allLibraries = []..addAll(requestedLibraries); |
| 114 if (includeSdk) { | 122 if (includeSdk) { |
| 115 allLibraries.addAll(_listSdk()); | 123 allLibraries.addAll(_listSdk()); |
| 116 } | 124 } |
| 117 | 125 |
| 118 return getMirrorSystem(allLibraries, packageRoot: packageRoot, | 126 return getMirrorSystem(allLibraries, packageRoot: packageRoot, |
| 119 parseSdk: parseSdk) | 127 parseSdk: parseSdk) |
| 120 .then((MirrorSystem mirrorSystem) { | 128 .then((MirrorSystem mirrorSystem) { |
| 121 if (mirrorSystem.libraries.isEmpty) { | 129 if (mirrorSystem.libraries.isEmpty) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 () => throw "Missing library $each")).toList(); | 143 () => throw "Missing library $each")).toList(); |
| 136 librariesToDocument.addAll((includeSdk || parseSdk) ? _sdkLibraries : []); | 144 librariesToDocument.addAll((includeSdk || parseSdk) ? _sdkLibraries : []); |
| 137 librariesToDocument.removeWhere((x) => _excluded.contains(x.simpleName)); | 145 librariesToDocument.removeWhere((x) => _excluded.contains(x.simpleName)); |
| 138 _documentLibraries(librariesToDocument, includeSdk: includeSdk, | 146 _documentLibraries(librariesToDocument, includeSdk: includeSdk, |
| 139 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, | 147 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, |
| 140 introduction: introduction); | 148 introduction: introduction); |
| 141 return true; | 149 return true; |
| 142 }); | 150 }); |
| 143 } | 151 } |
| 144 | 152 |
| 153 /// All of the directories for our dependent packages |
| 154 List<String> allDependentPackageDirs(String packageDirectory) { |
| 155 var dependentsJson = Process.runSync('pub', ['list-package-dirs'], |
| 156 workingDirectory: packageDirectory, runInShell: true); |
| 157 if (dependentsJson.exitCode != 0) { |
| 158 print(dependentsJson.stderr); |
| 159 } |
| 160 var dependents = JSON.decode(dependentsJson.stdout)['packages']; |
| 161 return dependents.values.toList(); |
| 162 } |
| 163 |
| 145 /// For a library's [mirror], determine the name of the package (if any) we | 164 /// For a library's [mirror], determine the name of the package (if any) we |
| 146 /// believe it came from (because of its file URI). | 165 /// believe it came from (because of its file URI). |
| 147 /// | 166 /// |
| 148 /// If [library] is specified, we set the packageName field. If no package could | 167 /// If [library] is specified, we set the packageName field. If no package could |
| 149 /// be determined, we return an empty string. | 168 /// be determined, we return an empty string. |
| 150 String _findPackage(LibraryMirror mirror, [Library library]) { | 169 String _findPackage(LibraryMirror mirror, [Library library]) { |
| 151 if (mirror == null) return ''; | 170 if (mirror == null) return ''; |
| 152 if (library == null) { | 171 if (library == null) { |
| 153 library = entityMap[docName(mirror)]; | 172 library = entityMap[docName(mirror)]; |
| 154 } | 173 } |
| (...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 /// Remove statics from the map of inherited items before adding them. | 1701 /// Remove statics from the map of inherited items before adding them. |
| 1683 Map _filterStatics(Map items) { | 1702 Map _filterStatics(Map items) { |
| 1684 var result = {}; | 1703 var result = {}; |
| 1685 items.forEach((name, item) { | 1704 items.forEach((name, item) { |
| 1686 if (!item.isStatic) { | 1705 if (!item.isStatic) { |
| 1687 result[name] = item; | 1706 result[name] = item; |
| 1688 } | 1707 } |
| 1689 }); | 1708 }); |
| 1690 return result; | 1709 return result; |
| 1691 } | 1710 } |
| OLD | NEW |