| 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 404 } |
| 405 _writeOutputFiles(libraryMap, filteredEntities, outputToYaml, append, | 405 _writeOutputFiles(libraryMap, filteredEntities, outputToYaml, append, |
| 406 startPage); | 406 startPage); |
| 407 } | 407 } |
| 408 | 408 |
| 409 /// Output all of the libraries and classes into json or yaml files for | 409 /// Output all of the libraries and classes into json or yaml files for |
| 410 /// consumption by a viewer. | 410 /// consumption by a viewer. |
| 411 static void _writeOutputFiles(libraryMap, | 411 static void _writeOutputFiles(libraryMap, |
| 412 Iterable<Indexable> filteredEntities, bool outputToYaml, bool append, | 412 Iterable<Indexable> filteredEntities, bool outputToYaml, bool append, |
| 413 String startPage) { | 413 String startPage) { |
| 414 if (startPage != null) libraryMap['startPage'] = startPage; | 414 if (startPage != null) libraryMap['start-page'] = startPage; |
| 415 | 415 |
| 416 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); | 416 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); |
| 417 | 417 |
| 418 // Output libraries and classes to file after all information is generated. | 418 // Output libraries and classes to file after all information is generated. |
| 419 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 419 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 420 _writeIndexableToFile(output, outputToYaml); | 420 _writeIndexableToFile(output, outputToYaml); |
| 421 }); | 421 }); |
| 422 | 422 |
| 423 // Outputs all the qualified names documented with their type. | 423 // Outputs all the qualified names documented with their type. |
| 424 // This will help generate search results. | 424 // This will help generate search results. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 contents.startsWith(new RegExp('part of ')))) { | 584 contents.startsWith(new RegExp('part of ')))) { |
| 585 libraries.add(new Uri.file(path.normalize(path.absolute(f)))); | 585 libraries.add(new Uri.file(path.normalize(path.absolute(f)))); |
| 586 logger.info('Added to libraries: $f'); | 586 logger.info('Added to libraries: $f'); |
| 587 } | 587 } |
| 588 } | 588 } |
| 589 }); | 589 }); |
| 590 return libraries; | 590 return libraries; |
| 591 } | 591 } |
| 592 | 592 |
| 593 /// All of the directories for our dependent packages | 593 /// All of the directories for our dependent packages |
| 594 /// If this is not a package, return an empty list. |
| 594 static List<String> _allDependentPackageDirs(String packageDirectory) { | 595 static List<String> _allDependentPackageDirs(String packageDirectory) { |
| 596 var packageName = Library.packageNameFor(packageDirectory); |
| 597 if (packageName == '') return []; |
| 595 var dependentsJson = Process.runSync('pub', ['list-package-dirs'], | 598 var dependentsJson = Process.runSync('pub', ['list-package-dirs'], |
| 596 workingDirectory: packageDirectory, runInShell: true); | 599 workingDirectory: packageDirectory, runInShell: true); |
| 597 if (dependentsJson.exitCode != 0) { | 600 if (dependentsJson.exitCode != 0) { |
| 598 print(dependentsJson.stderr); | 601 print(dependentsJson.stderr); |
| 599 } | 602 } |
| 600 var dependents = JSON.decode(dependentsJson.stdout)['packages']; | 603 var dependents = JSON.decode(dependentsJson.stdout)['packages']; |
| 601 return dependents.values.toList(); | 604 return dependents.values.toList(); |
| 602 } | 605 } |
| 603 | 606 |
| 604 /// For all the libraries, return a list of the libraries that are part of | 607 /// For all the libraries, return a list of the libraries that are part of |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 .readAsStringSync(), linkResolver: linkResolver, | 1390 .readAsStringSync(), linkResolver: linkResolver, |
| 1388 inlineSyntaxes: _MARKDOWN_SYNTAXES); | 1391 inlineSyntaxes: _MARKDOWN_SYNTAXES); |
| 1389 return contents; | 1392 return contents; |
| 1390 } | 1393 } |
| 1391 | 1394 |
| 1392 /// Given a LibraryMirror that is a library, return the name of the directory | 1395 /// Given a LibraryMirror that is a library, return the name of the directory |
| 1393 /// holding that library. | 1396 /// holding that library. |
| 1394 static String _getRootdir(LibraryMirror mirror) => | 1397 static String _getRootdir(LibraryMirror mirror) => |
| 1395 path.dirname(path.dirname(mirror.uri.toFilePath())); | 1398 path.dirname(path.dirname(mirror.uri.toFilePath())); |
| 1396 | 1399 |
| 1397 /// Read a pubspec and return the library name. | 1400 /// Read a pubspec and return the library name given a [LibraryMirror]. |
| 1398 static String _packageName(LibraryMirror mirror) { | 1401 static String _packageName(LibraryMirror mirror) { |
| 1399 if (mirror.uri.scheme != 'file') return ''; | 1402 if (mirror.uri.scheme != 'file') return ''; |
| 1400 var rootdir = _getRootdir(mirror); | 1403 var rootdir = _getRootdir(mirror); |
| 1401 var pubspecName = path.join(rootdir, 'pubspec.yaml'); | 1404 return packageNameFor(rootdir); |
| 1405 } |
| 1406 |
| 1407 /// Read a pubspec and return the library name, given a directory |
| 1408 static String packageNameFor(String directoryName) { |
| 1409 var pubspecName = path.join(directoryName, 'pubspec.yaml'); |
| 1402 File pubspec = new File(pubspecName); | 1410 File pubspec = new File(pubspecName); |
| 1403 if (!pubspec.existsSync()) return ''; | 1411 if (!pubspec.existsSync()) return ''; |
| 1404 var contents = pubspec.readAsStringSync(); | 1412 var contents = pubspec.readAsStringSync(); |
| 1405 var spec = loadYaml(contents); | 1413 var spec = loadYaml(contents); |
| 1406 return spec["name"]; | 1414 return spec["name"]; |
| 1407 } | 1415 } |
| 1408 | 1416 |
| 1409 String get packagePrefix => packageName == null || packageName.isEmpty ? | 1417 String get packagePrefix => packageName == null || packageName.isEmpty ? |
| 1410 '' : '$packageName/'; | 1418 '' : '$packageName/'; |
| 1411 | 1419 |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2166 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 2174 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
| 2167 .where((e) => e != null) | 2175 .where((e) => e != null) |
| 2168 .toList(); | 2176 .toList(); |
| 2169 } | 2177 } |
| 2170 | 2178 |
| 2171 Map toMap() => { | 2179 Map toMap() => { |
| 2172 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, | 2180 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, |
| 2173 'parameters': parameters | 2181 'parameters': parameters |
| 2174 }; | 2182 }; |
| 2175 } | 2183 } |
| OLD | NEW |