| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 docgen.generator; | 5 library docgen.generator; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:markdown/markdown.dart' as markdown; | 12 import 'package:markdown/markdown.dart' as markdown; |
| 13 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
| 14 | 14 |
| 15 import '../../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 15 import '../../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 16 import '../../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 16 import '../../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 17 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.da
rt' | 17 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/analyze.da
rt' |
| 18 as dart2js; | 18 as dart2js; |
| 19 import '../../../../sdk/lib/_internal/compiler/implementation/source_file_provid
er.dart'; | 19 import '../../../../sdk/lib/_internal/compiler/implementation/source_file_provid
er.dart'; |
| 20 | 20 |
| 21 import 'exports/dart2js_mirrors.dart' as dart2js_mirrors; | 21 import 'exports/dart2js_mirrors.dart' as dart2js_mirrors; |
| 22 import 'exports/libraries.dart'; | 22 import 'exports/libraries.dart'; |
| 23 import 'exports/mirrors_util.dart' as dart2js_util; | 23 import 'exports/mirrors_util.dart' as dart2js_util; |
| 24 import 'exports/source_mirrors.dart'; | 24 import 'exports/source_mirrors.dart'; |
| 25 | 25 |
| 26 import 'io.dart'; | 26 import 'io.dart'; |
| 27 import 'library_helpers.dart'; | 27 import 'library_helpers.dart'; |
| 28 import 'models.dart'; | 28 import 'models.dart'; |
| 29 import 'package_helpers.dart' show packageNameFor, rootDirectory; | 29 import 'package_helpers.dart'; |
| 30 | 30 |
| 31 const String DEFAULT_OUTPUT_DIRECTORY = 'docs'; | 31 const String DEFAULT_OUTPUT_DIRECTORY = 'docs'; |
| 32 | 32 |
| 33 /// The directory where the output docs are generated. | 33 /// The directory where the output docs are generated. |
| 34 String get outputDirectory => _outputDirectory; | 34 String get outputDirectory => _outputDirectory; |
| 35 String _outputDirectory; | 35 String _outputDirectory; |
| 36 | 36 |
| 37 /// Library names to explicitly exclude. | 37 /// Library names to explicitly exclude. |
| 38 /// | 38 /// |
| 39 /// Set from the command line option | 39 /// Set from the command line option |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Outputs a JSON file with all libraries and their preview comments. | 200 // Outputs a JSON file with all libraries and their preview comments. |
| 201 // This will help the viewer know what libraries are available to read in. | 201 // This will help the viewer know what libraries are available to read in. |
| 202 Map<String, dynamic> libraryMap = { | 202 Map<String, dynamic> libraryMap = { |
| 203 'libraries': filteredEntities.where((e) => e is Library).map((e) => | 203 'libraries': filteredEntities.where((e) => e is Library).map((e) => |
| 204 e.previewMap).toList(), | 204 e.previewMap).toList(), |
| 205 'introduction': _readIntroductionFile(introFileName, includeSdk), | 205 'introduction': _readIntroductionFile(introFileName, includeSdk), |
| 206 'filetype': 'json' | 206 'filetype': 'json', |
| 207 'sdkVersion': packageVersion(coreLibrary.mirror) |
| 207 }; | 208 }; |
| 208 | 209 |
| 209 var encoder = new JsonEncoder.withIndent(indentJson ? ' ' : null); | 210 var encoder = new JsonEncoder.withIndent(indentJson ? ' ' : null); |
| 210 | 211 |
| 211 _writeOutputFiles(libraryMap, filteredEntities, startPage, encoder); | 212 _writeOutputFiles(libraryMap, filteredEntities, startPage, encoder); |
| 212 } | 213 } |
| 213 | 214 |
| 214 /// Output all of the libraries and classes into json files for consumption by a | 215 /// Output all of the libraries and classes into json files for consumption by a |
| 215 /// viewer. | 216 /// viewer. |
| 216 void _writeOutputFiles(Map<String, dynamic> libraryMap, Iterable<Indexable> | 217 void _writeOutputFiles(Map<String, dynamic> libraryMap, Iterable<Indexable> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 /// For this run of docgen, determine the packageRoot value. | 289 /// For this run of docgen, determine the packageRoot value. |
| 289 /// | 290 /// |
| 290 /// If packageRoot is not explicitly passed, we examine the files we're | 291 /// If packageRoot is not explicitly passed, we examine the files we're |
| 291 /// documenting to attempt to find a package root. | 292 /// documenting to attempt to find a package root. |
| 292 String _obtainPackageRoot(String packageRoot, bool parseSdk, | 293 String _obtainPackageRoot(String packageRoot, bool parseSdk, |
| 293 List<String> files) { | 294 List<String> files) { |
| 294 if (packageRoot == null && !parseSdk) { | 295 if (packageRoot == null && !parseSdk) { |
| 295 var type = FileSystemEntity.typeSync(files.first); | 296 var type = FileSystemEntity.typeSync(files.first); |
| 296 if (type == FileSystemEntityType.DIRECTORY) { | 297 if (type == FileSystemEntityType.DIRECTORY) { |
| 297 var files2 = listDir(files.first, recursive: true); | 298 var files2 = listDir(files.first, recursive: true); |
| 298 // Return '' means that there was no pubspec.yaml and therefor no p | 299 // Return '' means that there was no pubspec.yaml and therefore no |
| 299 // ackageRoot. | 300 // packageRoot. |
| 300 packageRoot = files2.firstWhere((f) => f.endsWith( | 301 packageRoot = files2.firstWhere((f) => f.endsWith( |
| 301 '${path.separator}pubspec.yaml'), orElse: () => ''); | 302 '${path.separator}pubspec.yaml'), orElse: () => ''); |
| 302 if (packageRoot != '') { | 303 if (packageRoot != '') { |
| 303 packageRoot = path.join(path.dirname(packageRoot), 'packages'); | 304 packageRoot = path.join(path.dirname(packageRoot), 'packages'); |
| 304 } | 305 } |
| 305 } else if (type == FileSystemEntityType.FILE) { | 306 } else if (type == FileSystemEntityType.FILE) { |
| 306 logger.warning('WARNING: No package root defined. If Docgen fails, try ' | 307 logger.warning('WARNING: No package root defined. If Docgen fails, try ' |
| 307 'again by setting the --package-root option.'); | 308 'again by setting the --package-root option.'); |
| 308 } | 309 } |
| 309 } | 310 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 * [Samples](http://www.dartlang.org/samples/) | 463 * [Samples](http://www.dartlang.org/samples/) |
| 463 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn
ing/contents/ch03.html) | 464 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn
ing/contents/ch03.html) |
| 464 | 465 |
| 465 This API reference is automatically generated from the source code in the | 466 This API reference is automatically generated from the source code in the |
| 466 [Dart project](https://code.google.com/p/dart/). | 467 [Dart project](https://code.google.com/p/dart/). |
| 467 If you'd like to contribute to this documentation, see | 468 If you'd like to contribute to this documentation, see |
| 468 [Contributing](https://code.google.com/p/dart/wiki/Contributing) | 469 [Contributing](https://code.google.com/p/dart/wiki/Contributing) |
| 469 and | 470 and |
| 470 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume
ntation). | 471 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume
ntation). |
| 471 """; | 472 """; |
| OLD | NEW |