Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 import 'dart2yaml.dart'; | 27 import 'dart2yaml.dart'; |
| 28 import 'src/io.dart'; | 28 import 'src/io.dart'; |
| 29 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 29 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 30 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 30 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 31 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart' | 31 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart' |
| 32 as dart2js; | 32 as dart2js; |
| 33 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; | 33 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; |
| 34 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; | 34 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; |
| 35 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider. dart'; | 35 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider. dart'; |
| 36 import '../../../sdk/lib/_internal/libraries.dart'; | |
| 36 | 37 |
| 37 var logger = new Logger('Docgen'); | 38 var logger = new Logger('Docgen'); |
| 38 | 39 |
| 39 const String usage = 'Usage: dart docgen.dart [OPTIONS] [fooDir/barFile]'; | 40 const String usage = 'Usage: dart docgen.dart [OPTIONS] [fooDir/barFile]'; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * This class documents a list of libraries. | 43 * This class documents a list of libraries. |
| 43 */ | 44 */ |
| 44 class Docgen { | 45 class Docgen { |
| 45 | 46 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 57 | 58 |
| 58 /// Resolves reference links in doc comments. | 59 /// Resolves reference links in doc comments. |
| 59 markdown.Resolver linkResolver; | 60 markdown.Resolver linkResolver; |
| 60 | 61 |
| 61 /// Package directory of directory being analyzed. | 62 /// Package directory of directory being analyzed. |
| 62 String packageDir; | 63 String packageDir; |
| 63 | 64 |
| 64 bool outputToYaml; | 65 bool outputToYaml; |
| 65 bool outputToJson; | 66 bool outputToJson; |
| 66 bool includePrivate; | 67 bool includePrivate; |
| 67 /// State for whether or not the SDK libraries should also be outputted. | 68 /// State for whether imported SDK libraries should also be outputted. |
| 68 bool includeSdk; | 69 bool includeSdk; |
| 70 /// State for whether all SDK libraries should be outputted. | |
| 71 bool parseSdk; | |
| 69 | 72 |
| 70 /** | 73 /** |
| 71 * Docgen constructor initializes the link resolver for markdown parsing. | 74 * Docgen constructor initializes the link resolver for markdown parsing. |
| 72 * Also initializes the command line arguments. | 75 * Also initializes the command line arguments. |
| 73 */ | 76 */ |
| 74 Docgen(ArgResults argResults) { | 77 Docgen(ArgResults argResults) { |
| 75 if (argResults['output-format'] == null) { | 78 if (argResults['output-format'] == null) { |
| 76 outputToYaml = | 79 outputToYaml = |
| 77 (argResults['yaml'] == false && argResults['json'] == false) ? | 80 (argResults['yaml'] == false && argResults['json'] == false) ? |
| 78 true : argResults['yaml']; | 81 true : argResults['yaml']; |
| 79 } else { | 82 } else { |
| 80 if ((argResults['output-format'] == 'yaml' && | 83 if ((argResults['output-format'] == 'yaml' && |
| 81 argResults['json'] == true) || | 84 argResults['json'] == true) || |
| 82 (argResults['output-format'] == 'json' && | 85 (argResults['output-format'] == 'json' && |
| 83 argResults['yaml'] == true)) { | 86 argResults['yaml'] == true)) { |
| 84 throw new UnsupportedError('Cannot have contradictory output flags.'); | 87 throw new UnsupportedError('Cannot have contradictory output flags.'); |
| 85 } | 88 } |
| 86 outputToYaml = argResults['output-format'] == 'yaml' ? true : false; | 89 outputToYaml = argResults['output-format'] == 'yaml' ? true : false; |
| 87 } | 90 } |
| 88 outputToJson = !outputToYaml; | 91 outputToJson = !outputToYaml; |
| 89 includePrivate = argResults['include-private']; | 92 includePrivate = argResults['include-private']; |
| 90 includeSdk = argResults['include-sdk']; | 93 parseSdk = argResults['parse-sdk']; |
| 94 includeSdk = parseSdk == true ? true : argResults['include-sdk']; | |
|
Andrei Mouravski
2013/06/26 04:42:11
Simply do = parseSdk || arg...
| |
| 91 | 95 |
| 92 this.linkResolver = (name) => | 96 this.linkResolver = (name) => |
| 93 fixReference(name, _currentLibrary, _currentClass, _currentMember); | 97 fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| 94 | 98 |
| 95 analyze(argResults.rest); | 99 analyze(argResults.rest); |
| 96 } | 100 } |
| 97 | 101 |
| 98 List<String> listLibraries(List<String> args) { | 102 List<String> listLibraries(List<String> args) { |
| 99 // TODO(janicejl): At the moment, only have support to have either one file, | 103 // TODO(janicejl): At the moment, only have support to have either one file, |
| 100 // or one directory. This is because there can only be one package directory | 104 // or one directory. This is because there can only be one package directory |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 116 List<String> listDartFromDir(String args) { | 120 List<String> listDartFromDir(String args) { |
| 117 var files = listDir(args, recursive: true); | 121 var files = listDir(args, recursive: true); |
| 118 packageDir = files.firstWhere((f) => | 122 packageDir = files.firstWhere((f) => |
| 119 f.endsWith('/pubspec.yaml'), orElse: () => ''); | 123 f.endsWith('/pubspec.yaml'), orElse: () => ''); |
| 120 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; | 124 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; |
| 121 return files.where((f) => | 125 return files.where((f) => |
| 122 f.endsWith('.dart') && !f.contains('/packages')).toList() | 126 f.endsWith('.dart') && !f.contains('/packages')).toList() |
| 123 ..forEach((lib) => logger.info('Added to libraries: $lib')); | 127 ..forEach((lib) => logger.info('Added to libraries: $lib')); |
| 124 } | 128 } |
| 125 | 129 |
| 130 List<String> listSdk() { | |
| 131 var sdk = new List<String>(); | |
| 132 LIBRARIES.forEach((String name, LibraryInfo info) { | |
| 133 if (info.documented) { | |
| 134 sdk.add('dart:$name'); | |
| 135 logger.info('Add to SDK: ${sdk.last}'); | |
| 136 } | |
| 137 }); | |
| 138 return sdk; | |
| 139 } | |
| 140 | |
| 126 /** | 141 /** |
| 127 * Analyzes set of libraries by getting a mirror system and triggers the | 142 * Analyzes set of libraries by getting a mirror system and triggers the |
| 128 * documentation of the libraries. | 143 * documentation of the libraries. |
| 129 */ | 144 */ |
| 130 void analyze(List<String> args) { | 145 void analyze(List<String> args) { |
| 131 var libraries = listLibraries(args); | 146 var libraries = parseSdk == false ? listLibraries(args) : listSdk(); |
|
Andrei Mouravski
2013/06/26 04:42:11
Same as above.
| |
| 132 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 147 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 133 // DART_SDK should be set to the root of the SDK library. | 148 // DART_SDK should be set to the root of the SDK library. |
| 134 var sdkRoot = Platform.environment['DART_SDK']; | 149 var sdkRoot = Platform.environment['DART_SDK']; |
| 135 if (sdkRoot != null) { | 150 if (sdkRoot != null) { |
| 136 logger.info('Using DART_SDK to find SDK at $sdkRoot'); | 151 logger.info('Using DART_SDK to find SDK at $sdkRoot'); |
| 137 } else { | 152 } else { |
| 138 // If DART_SDK is not defined in the environment, | 153 // If DART_SDK is not defined in the environment, |
| 139 // assuming the dart executable is from the Dart SDK folder inside bin. | 154 // assuming the dart executable is from the Dart SDK folder inside bin. |
| 140 sdkRoot = path.dirname(path.dirname(new Options().executable)); | 155 sdkRoot = path.dirname(path.dirname(new Options().executable)); |
| 141 logger.info('SDK Root: ${sdkRoot}'); | 156 logger.info('SDK Root: ${sdkRoot}'); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 if (!dir.existsSync()) { | 514 if (!dir.existsSync()) { |
| 500 dir.createSync(); | 515 dir.createSync(); |
| 501 } | 516 } |
| 502 File file = new File('docs/$filename'); | 517 File file = new File('docs/$filename'); |
| 503 if (!file.existsSync()) { | 518 if (!file.existsSync()) { |
| 504 file.createSync(); | 519 file.createSync(); |
| 505 } | 520 } |
| 506 file.openSync(); | 521 file.openSync(); |
| 507 file.writeAsString(text); | 522 file.writeAsString(text); |
| 508 } | 523 } |
| OLD | NEW |